module LittleGhost::Agent::Delegation

Give one agent a bounded way to ask another agent for help. Delegated agents can run as managed subagents or behind an ordinary tool call.

class CustomerSupportAgent < LittleGhost::Agent
  subagent ResearchAgent, kind: "research"
  agent_as_tool SentimentAgent, name: "classify_sentiment"
end

The support model receives spawn, messaging, interjection, waiting, and listing tools for the research kind. It sees the sentiment agent as one regular tool whose result is returned to the current turn.

Static declarations may be combined with a resolver that returns dynamic Subagents::Definition objects. Managed conversations persist when a session store is configured unless persist: false keeps them local to one invocation. A class-declared agent exposed as a tool starts with an empty history and a fresh run-scoped Agent for every call. Set preserve_context: true to serialize calls through one Agent and retain its history.

Tool overrides must be classes. A delegated agent otherwise receives only its own declared tools; it does not inherit the parent’s registry. The manager enforces concurrency, identity, wait duration, and persistence bounds.