Skip to main content
Already read Your First Agent? This goes deeper.

Agent Structure

Agents follow a simple directory structure with separate YAML and TypeScript files:

The Handler Pattern

Conductor follows an interface vs implementation pattern:
  • YAML declares WHAT - The agent’s contract: inputs, outputs, and metadata
  • TypeScript defines HOW - The actual implementation logic
This keeps agents testable, type-safe, and debuggable while avoiding complex logic in YAML.

Simple Handler Example

Here’s a minimal agent showing the handler pattern:
Key Points:
  • The YAML handler: ./greeter.ts points to the TypeScript file
  • The TypeScript function signature: (input, ctx) => Promise<Output>
  • The function name can be anything (typically matches the agent name)
  • Full type safety with TypeScript interfaces
  • Access location and edge context for geo-aware behavior

Complete Agent Example

Caching Strategies

Agent-Level Caching

Cache the entire agent execution:

Operation-Level Caching

Cache specific operations:

Dynamic Cache Keys

Retry Logic

Basic Retry

Advanced Retry

Conditional Retry

Error Handling

Fallback Pattern

Error Logging

Graceful Degradation

Testing Agents

Unit Tests

Integration Tests

Mock Data

Performance Optimization

Parallel Operations

Minimize Dependencies

Early Termination

Using Agents in TypeScript Ensembles

Once you’ve created YAML agents with TypeScript handlers, use them in TypeScript ensembles:

Validating Your Setup

Validate both agents and ensembles:
For complete TypeScript API documentation, see the TypeScript API Reference.

Best Practices

  1. Single Responsibility - One agent, one job
  2. Cache Aggressively - Cache expensive operations
  3. Handle Failures - Always have fallbacks
  4. Use Retry Logic - For transient failures
  5. Test Thoroughly - Unit and integration tests
  6. Document Inputs/Outputs - Clear schemas
  7. Monitor Performance - Track execution times
  8. Version with Edgit - Track changes over time
  9. Use Location Context - Leverage location for localization and compliance
  10. Consider Edge Context - Use edge for security decisions

Next Steps

TypeScript API

Complete TypeScript reference

Writing Ensembles

Orchestrate agents

Location Context

Geographic data and compliance

Edge Context

Network and protocol info