Veryfront supports two agent composition patterns:
- Let one agent call others by naming them in
delegates. - Run agents as ordered workflow steps.
Use delegation when the parent should choose the order at runtime. Use a workflow when the order is known in advance.
Each agent can omit model to use the Cloud default (mistral/mistral-small-2503)
with hosted context, or openai/gpt-5-nano with direct credentials. Set "auto"
for runtime selection, or set an explicit provider/model override.
Prerequisites
- A working agent project, such as the Local quickstart.
- A configured provider (see Providers).
Direct local delegation does not require a Veryfront account. Set a direct
provider key, run veryfront dev, and use delegates on the parent agent. The
runtime runs the delegates in-process and gives the parent one scoped tool for
each allowed agent. Veryfront Cloud is only required when you choose hosted run
or control-plane capabilities.
Local delegation
This section starts with the quickstart project and creates both specialists. Keep its provider key. Add an agent that identifies the important facts:
import { agent } from "veryfront/agent"; export default agent({ id: "researcher", system: "Identify the three most important facts in the user's request. Return concise bullet points.", maxSteps: 3,});Add a second specialist that turns notes into a clear answer:
import { agent } from "veryfront/agent"; export default agent({ id: "writer", system: "Turn the supplied notes into a concise, practical answer.", maxSteps: 3,});Replace agents/assistant.ts with an orchestrator that can call both
specialists:
import { agent } from "veryfront/agent"; export default agent({ id: "assistant", name: "Assistant", description: "Research a request and turn it into a practical answer.", system: "Use the researcher first. Pass the researcher's notes to the writer, then return the writer's answer.", delegates: ["researcher", "writer"], maxSteps: 10,});Each delegate runs in the same Veryfront process as the assistant. The
delegates list exposes the specialists as agent_researcher and
agent_writer tools. It does not create hosted child runs or require a
Veryfront account.
If the development server is still running, keep using it. If you stopped the server for the eval, start it again:
npm run devOpen the local URL printed by the CLI and ask:
Compare two ways a small team could reduce support response time. Recommend one.Ensure the run calls agent_researcher and agent_writer, then returns one
combined recommendation.
Replace evals/assistant.eval.ts so the smoke eval checks delegation instead
of the starter's calculator behavior:
import { datasets, evalAgent, metrics } from "veryfront/eval"; export default evalAgent({ name: "Assistant delegation smoke test", target: "agent:assistant", dataset: datasets.inline([ { id: "support-recommendation", input: "Compare two ways a small team could reduce support response time. Recommend one.", }, ]), metrics: [ metrics.agent.calledTool("agent_researcher").gate(), metrics.agent.calledTool("agent_writer").gate(), metrics.agent.noFailedTools().gate(), ],});Stop the dev server with Ctrl+C, then run:
npm run eval -- assistantThe eval passes when both specialists run without tool errors. It does not grade the recommendation's quality; add answer checks for your application's needs.
Agent-as-tool
Convert an agent into a tool that another agent can call:
import { agent } from "veryfront/agent"; export default agent({ id: "researcher", model: "veryfront-cloud/anthropic/claude-sonnet-4-6", system: "Research topics thoroughly using web search.", providerTools: ["web_search"], maxSteps: 5,});Provider-native web search uses the web_search tool name and requires a
provider/model that supports it. Use providerTools for provider-executed
tools. Use tools for local tools that your app defines.
import { agent } from "veryfront/agent"; export default agent({ id: "writer", system: "Write clear, well-structured articles.",});import { agent } from "veryfront/agent"; export default agent({ id: "orchestrator", system: "You coordinate research and writing. Use the researcher to gather facts, then the writer to produce the article.", delegates: ["researcher", "writer"], maxSteps: 10,});Each id in delegates becomes an agent_<id> tool. The orchestrator decides when to call each agent based on its system prompt, and each sub-agent runs its own tool loop independently.
Name the delegates rather than building the tools yourself. Discovery loads agents/ in filename order, so a top-level getAgentsAsTools() in orchestrator.ts runs before researcher.ts and writer.ts have registered and returns nothing. delegates resolves each agent when the run starts, so load order cannot matter. Reach for agentAsTool() or getAgentsAsTools() only where you register the agents yourself and control the order.
Invoke the orchestrator
Expose the orchestrator through an AG-UI route:
import { createAgUiHandler } from "veryfront/agent"; export const POST = createAgUiHandler("orchestrator");Run the dev server and ask for an output that requires delegation:
curl -N http://localhost:3000/api/ag-ui \ -H "Content-Type: application/json" \ -H "Cookie: __Host-vf_csrf=local-check" \ -H "x-csrf-token: local-check" \ -d '{"messages":[{"id":"1","role":"user","parts":[{"type":"text","text":"Research Deno Deploy and write a short technical summary."}]}]}'The orchestrator receives the user message, then calls researcher and writer as tools when the model decides they are needed.
Single agent-as-tool
For wrapping a single agent:
import { agentAsTool, getAgent } from "veryfront/agent"; const researcher = getAgent("researcher");const researchTool = agentAsTool(researcher, "Research a topic using web search");The tool returns the delegate's text, its status, and the number of tool calls it made
(toolCalls). When the delegate declares an outputSchema and its output parses against it,
the result also carries object, the parsed value. If parsing fails (for example, the delegate
runs out of steps with incomplete JSON), object is absent and only text is returned.
Declarative delegation with delegates
Code and markdown agents can opt into orchestration by listing the exact
specialists they may call. The runtime gives the agent one agent_{id} tool
per delegate. Each scoped tool accepts { input: string } and runs the actual
delegate definition with its own model, skills, MCP servers, and tools.
import { agent } from "veryfront/agent"; export default agent({ id: "orchestrator", system: "Use agent_researcher, then agent_writer.", delegates: ["researcher", "writer"],});The same configuration is available in markdown frontmatter:
---name: Leaddescription: Plans the work and routes to specialistsdelegates: [researcher, writer]--- Break the task down. Use agent_researcher to gather facts, then agent_writer toproduce the final copy.Set delegates: [] when an agent must not delegate. veryfront__invoke_agent is the
generic platform tool for dynamic agent selection. Enable it explicitly in a
direct runtime with tools: { veryfront__invoke_agent: true }. The legacy
invoke_agent: true selector also publishes veryfront__invoke_agent to the model.
Hosted runtimes expose it when generic delegation is allowed and delegates is absent. Self-delegation
and delegate ids that cannot form a valid provider tool name are rejected with
explicit diagnostics. Declare direct tools by name when using delegates;
tools: true is intentionally rejected because it would hide the agent's
capability boundary.
Hosted nested delegation carries trusted invocation lineage from parent to child runs. The root conversation and run stay stable, the immediate parent is updated for each handoff, and hosted runtimes stop delegation after eight nested levels.
Workflow-based composition
For multi-agent pipelines with explicit execution order, use workflows:
import { parallel, step, workflow } from "veryfront/workflow"; export default workflow({ id: "article-pipeline", steps: [ step("research", { agent: "researcher" }), parallel("drafts", [ step("draft-1", { agent: "writer", input: "Style: conversational" }), step("draft-2", { agent: "writer", input: "Style: technical" }), ]), step("select", { agent: "editor" }), ],});Start this workflow from an API route, task, or tool. The Workflows guide shows a copyable createWorkflowClient() start route.
When to use which
Agent-as-tool is more flexible but harder to predict. Workflows make execution order explicit and easier to debug.
Agent registry
All agents in agents/ are registered automatically. Access them programmatically:
import { getAgent, getAllAgentIds } from "veryfront/agent"; const ids = getAllAgentIds(); // ["assistant", "researcher", "writer"]const agent = getAgent("writer"); // Get a specific agentVerify it worked
After wiring delegation, run a request against the orchestrator and watch the dev-server logs:
curl -N http://localhost:3000/api/ag-ui \ -H "Content-Type: application/json" \ -H "Cookie: __Host-vf_csrf=local-check" \ -H "x-csrf-token: local-check" \ -d '{"messages":[{"id":"1","role":"user","parts":[{"type":"text","text":"Research and summarise the latest npm release."}]}]}'A working delegation:
- Logs show the orchestrator calling each sub-agent in order.
- The final AG-UI response contains output that could only come from the sub-agents (research output then writer output, for example).
For workflows, hit the workflow start route from
Workflows and follow runId events instead.
Bind hosted children to accepted artifacts
A hosted parent can register withHostedChildTaskInputResolver(resolver, next) around its awaited execution. The resolver receives the host-derived project, root, parent, child target and tool-call identities, together with two narrow readers: the parent's canonical tool-result page and an exact historical file version in the same project. It must return undefined for an unbound child, or a bounded JSON payload with source event IDs and immutable artifact references. A truncated result page fails explicitly.
Accepted-input resolution applies only to durable children in the verified parent project. Cross-project delegation stays unbound, and missing durable parent context retains its normal error result.
Evidence reads require verified canonical parent identity. The hosted service verifies its signed writer generation or terminal credential before sending a request. A terminal routing hint alone does not authorize evidence reads.
If you use a custom hosted request parser or route set, supply verifyRunTerminalToken when the writer credential has no canonical generation. Pass the verifier returned by createHostedServiceAuth with the same host authentication configuration. The standard hosted service supplies this verifier.
The hosted runtime submits the receipt through its private event writer. Native child admission verifies the lineage, target, successful source events and artifact version content before storing one immutable input. Replaying the same receipt restores that input; altered receipts conflict. Application code receives no event credential or general HTTP client.
Child tools read getVerifiedHostedTaskInput(context). A present binding is accepted only after native verification and must match the tool's host-derived project, root and run. JSON reconstruction does not preserve this authority. An application should validate the expected stage and historical artifact content before deriving arguments such as an email directory. Payload fields are never spread into credentials, prompts or general context. Legacy children without a binding keep their existing behavior.
The resolver belongs to the awaited parent execution. For a streamed Response, the scope is revoked when its source closes or fails, or when you cancel its body. A buffered final chunk does not extend this lifetime. A detached durable start transfers the resolver into the scheduled execution: consuming the 202 acknowledgement does not revoke the running parent, and the scheduled scope is revoked when execution settles. For other results, the scope is revoked when the awaited execution settles. The evidence readers share this lifetime: retained readers and reads that finish after revocation reject. A cancelled child invocation does not resolve or persist new accepted input. Child execution clears the parent resolver. It does not change which agents execute or replace durable child runs. Artifact stage ordering and business validation belong to the application; the framework checks generic receipt provenance and bounded transport.