Installation
- Python
- JavaScript / TypeScript
Basic Usage
The SDK providesAgentClient 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:
- Python
- JavaScript
- TypeScript
- 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 theORCHAGENT_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 usingpython3 for .py entrypoints and node for .js entrypoints.
API Reference
AgentClient
The main class for calling other agents.Creating a Client
- Python
- JavaScript
call()
Call another agent asynchronously.- Python
- JavaScript
Returns:
dict / object - The agent’s response data
Raises: DependencyCallError, TimeoutExceededError, CallChainCycleError
Examples
- Python
- JavaScript
Environment Variables
The SDK uses these environment variables:Error Handling
Both SDKs provide specific exception/error types for different failure modes:- Python
- JavaScript
Exception Reference
Handling Partial Failures
When calling multiple agents, handle failures gracefully:- Python
- JavaScript
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
-
Use
AgentClient()/new AgentClient()for stdin/stdout agents (the common case) — the SDK reads all context from environment variables injected by the gateway. Usefrom_request()/fromRequest()only for custom HTTP servers (FastAPI, Express, etc.) where you need to propagate call chain and deadline from incoming request headers. -
Handle all exception types - Don’t let
DependencyCallErrorcrash your agent -
Use parallel calls when possible - Fan-out to independent agents with
asyncio.gather()(Python) orPromise.allSettled()(JavaScript) -
Pin dependency versions - Use
org/agent@v1, notorg/agent@latest -
Set reasonable timeouts - Account for all dependency calls in your
timeout_ms - Return partial results on failure - Don’t fail completely if one dependency fails
- Python
- JavaScript
Anti-patterns to Avoid
- Don’t hardcode service keys — use
AgentClient()(reads from env) orfrom_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