LangEx.Prebuilt.Supervisor (LangEx v0.11.3)

Copy Markdown View Source

Builds a hub-and-spoke team: a supervisor agent delegates to workers and workers report back to the supervisor.

The supervisor is a tool-calling agent whose tools are handoffs to each worker. When it calls one it can attach a task brief; control moves to that worker for a turn; the worker does its work and its result is reported back to the supervisor as an attributed message, so the supervisor can tell each specialist's findings apart from its own reasoning. The supervisor then delegates again or answers and ends the run.

graph =
  LangEx.Prebuilt.Supervisor.create(
    model: "gpt-4o",
    prompt: "You manage a research and a math agent. Delegate.",
    agents: [
      [name: :research, model: "gpt-4o", tools: [search_tool]],
      [name: :math, model: "gpt-4o", tools: [calc_tool]]
    ],
    checkpointer: LangEx.Checkpointer.Memory
  )

How workers see the conversation

Each worker runs on a task-focused view of the conversation — the user request, prior specialist responses, and the supervisor's plain replies — with handoff plumbing (transfer tool calls and their acknowledgements) stripped out, so a worker is not confused by routing it did not perform. A worker's output is reported back as a user-role message attributed to that worker ("Response from the <name> agent: ..."). Attribution both keeps specialist findings distinguishable and leaves the conversation on a user turn, which providers such as Anthropic require.

Options

  • :model / :provider (required) - the supervisor's LLM
  • :agents (required) - list of worker member specs (keyword lists) forwarded to LangEx.Prebuilt.Member.build/1; each must include :name
  • :prompt - supervisor system prompt
  • :tools - extra non-handoff tools for the supervisor (default [])
  • :supervisor_name - supervisor node/agent name (default :supervisor)
  • :output_mode - :full_history (default) reports a worker's full textual output back to the supervisor; :last_message reports only its final message
  • :handoff_tool_prefix - prefix for generated handoff tool names (default names are "transfer_to_<worker>")
  • :checkpointer / :store - persistence and shared memory
  • other options (:temperature, :api_key, ...) are forwarded to the supervisor's LLM node

Summary

Functions

Builds and compiles a supervisor team graph.

Functions

create(opts)

@spec create(keyword()) :: LangEx.Graph.Compiled.t()

Builds and compiles a supervisor team graph.