Decorator used to dynamically create a middleware with the after_agent hook.
Async version is aafter_agent.
after_agent(
func: _CallableWithStateAndRuntime[StateT, ContextT] | None = None,
*,
state_schema: type[StateT] | None = None,
tools: list[BaseTool] | None = None,
can_jump_to: list[JumpTo] | None = None,
name: str | None = None
) -> Callable[[_CallableWithStateAndRuntime[StateT, ContextT]], AgentMiddleware[StateT, ContextT]] | AgentMiddleware[StateT, ContextT]The decorated function should return:
dict[str, Any] - State updates to merge into the agent stateCommand - A command to control flow (e.g., jump to different node)None - No state updates or flow control| Name | Type | Description |
|---|---|---|
func | _CallableWithStateAndRuntime[StateT, ContextT] | None | Default: NoneThe function to be decorated. Must accept: |
state_schema | type[StateT] | None | Default: NoneOptional custom state schema type. If not provided, uses the default |
tools | list[BaseTool] | None | Default: NoneOptional list of additional tools to register with this middleware. |
can_jump_to | list[JumpTo] | None | Default: NoneOptional list of valid jump destinations for conditional edges. Valid values are: |
name | str | None | Default: NoneOptional name for the generated middleware class. If not provided, uses the decorated function's name. |