Runnable examples demonstrating every feature of the Agentspan TypeScript SDK.
Every example uses
runtime.run()for convenience. In production, you should not.
Examples call runtime.run() so you can try them in a single command — no setup, no
separate processes. But run() blocks the caller until the agent finishes, which is fine
for demos but not how you deploy real agents.
In production, the three concerns are separated:
┌──────────────────────────────────────────────────────────────┐
│ 1. DEPLOY (once, during CI/CD) │
│ Registers the agent definition with the Agentspan server │
│ │
│ await runtime.deploy(agent); │
│ // or CLI: agentspan deploy --package my-agents │
├──────────────────────────────────────────────────────────────┤
│ 2. SERVE (long-running worker process) │
│ Listens for tool-call tasks and executes them │
│ │
│ await runtime.serve(agent); │
│ // typically run as a daemon or container │
├──────────────────────────────────────────────────────────────┤
│ 3. RUN (on-demand, from anywhere) │
│ Triggers an agent execution │
│ │
│ agentspan run <agent-name> "prompt" │
│ // or SDK: await runtime.run("agent_name", "prompt"); │
│ // or REST API │
└──────────────────────────────────────────────────────────────┘
Every example includes the deploy/serve pattern as commented code at the bottom of its
main() function — look for the // Production pattern: comment.
See 63-deploy.ts, 63b-serve.ts, and 63c-run-by-name.ts for a complete working example of this pattern.
The core examples (numbered files in this directory) are repository examples.
They resolve @io-orkes/conductor-javascript/agents straight to the repo's
src/agents/ sources (via this directory's tsconfig.json paths), so they are
meant to be run from this checkout of the SDK:
# from the repository root
npm installFramework-specific examples require additional packages. Install only what you need:
If you want to copy an example into a separate project after npm install, switch
its imports to the published package:
npm install @io-orkes/conductor-javascript zodimport { Agent, AgentRuntime } from '@io-orkes/conductor-javascript/agents';The files under examples/ are not copy/paste-ready as-is because they import the
SDK source tree directly.
cd adk && npm installcd langgraph && npm installcd openai && npm installRequires OPENAI_API_KEY environment variable.
cd vercel-ai && npm installExport environment variables:
export AGENTSPAN_LLM_MODEL=openai/gpt-4o-mini
export AGENTSPAN_SERVER_URL=http://localhost:8080/api
# export AGENTSPAN_AUTH_KEY=<key> # if authentication is enabled
# export AGENTSPAN_AUTH_SECRET=<secret>The AGENTSPAN_LLM_MODEL variable uses the provider/model-name format. Examples:
| Provider | Model string | API key env var |
|---|---|---|
| OpenAI | anthropic/claude-sonnet-4-6 (default) |
OPENAI_API_KEY |
| Anthropic | anthropic/claude-sonnet-4-20250514 |
ANTHROPIC_API_KEY |
| Google Gemini | google_gemini/gemini-2.0-flash |
GOOGLE_GEMINI_API_KEY |
| AWS Bedrock | aws_bedrock/... |
AWS credentials |
| Azure OpenAI | azure_openai/... |
Azure credentials |
# Core agent examples (run from the repository root)
npx tsx examples/agents/01-basic-agent.ts
npx tsx examples/agents/15-agent-discussion.ts
# Framework-specific examples (install their deps first, see 1.1)
cd examples/agents/adk && npx tsx 01-basic-agent.ts
cd examples/agents/langgraph && npx tsx 01-hello-world.ts
cd examples/agents/openai && npx tsx 01-basic-agent.ts| # | Example | What it demonstrates |
|---|---|---|
| 01 | Basic Agent | Simplest possible agent — single LLM, no tools |
| 02 | Tools | Multiple tool() functions, approval-required tools |
| # | Example | What it demonstrates |
|---|---|---|
| 02a | Simple Tools | Two tools (weather, stocks) — LLM picks the right one |
| 02b | Multi-Step Tools | Chained tool calls: lookup → fetch → calculate → answer |
| 03 | Structured Output | Zod outputType for typed, validated responses |
| 04 | HTTP & MCP Tools | Server-side tools via httpTool() and mcpTool() — no workers needed |
| 04b | MCP Weather | Real-time weather via an MCP server |
| 14 | Existing Workers | Use existing worker task functions directly as agent tools |
| 33 | Single Turn Tool | Single-turn tool invocation with immediate response |
| 33 | External Workers | Reference workers in other services — no local code needed |
| # | Example | Pattern |
|---|---|---|
| 05 | Handoffs | LLM-driven delegation to sub-agents |
| 06 | Sequential Pipeline | Agents run in order, output chains forward |
| 07 | Parallel Agents | All agents run concurrently, results aggregated |
| 08 | Router Agent | Router selects which sub-agent runs |
| 13 | Hierarchical Agents | 3-level nested hierarchy: CEO → leads → specialists |
| 15 | Agent Discussion | Round-robin debate between agents, piped to a summarizer |
| 16 | Random Strategy | Random agent selected each turn (brainstorming) |
| 17 | Swarm Orchestration | Automatic transitions via handoff conditions |
| 18 | Manual Selection | Human picks which agent speaks each turn |
| 20 | Constrained Transitions | Restrict which agents can follow which |
| 29 | Agent Introductions | Agents introduce themselves before a group discussion |
| 38 | Tech Trends | Multi-agent research pipeline with live HTTP API tools |
| # | Example | What it demonstrates |
|---|---|---|
| 09 | Human-in-the-Loop | Tool approval gate — approve or reject before execution |
| 09b | HITL with Feedback | Custom feedback via respond() — editorial review |
| 09c | HITL with Streaming | Real-time event stream with approval pauses |
| 09d | Human Tool | Human-as-a-tool for interactive conversations |
| 27 | User Proxy Agent | Human stand-in agent for interactive conversations |
| # | Example | What it demonstrates |
|---|---|---|
| 10 | Guardrails | Output validation with guardrail functions |
| 21 | Regex Guardrails | Pattern-based blocking (emails, SSNs) and allow-listing |
| 22 | LLM Guardrails | AI-powered content safety evaluation via a judge LLM |
| 31 | Tool Guardrails | Pre-execution validation on tool inputs |
| 32 | Human Guardrail | Pause agent for human review when output fails |
| 35 | Standalone Guardrails | Use guardrails as plain callables — no agent needed |
| 36 | Simple Agent Guardrails | Mixed regex + custom guardrails on agents |
| 37 | Fix Guardrail | Auto-correct output instead of retrying |
| # | Example | What it demonstrates |
|---|---|---|
| 11 | Streaming | Real-time event stream with runtime.stream() |
| 12 | Long-Running | Async polling with runtime.start() |
| # | Example | What it demonstrates |
|---|---|---|
| 08 | Credentials | Server-side credential injection |
| 16 | Isolated Tool | Credentials scoped to a single tool |
| 16b | Non-Isolated | Credentials shared across tools |
| 16e | HTTP Tool | Credentials in HTTP tool headers |
| 16f | MCP Tool | Credentials in MCP tool headers |
| # | Example | What it demonstrates |
|---|---|---|
| 63 | Deploy | Register agent with the server |
| 63b | Serve | Start a long-running worker |
| 63c | Run by Name | Execute a pre-deployed agent |
| 63d | Serve from Package | Serve agents from a package |
| 63e | Run Monitoring | Monitor running executions |
| Directory | Framework | Examples |
|---|---|---|
| adk/ | Google ADK | 35 examples — agents, tools, streaming, planners, security |
| langgraph/ | LangGraph | 45 examples — state graphs, react agents, memory, RAG |
| openai/ | OpenAI Agents SDK | 10 examples — agents, tools, handoffs, guardrails |
| vercel-ai/ | Vercel AI SDK | 10 examples — agents, tools, streaming, HITL |
| quickstart/ | Agentspan Quickstart | 5 examples — minimal getting-started guides |