d:spatch logodocs

Context API Reference

Complete reference for the d:spatch Context methods.

This page covers all methods available on the base Context class. ClaudeAgentContext and OpenAiAgentContext inherit these methods.

Properties

Prop

Type

Methods

ctx.message()

Send or stream a message to the user.

# Send a complete message
msg_id = await ctx.message("Here's what I found...")

# Stream tokens incrementally
msg_id = None
for token in tokens:
    msg_id = await ctx.message(token, is_delta=True, id=msg_id)

When is_delta=True, content is appended to the existing message identified by id. When is_delta=False (the default), a new message is created.

If your agent function returns a string and ctx.message() was never called, the return value is automatically sent as a message.

ctx.log()

Log messages to the session's Logs tab.

ctx.log("Starting analysis...")
ctx.log("Something went wrong", level="error")

Levels: debug, info, warn, error. Defaults to info.

ctx.activity()

Record activities such as tool calls or thinking steps.

# Record a discrete activity
await ctx.activity("tool_call", data={"tool": "pytest", "input": "..."})

# Stream an activity incrementally
thinking_id = None
for token in thinking_tokens:
    thinking_id = await ctx.activity(
        "thinking", content=token, is_delta=True, id=thinking_id
    )

ctx.usage()

Record token usage and cost for a generation.

await ctx.usage(
    model="claude-sonnet-4-5-20250929",
    input_tokens=1500,
    output_tokens=800,
    cost_usd=0.012,
)

ctx.files()

Record file operations performed by the agent.

await ctx.files([
    {"file_path": "/workspace/src/main.py", "operation": "write"},
    {"file_path": "/workspace/tests/test_main.py", "operation": "write"},
])

ctx.inquire()

Post an inquiry to the user. This is a blocking call that suspends the agent until the user responds.

response = await ctx.inquire(
    content_markdown="## Question\n\nShould I proceed with the refactor?",
    suggestions=["Option A", "Option B"],
    file_paths=["/workspace/src/main.py"],
    priority="normal",
    timeout_hours=72,
)

ctx.talk_to()

Send a message to another agent in the workspace.

result = await ctx.talk_to("other-agent", "Analyze the test results.")
followup = await ctx.talk_to(
    "other-agent", "What about edge cases?", continue_conversation=True
)

The continue_conversation=True flag continues the existing conversation with the target agent instead of starting a new one.

Summary

MethodBlockingDescription
ctx.message()NoSend or stream a message to the user.
ctx.log()NoLog to the session's Logs tab.
ctx.activity()NoRecord a tool call, thinking step, or other activity.
ctx.usage()NoRecord token usage and cost.
ctx.files()NoRecord file operations.
ctx.inquire()YesPost an inquiry and wait for a response.
ctx.talk_to()YesSend a message to a peer agent and wait for a response.

On this page