phuryn/product-engineering / app-stack/skills/embedded-agents-agent-sdk
embedded-agents-agent-sdk
VerifiedOnly when the Agent SDK is asked for, an agent needs Claude Code's own tools, or the app already runs it: embed Claude agents in a Next.js app with the Agent SDK.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 9.9 KB |
| examples/knowledge-agent.live.test.ts | script | 1.2 KB |
| examples/knowledge-agent/AGENTS.md | markdown | 2.0 KB |
| examples/knowledge-agent/knowledge/jtbd.md | markdown | 3.3 KB |
| examples/knowledge-agent/knowledge/llms.md | markdown | 6.1 KB |
| examples/knowledge-agent/knowledge/okrs.md | markdown | 2.7 KB |
| examples/knowledge-agent/knowledge/product-strategy.md | markdown | 3.8 KB |
| examples/knowledge-agent/knowledge/product-vision.md | markdown | 3.8 KB |
| examples/research-agent.live.test.ts | script | 1.1 KB |
| examples/research-agent/.mcp.json | config | 277 B |
| examples/research-agent/AGENTS.md | markdown | 2.5 KB |
| reference/playbook.md | markdown | 16.4 KB |
| scripts/discover-mcp-tools.mjs | script | 2.6 KB |
| scripts/new-agent.mjs | script | 1.9 KB |
| templates/agent.test.ts | script | 5.1 KB |
| templates/agent.ts | script | 8.6 KB |
| templates/agents.live.test.ts | script | 1.7 KB |
| templates/route.ts | script | 2.4 KB |
templates/route.ts
View on GitHubimport { z } from 'zod';
import { askAgent, listAgents } from '@/lib/agent';
// GET lists the agents (their directory names); POST streams one agent's answer as
// server-sent events. The agent is chosen per request: nothing here names one.
export const runtime = 'nodejs'; // the SDK spawns a process: never the edge runtime
export const dynamic = 'force-dynamic';
const Body = z.object({
agent: z.string().regex(/^[a-z0-9][a-z0-9-]*$/),
prompt: z.string().trim().min(1).max(4000),
history: z.array(z.object({ role: z.enum(['user', 'assistant']), content: z.string().max(8000) })).max(20).default([]),
});
export function GET() {
return Response.json({ agents: listAgents() });
}
export async function POST(req: Request) {
// A mutation from another origin is refused: a cross-site form or script must not spend the caller's budget.
const origin = req.headers.get('origin');
if (origin && new URL(origin).host !== req.headers.get('host')) return new Response('Forbidden', { status: 403 });
// Every call spends money. Before anyone but the developer can reach
// this route, resolve the caller here and apply a per-actor limit and a maxBudgetUsd.
const parsed = Body.safeParse(await req.json().catch(() => null));
if (!parsed.success || !listAgents().includes(parsed.data.agent)) {
return Response.json({ error: 'invalid request' }, { status: 400 });
}
const { agent, prompt, history } = parsed.data;
const enc = new TextEncoder();
const stream = new ReadableStream<Uint8Array>({
async start(controller) {
const send = (data: unknown) => controller.enqueue(enc.encode(`data: ${JSON.stringify(data)}\n\n`));
try {
for await (const ev of askAgent({ agent, prompt, history })) {
if (ev.type === 'text') send({ text: ev.text });
if (ev.type === 'done') send({ done: true, agent, metadata: ev.metadata });
if (ev.type === 'error') send({ error: ev.subtype, agent });
}
} catch (err) {
// Log ids, never bodies: the prompt is the caller's text and stays out of the log.
console.error('agent run failed', { agent, message: err instanceof Error ? err.message : String(err) });
send({ error: 'failed', agent });
} finally {
controller.close();
}
},
});
return new Response(stream, {
headers: { 'Content-Type': 'text/event-stream', 'Cache-Control': 'no-cache, no-transform' },
});
}
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| reverse-engineer-anythingmorluto/reaReverse engineer native, managed, Electron/JavaScript, packaged, firmware, and browser targets with REA, and build agent environments (AgentEnv bundles) of web applications from a live instance or a capture, and of Linux desktop apps with a task from a request. Use shipped-artifact or requested runtime evidence to explain features, compare versions, decompile code, or guide a reconstruction. Skip REA for ordinary source-repository architecture analysis. | Stars: 471k | Updated | Claude CodeCodex | Verified | Install |
| diagnosing-superpowersobra/superpowersUse when a superpowers session went wrong and your human partner wants to know why — repeated work, ignored plans, stumbles, poor results, a skill that didn't fire, "it took too long", "why is it so expensive", "what is it doing" — or wants to build a bug report for the superpowers maintainers, for the current session or a past one identified by id or path, on any harness. | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| dispatching-parallel-agentsobra/superpowersUse when facing 2+ independent tasks that can be worked on without shared state or sequential dependencies | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| executing-plansobra/superpowersUse when executing an implementation plan in the current session as the implementer yourself — your human partner chose inline execution, or no subagent tool is available | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |