Skip to content

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
  1. Pick the runtime problem you are trying to solve.
  2. Open the closest example page.
  3. Run the script from examples/package.json.
  4. Compare the documented flow with the example source and the output you see locally.

Setup once ​

bash
cd examples
npm install

Some examples run entirely with fake models. Others need real provider credentials.

Environment matrix ​

Example typeReal provider key requiredNotes
basic, planning, summarization, tool-limitoptionalThese examples include a fake model fallback.
toolsOPENAI_API_KEYTAVILY_API_KEY is optional unless the search tool is used.
structured-outputoptionalIncludes a fake model fallback.
pause-resume, tool-approval, ask-user, guardrailsnoBuilt for local runtime behavior inspection.
multi-agentoptionalIncludes fake-model fallback.
handoffyesUses ChatOpenAI directly.
visionyesRequires a multimodal-capable provider model.
mcpyesRequires 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 ​

  • basic
  • tools
  • planning

2. Smart runtime behavior ​

  • summarization
  • summarize-context
  • rewrite-summary
  • tool-limit

3. Production control surfaces ​

  • tool-approval
  • ask-user
  • pause-resume
  • structured-output
  • guardrails

4. Orchestration and integrations ​

  • multi-agent
  • handoff
  • vision
  • mcp

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub