Examples
This section is a recipe catalog, not a loose folder dump. Each example is here to demonstrate one concrete runtime behavior, how to run it, what to inspect, and which integration problem it helps solve.
Browse by track
FundamentalsBasic AgentUnderstand the minimal loop, one tool call, and final response assembly.
example:basicFundamentalsToolsSee typed local tools, env checks, and an external API-backed tool in one place.example:toolsSmart RuntimePlanning & TODOsInspect how a smart agent turns multi-step work into durable plan state.example:todo-planningSmart RuntimeSummarizationUnderstand context compaction before adding retrieval and resume behaviors.example:summarizationSmart RuntimeArchived Tool RetrievalRecover raw tool payloads after the runtime archived heavy responses.example:summarize-contextSmart RuntimeRewrite After SummaryContinue on a later turn after history was already rewritten into a compact form.example:rewrite-summarySmart RuntimeTool Limit FinalizeSee how the runtime forces a direct answer once the tool-call budget is exhausted.example:tool-limitControl & SafetyTool ApprovalPause before sensitive execution, then resume from an approved runtime state.example:tool-approvalControl & SafetyAsk UserPause with a structured multi-choice prompt, then resume with the user's answer.example:ask-userControl & SafetyPause & ResumeSnapshot a paused run, serialize it, and continue later without replaying the session.example:pause-resumeControl & SafetyStructured OutputRequire a schema-shaped final result while keeping the standard assistant response path.example:structured-outputControl & SafetyGuardrailsEnforce request and response policy at runtime instead of relying on prompt wording.example:guardrailsOrchestrationMulti-AgentCompose specialist agents as tools without moving into a heavier orchestration stack.example:multi-agentOrchestrationHandoffTransfer ownership to another agent and inspect explicit handoff events.example:handoffIntegrationsVisionStart with the smallest multimodal message format before wrapping it in a full agent.example:visionIntegrationsMCP ToolsConnect a remote MCP server and run discovered tools inside the same smart runtime.example:mcp-tavily- Pick the runtime problem you are trying to solve.
- Open the closest example page.
- Run the script from
examples/package.json. - Compare the documented flow with the example source and the output you see locally.
Setup once
bash
cd examples
npm installSome examples run entirely with fake models. Others need real provider credentials.
Environment matrix
| Example type | Real provider key required | Notes |
|---|---|---|
basic, planning, summarization, tool-limit | optional | These examples include a fake model fallback. |
tools | OPENAI_API_KEY | TAVILY_API_KEY is optional unless the search tool is used. |
structured-output | optional | Includes a fake model fallback. |
pause-resume, tool-approval, ask-user, guardrails | no | Built for local runtime behavior inspection. |
multi-agent | optional | Includes fake-model fallback. |
handoff | yes | Uses ChatOpenAI directly. |
vision | yes | Requires a multimodal-capable provider model. |
mcp | yes | Requires OPENAI_API_KEY and TAVILY_API_KEY. |
Choose by product need
| If you need to... | Open this example first |
|---|---|
| understand the minimal runtime loop | /examples/basic |
| define and call local typed tools | /examples/tools |
| make the agent manage multi-step work | /examples/planning |
| keep a long-running agent alive under context pressure | /examples/summarization |
| recover archived raw tool payloads | /examples/summarize-context |
| continue after compaction on a later turn | /examples/rewrite-summary |
| stop unbounded tool recursion | /examples/tool-limit |
| pause for human approval | /examples/tool-approval |
| ask the user a structured question | /examples/ask-user |
| snapshot and resume later | /examples/pause-resume |
| force typed final output | /examples/structured-output |
| block unsafe requests or responses | /examples/guardrails |
| compose specialist agents | /examples/multi-agent |
| hand off ownership to another agent | /examples/handoff |
| connect a remote MCP tool server | /examples/mcp |
| send image input to a multimodal model | /examples/vision |
Suggested learning path
1. Fundamentals
basictoolsplanning
2. Smart runtime behavior
summarizationsummarize-contextrewrite-summarytool-limit
3. Production control surfaces
tool-approvalask-userpause-resumestructured-outputguardrails
4. Orchestration and integrations
multi-agenthandoffvisionmcp

