In short.
Embedded agents — Claude API is a skill for Next.js developers building Claude assistants, but application security, conversation storage and the chat interface remain their responsibility. It provides a readable wrapper with explicitly supplied tools, knowledge-file access, MCP integration and test templates. The sample route accepts client-provided history and applies no spending limit, while the wrapper's optional budget checks can overshoot their threshold. Current provider compatibility, test outcomes and production behavior are not established.
Researched and written by an AI model and checked by a second AI model. How it works
Covers all 19 supplied files under app-stack/skills/embedded-agents-messages-api at revision cea779f703f4d57a54ece91a3b1a03bd96da7555, plus the repository-root LICENSE.md notice. This includes the skill instructions, playbook, two scripts, five templates and both examples with their instructions, knowledge, configuration and tests. Sibling skills, complete applications, installed dependencies and external provider documentation are outside this scope. No code was executed. Current test outcomes, service compatibility, prices and deployed behavior remain unknown.
The overview
Identity
The resource is the embedded-agents-messages-api skill in phuryn/product-engineering. Its instructions guide a coding assistant, while its TypeScript templates become part of the developer's application. The folder includes a reference playbook, scaffolding and discovery scripts, and knowledge and research agent examples.
Original source: [https://github.com/phuryn/product-engineering/tree/main/app-stack/skills/embedded-agents-messages-api]. The repository licence identifies Pawel Huryn as the copyright holder.
Assessment
This is a useful implementation starting point for teams that want their application to control which tools an agent receives. The wrapper, route and tests make important choices inspectable: agent discovery, prompt construction, file access, tool errors and run termination.
It requires engineering work before exposure to other users. The sample route validates requests and checks the Origin header, but caller authentication, permissions, per-caller limits and request budgets are left for the application to implement. Included test definitions do not establish that these integrations work in a deployed product.
Users
The strongest fit is a TypeScript developer adding an assistant to a Next.js product: answering from local documents, researching through an external service, or using application tools tied to the signed-in caller.
Beginners get concrete files and examples, but still need to understand server routes, environment variables, API billing and tests. Experienced developers get extension points for caller-specific tools, trusted request context and response attachments. There is no supplied chat UI.
Capabilities
Agents are discovered from directories containing AGENTS.md. Each can have local knowledge, instructions loaded on demand as skills, and explicitly allowed MCP tools. MCP connects the application to external tool servers; the implementation supports stdio subprocesses and Streamable HTTP connections.
Knowledge tools list files, return matching lines and read individual files. Search uses keyword substring matches, returns at most 40 lines, and is not semantic retrieval. Whole-file reads are limited to 256 KB. Agent-local skills supply instructions and reference material rather than executable capabilities.
The wrapper also accepts application-defined tools, validates their inputs, substitutes a fixed message for unexpected tool exceptions, and reports estimated model cost, tokens, duration and explicit file reads.
Using it
Requirements
The templates target Next.js App Router with TypeScript and a Node.js runtime. Dependencies include @anthropic-ai/sdk, @modelcontextprotocol/sdk, zod and server-only, with Vitest for tests. A deployed application needs ANTHROPIC_API_KEY and any secrets referenced by its agents' MCP configurations.
The host must support disk reads and remain active for the complete multi-call run. Stdio MCP servers additionally require subprocess support. Edge runtimes are excluded by the supplied design. A standalone Next.js deployment must include the agent directories in its file trace.
The folder supplies no application package manifest, lockfile or explicit minimum Node.js version. Availability of the configured model identifiers and compatibility with current SDK releases are unknown.
Mechanism
GET /api/agents lists available agents. POST validates the requested name, prompt and history, then calls askAgent. The wrapper reads that agent's AGENTS.md as its entire system prompt, adds its skill index and trusted context, and assembles its available tools.
Anthropic's tool runner repeatedly requests a model response, executes requested tools and returns their results to the model. There are no built-in shell or browsing tools supplied by this wrapper. File tools resolve paths before reading and reject escapes and path segments beginning with .env; MCP tools are filtered through allowedTools.
The route sends server-sent events containing one complete model response's text at a time, followed by completion metadata or an error. This is response-level delivery rather than token-by-token streaming. The default turn limit counts ten model responses, not ten individual tool calls.
Setup
The documented installation starts by checking for an existing askAgent wrapper. For a new installation, copy agent.ts and agent-mcp.ts into src/lib, the route into src/app/api/agents/route.ts, and the unit and live tests into separate test directories. Configure Vitest to understand the application's @ import alias and pin dependency versions.
The new-agent.mjs script creates an agent directory, an AGENTS.md containing placeholders, and optional knowledge or MCP configuration. Those placeholders need complete role, source, output and refusal instructions. The discover-mcp-tools.mjs script connects to declared servers and lists available and granted tools so allowedTools can be restricted.
The live suite needs its own configuration and secrets and is kept outside npm test because it incurs service charges. A chat interface and any required conversation persistence must be implemented separately.
Example
The knowledge-agent example contains reference files on OKRs, Jobs-to-be-Done, product strategy, product vision and LLM fundamentals. Its instructions require reading relevant files, citing them and declining uncovered questions. For a question about OKR scoring, the included test expects the sample document's 0.7 target and a knowledge/okrs.md citation. Another test expects refusal of an unrelated geography question. These are intended outcomes, not observed results.
The research-agent example uses the perplexity-mcp package through stdio, granting search, reason and deep_research. It requires PERPLEXITY_API_KEY and asks for source-cited answers. Its live test checks completion and the presence of a URL; that assertion alone would not establish the accuracy of the research or citations.
Assessment & evidence
Limitations
Client-supplied history includes assistant turns, so a caller can fabricate earlier replies. The documentation requires server-owned transcripts before tools act on a caller's behalf. The Origin check does not authenticate a caller or enforce account permissions.
Grounding instructions ask the model to answer only from knowledge files, but code does not verify every factual claim against those files. metadata.filesRead records explicit file and skill reads; search_files returns file contents without adding their paths to that list, so it is not a complete record of source material encountered.
The route's exception handler logs the exception message. Tool execution errors receive a fixed message through the wrapper, but that does not establish redaction of SDK or connection failures reaching the route. MCP connections also open anew for every run; connection pooling is not supplied.
Reasoning
The architectural benefit is a clear division of responsibility: the application controls identity, storage and available actions, while the model chooses among exposed tools. This makes the integration suitable for narrowly defined product assistants whose tools can be inspected individually.
The tradeoff is application ownership of the surrounding controls and copied implementation. Caller identity should be captured inside tool functions rather than accepted as model-supplied account identifiers. Irreversible actions require application-enforced approval rather than relying on an agent's judgment. The value lies in this explicit design, while performance advantages remain workload-dependent.
Alternatives
The playbook describes the sibling embedded-agents-agent-sdk skill for applications needing Claude Code's engine, working-directory tools, shell or subagents. It describes that variant as requiring a long-lived Node host and a different system-prompt arrangement. The sibling implementation is outside this folder, so those comparisons rest on the supplied playbook.
For a feature needing one model response rather than repeated tool use, the playbook recommends a direct API call with output validation instead of an agent wrapper. For a small, stable knowledge base, it also describes placing reference material directly in the system prompt to avoid file-reading round trips.
Evidence
The unit-test template exercises the SDK tool runner against scripted network responses. Its assertions cover request construction, path confinement, tool failures, history, cost arithmetic and stopping behavior. Separate live-test definitions check server availability, tool lists and a model response; example-specific tests add a few behavioral expectations. Passing outcomes are not established here.
The playbook contains author-reported measurements and mutation-test claims dated October 2026. Its performance comparison concerns nine conversations in one support application with Stripe mocked. Raw execution logs and that application's reproduction harness are not included in this folder. Those figures do not establish general latency, cost savings or production reliability.
Access & freshness
Costs
Running agents incurs Claude API usage, hosting costs and any charges from external tools such as Perplexity. Current provider tariffs and total operating cost are unknown. The wrapper estimates model charges from a hard-coded table; for its Sonnet model identifier, that table assumes $2 per million input tokens and $10 per million output tokens, with separate cache rates. These are source assumptions, not verified current prices.
maxBudgetUsd is optional and checked after a response has already incurred usage. A response can therefore exceed the threshold, and a terminal answer is retained. Closing tools execute before the ordinary budget and turn checks. External tool fees and hosting are excluded, so this setting is not a hard ceiling on total spending.
The sample route supplies no maxBudgetUsd or per-caller allowance. The playbook's reported example costs concern particular historical workloads and do not establish a budget for another application.
Rights
The supplied repository-root LICENSE.md applies the MIT License, copyright 2026 Pawel Huryn. It permits use, copying, modification, publication, distribution, sublicensing and sale, provided the copyright and permission notices remain in copies or substantial portions.
The software is supplied without warranty. The skill's code and documentation can be redistributed under those conditions; terms for external services and installed dependencies are not established by this notice.
Freshness
The supplied source snapshot is revision cea779f703f4d57a54ece91a3b1a03bd96da7555, captured on 17 November 2026. The playbook reports a 24 October 2026 baseline using @anthropic-ai/sdk 0.133.0 and @modelcontextprotocol/sdk 1.32.1, with some provider notes dated 25 October. These are source-reported baselines, not independently confirmed compatibility results.
The implementation depends on a beta tool runner, configured model identifiers, provider fallback settings and a maintained price table. The research example invokes perplexity-mcp without a package version. Later source changes, current package compatibility, model availability and service prices are unknown.
Actions
Before adoption, confirm the configured models and SDK features are available, pin dependencies and reconcile the embedded price table with applicable provider charges. Start with a narrowly scoped agent and grant only the tools it needs.
Before public access, implement caller authentication, account permissions, per-caller spending allowances and an explicit request budget. Use server-owned history for tools acting on user records, bind identity inside those tools, and enforce approval in application code for irreversible actions.
Evaluate the unit suite and paid live suite in the target application, adding realistic checks for grounding, refusals, permissions and failed services. Confirm deployment includes agent files and that host limits cover slow runs. These are recommended evaluation steps; their outcomes remain unknown.
