d:spatch logodocs

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

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:
                break

One-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}"

Next steps

On this page