Agent SDK
Build agents that run inside d:spatch workspaces.
The d:spatch Python SDK (dspatch) lets you build agents that integrate with the d:spatch platform.
It handles communication with the app, logging, lifecycle management, inter-agent messaging, and inquiries.
Integration levels
ClaudeAgentContext
Full integration with the Claude Agent SDK (claude_agent_sdk). Automatic system prompt
augmentation, MCP tool injection, and streaming.
OpenAiAgentContext
Full integration with the OpenAI Agents SDK. Same platform features, different LLM backend.
Base Context
Use any LLM or framework. Wire platform tools manually.
Basic pattern
Every agent follows the same structure regardless of context type:
from dspatch import DspatchEngine
dspatch = DspatchEngine()
@dspatch.agent(ContextType)
async def my_agent(prompt: str, ctx: ContextType):
# Setup, run, yield for next message
...
dspatch.run()The @dspatch.agent decorator registers your function as the agent entry point. DspatchEngine
manages the WebSocket connection to the app, routes incoming messages, and handles lifecycle.
Multi-turn (generator pattern)
Use prompt = yield to suspend execution and wait for the next user message. Return or
yield None to end the session.
@dspatch.agent(ClaudeAgentContext)
async def my_agent(prompt: str, ctx: ClaudeAgentContext):
ctx.setup(system_prompt="You are a helpful assistant.")
async with ctx:
while True:
await ctx.run(prompt)
prompt = yield
if prompt is None:
breakOne-shot pattern
If you don't need multi-turn, return a string. It is automatically sent as a message.
@dspatch.agent(Context)
async def my_agent(prompt: str, ctx: Context):
result = do_something(prompt)
return f"Done: {result}"