Skip to main content
Use a native integration when it fits your agent. For another framework or a custom loop, provide an asynchronous callback that accepts an Invocation.

Connect your agent

The callback receives task input, phase, current instructions, and—during reflection—feedback and the previous result. It must actually give those instructions and the supplied tool to the model. In this integration template, run_model_loop / runModelLoop and the business tools are your application code. They must translate the tool callbacks into the model’s native format and reject unavailable tools in the dispatcher. The example wraps the call in a trace; keep your existing model/tool instrumentation for diagnostic detail.
run() returns the task result. A failure notice can cause a second invocation with phase reflection; that phase’s reply does not replace the task reply. During validation, use the fresh assigned state and avoid replaying task conversation history. The generic interface cannot enforce restrictions inside arbitrary host code. During reflection, expose and execute only reflect_bash; do not leave domain actions reachable through a hidden dispatcher or unrestricted host shell. Refresh current instructions at your model checkpoints if the agent edits active memory during the loop.

Streaming and custom boundaries

Use an explicit boundary when you control the graph or stream. Consume the stream inside it so final traces belong to that execution:
execution() seals working changes and schedules evaluation. It does not call your agent again. Once you have the completed task result/history, continue explicitly:
This also supports feedback that becomes available after the original agent returned. Reflect does not restart an agent without a host-supplied continuation. Pass the history needed by your loop, or let its native session own that history; do not append both copies.

Submit already completed traces

An application that already knows its trace IDs can submit them directly:
Use real task trace UUIDs from the same project, a unique execution identity, and a meaningful application boundary. A session name alone cannot identify an execution. Reusing the same trace under a different execution ID is rejected. Submission evaluates evidence; it does not provide conversation history, tools, or a replay environment.