Skip to main content
The orchagent SDK provides a simple interface for building orchestrator agents that call other agents. It handles authentication, call chain propagation, and error handling automatically. SDKs are available for both Python and JavaScript/TypeScript.

Installation

Requires Python 3.9+.

Basic Usage

The SDK provides AgentClient for calling other agents from within your agent. Most agents use stdin/stdout — create a client with no arguments and the SDK reads all context from environment variables:
The SDK automatically extracts context from environment variables (injected by the gateway):
  • Service key for authentication
  • Call chain for cycle detection
  • Deadline for timeout propagation
  • Remaining hops count

Local vs Server Mode

Both SDKs automatically detect whether to route calls locally or through the gateway based on the ORCHAGENT_LOCAL_EXECUTION environment variable.
When you run an orchestrator with orch run --with-deps, the CLI automatically sets ORCHAGENT_LOCAL_EXECUTION=true so your agent calls dependencies locally.

Server Mode (Default)

In server mode, calls go through the gateway which handles routing, authentication, and sandbox management.

Local Mode

In local mode, calls go directly to locally running agent processes. The SDK spawns subprocesses using python3 for .py entrypoints and node for .js entrypoints.

API Reference

AgentClient

The main class for calling other agents.

Creating a Client

call()

Call another agent asynchronously.
Parameters: Returns: dict / object - The agent’s response data Raises: DependencyCallError, TimeoutExceededError, CallChainCycleError

Examples

Environment Variables

The SDK uses these environment variables:
When running on orchagent’s servers, ORCHAGENT_SERVICE_KEY is automatically injected into your agent’s environment.

Error Handling

Both SDKs provide specific exception/error types for different failure modes:

Exception Reference

Handling Partial Failures

When calling multiple agents, handle failures gracefully:

Best Practices

When to Use the SDK

  • Building orchestrators - Agents that compose multiple leaf agents
  • Multi-step workflows - Chaining agent calls in sequence
  • Fan-out patterns - Calling multiple agents in parallel

Recommendations

  1. Use AgentClient() / new AgentClient() for stdin/stdout agents (the common case) — the SDK reads all context from environment variables injected by the gateway. Use from_request() / fromRequest() only for custom HTTP servers (FastAPI, Express, etc.) where you need to propagate call chain and deadline from incoming request headers.
  2. Handle all exception types - Don’t let DependencyCallError crash your agent
  3. Use parallel calls when possible - Fan-out to independent agents with asyncio.gather() (Python) or Promise.allSettled() (JavaScript)
  4. Pin dependency versions - Use org/agent@v1, not org/agent@latest
  5. Set reasonable timeouts - Account for all dependency calls in your timeout_ms
  6. Return partial results on failure - Don’t fail completely if one dependency fails

Anti-patterns to Avoid

  • Don’t hardcode service keys — use AgentClient() (reads from env) or from_request(request) (reads from HTTP headers) to inherit context automatically
  • Don’t ignore the call chain — it prevents cycles and tracks lineage
  • Don’t hardcode gateway URLs — use the environment variable

Agent Storage

The SDK also includes a storage module for persistent shared state between agents. See the dedicated Agent Storage page for the full reference.

Agent Messages

Send messages from your agents to orch-hq. Use messages for briefings, alerts, reports — anything your agent wants to tell you. See the dedicated Agent Messages page for the full reference.

Agent Tasks

Create and manage tasks from your agents. Tasks appear in orch-hq’s Tasks panel, grouped by urgency. See the dedicated Agent Tasks page for the full reference.

Next Steps

Orchestration

Learn how to build orchestrator agents that compose multiple agents together

Agent Storage

Persistent shared state for multi-agent coordination and checkpoints

Messages

Send messages and notifications from your agents

Tasks

Create and manage tasks from your agents