What’s an Agent?
An agent is a reusable unit of work with:- Inputs: Parameters it accepts
- Operation: What it does (code, think, http, storage, etc.)
- Outputs: Data it returns
agents/ directory at build time (v1.12+) and can be used across multiple ensembles.
Explore the Template Agent
Your project already includes a working agent! Let’s exploreagents/examples/hello/:
agent.yaml
- Operation type:
code(runs JavaScript/TypeScript) - Input schema: Accepts
name(required) andstyle(optional) - Output schema: Returns a
messagestring
index.ts
AgentExecutionContext which provides:
input- Your agent’s parametersenv- Cloudflare bindings (KV, D1, AI, etc.)ctx- ExecutionContext (waitUntil, etc.)
Understanding Operation Types
Agents use different operations based on what they need to do:operation: code
When to use: Run custom TypeScript/JavaScript logic Requires: Function implementation inindex.ts
API keys needed: ❌ No
operation: think
When to use: Call LLM models for reasoning, analysis, generation Requires: Provider and model configuration API keys needed: ✅ Yes (OpenAI, Anthropic) or Cloudflare Workers AIoperation: http
When to use: Make HTTP requests to external APIs Requires: URL and method configuration API keys needed: Depends on APIoperation: data
When to use: Query databases (KV, D1, R2) Requires: Database binding in wrangler.toml API keys needed: ❌ No (uses Cloudflare bindings)Critical: Agent Signatures for Ensembles
All agents MUST use theAgentExecutionContext signature to work in ensembles!
The Correct Pattern ✅
Why This Signature?
When called through an ensemble, Conductor wraps your parameters:- ✅ Works in ensembles (orchestrated workflows)
- ✅ Works with direct calls
- ✅ Works in tests
- ✅ Access to Cloudflare bindings (env)
- ✅ Access to ExecutionContext (ctx)
Wrong Pattern (Don’t Do This) ❌
input.
Using env and ctx
The signature gives you access to powerful features:Quick Rule: Always use
AgentExecutionContext signature. It’s the only pattern that works everywhere!Test the Hello Agent
The template includes working tests. Let’s look attests/basic.test.ts:
Create Your First Custom Agent
Now that you understand how agents work, let’s create a new one.Step 1: Create Agent Directory
Step 2: Define the Agent
Createagents/user/greeter/agent.yaml:
Step 3: Implement the Agent
Createagents/user/greeter/index.ts:
Step 4: Rebuild
Agents are auto-discovered at build time:Step 5: Use Your Agent
Createensembles/greeting-workflow.yaml:
Step 6: Test It
Createtests/greeter.test.ts:
pnpm test
Agent with AI (operation: think)
Let’s create an agent that uses AI for more complex logic.Create AI Analyzer Agent
Createagents/user/analyzer/agent.yaml:
Use the Analyzer
Createensembles/analyze-text.yaml:
Auto-Discovery (v1.12+)
Zero-Config Agent Loading: Agents in theagents/ directory are automatically discovered at build time and registered with your application.
How It Works
- Build-Time Discovery: Vite plugins scan
agents/**/*.yamlduring build - Virtual Modules: Agent configs and handlers are bundled into
virtual:conductor-agents - Runtime Registration:
MemberLoader.autoDiscover()loads all discovered agents automatically
Creating a New Agent
Just create the files - no imports or registration needed:- Create the directory:
agents/user/my-agent/ - Add
agent.yaml(required) - Add
index.ts(optional, foroperation: code) - Rebuild:
pnpm run build - Done! Your agent is now available at
/api/v1/execute/agent/{name}
Using Auto-Discovered Agents
With the auto-discovery API (recommended):Verification
List all discovered agents:Testing with Manual Registration
Note: In unit tests, you can still use manual registration for clarity:Migration from v1.11
If you have existing manual registration code in your entry point: Before (v1.11):Agent Patterns
Pattern 1: Simple Code Agent
Pure logic, no external dependencies:Pattern 2: HTTP Data Fetcher
Fetch from external APIs:Pattern 3: Database Query
Query Cloudflare D1:Pattern 4: AI with Custom Logic
Combine AI with code:Best Practices
1. Keep Agents Focused
Each agent should do ONE thing well:- ✅
user-validator- Validates user data - ❌
user-handler- Validates, stores, sends email, logs (too much!)
2. Use Descriptive Names
- ✅
email-sender,pdf-extractor,sentiment-analyzer - ❌
helper,utils,processor
3. Document Inputs/Outputs
Always define schemas:4. Handle Errors Gracefully
5. Use Caching for HTTP Agents
6. Test Your Agents
Always write tests for custom agents:Troubleshooting
Agent not found after creation
Agent not found after creation
Problem: Created a new agent but it’s not availableFix: Rebuild to trigger auto-discovery:Agents are discovered at build time, not runtime.
ExecutionContext errors in tests
ExecutionContext errors in tests
Problem:
TypeError: this.ctx.waitUntil is not a functionFix: Use proper ExecutionContext mock:AI operation requires API key
AI operation requires API key
Problem: Or use Cloudflare Workers AI (no key needed):
operation: think fails with authentication errorFix: Add API key to wrangler.toml or environment:Agent fails in ensemble but works in tests
Agent fails in ensemble but works in tests
Problem: Agent works when called directly but fails in ensemblesCause: Agent not using See Agent Signatures section above.
AgentExecutionContext signatureFix: Update agent signature:Operation type not supported
Operation type not supported
Problem: Want to use an operation that doesn’t existFix: Use Code operations can do anything TypeScript can do!
operation: code and implement in TypeScript:TypeScript Agent Handlers
Every agent withoperation: code needs a TypeScript handler. Here’s everything you need to know about writing effective handlers.
Handler Structure
The AgentExecutionContext
All handlers receive the same context object:Handler Patterns
Simple Synchronous Handler:Using Agents in TypeScript Ensembles
Once you have YAML agents with TypeScript handlers, you can reference them in TypeScript ensembles:Validating Agents
Validate your agent configurations:Next Steps
Your First Ensemble
Combine agents into workflows
TypeScript API
Complete TypeScript reference
Starter Kit
Use ready-made agents
Testing Guide
Write comprehensive tests
Advanced: Versioning with Edgit (Optional)
If you want component-level versioning, you can use Edgit:Note: Edgit is optional. Standard git version control works great!Learn more about Edgit

