ExAgent.Patterns.Handoff (ExAgent v0.2.0)

Copy Markdown View Source

State-driven transitions pattern.

Enables dynamic transfer of control between agent processes. A handoff tool is added to an agent's tools list. When the LLM invokes it, the agent's tool loop returns a {:handoff, target, context} tuple to the caller, who can then redirect future messages.

Summary

Functions

Creates a tool that triggers a handoff to the target agent when invoked.

Sends a context to the target agent via GenServer.cast.

Produces a trimmed context suitable for the receiving agent.

Types

handoff_result()

@type handoff_result() :: {:handoff, target :: pid() | atom(), ExAgent.Context.t()}

Functions

build_handoff_tool(name, target, description)

@spec build_handoff_tool(String.t(), pid() | atom(), String.t()) :: ExAgent.Tool.t()

Creates a tool that triggers a handoff to the target agent when invoked.

The tool accepts a "summary" parameter that the LLM uses to summarize the conversation before handoff.

execute_handoff(target, context)

@spec execute_handoff(pid() | atom(), ExAgent.Context.t()) :: :ok

Sends a context to the target agent via GenServer.cast.

transfer_context(context, map)

@spec transfer_context(ExAgent.Context.t(), map()) :: ExAgent.Context.t()

Produces a trimmed context suitable for the receiving agent.

Adds a system message summarizing the handoff.