Create a completion callback middleware for async subagents.
Experimental — this middleware is experimental and may change.
This middleware is added to a subagent's middleware stack. On success or
model-call error, it sends a notification to the configured callback
thread by calling runs.create().
The callback destination is configured with callbackGraphId and
optional url and headers. The target thread is read from
callbackThreadId in the subagent state.
If callbackThreadId is not present in state, the middleware does
nothing.
createCompletionCallbackMiddleware(
options: CompletionCallbackOptions
): AgentMiddleware<ZodObject<__type, strip>, undefined, unknown, readonly ClientTool | ServerTool[]>| Name | Type | Description |
|---|---|---|
options* | CompletionCallbackOptions | Configuration options. |
import { createCompletionCallbackMiddleware } from "deepagents";
const notifier = createCompletionCallbackMiddleware({
callbackGraphId: "supervisor",
});
const agent = createDeepAgent({
model: "claude-sonnet-4-5-20250929",
middleware: [notifier],
});