Docs: "Chat as a tool" multi-agent delegation recipe

Aperta Adatta ai principianti
#354 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
documentation

Direzione di ricerca

Leggi docs/tool-calling/how-it-works.qmd, le pagine adiacenti sul tool-calling, docs/_quarto.yml e le definizioni di register_tool(), chat() e get_cost() in chatlas/_chat.py. Aggiungi un articolo mirato o una sezione concordata sulla delega tra più agenti, collegando issue #43 dove appropriato, e verifica l’esempio e la limitazione documentata relativa alla contabilizzazione dei costi rispetto all’API attuale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

ai-triage:needs-review documentation

Motivation

Pydantic AI's agent-delegation pattern — one agent calls another agent via a tool call — covers most of the practical value people reach for "multi-agent frameworks" for, without needing a graph/orchestration layer. chatlas can already do this today with zero new API: register one Chat's .chat() method (wrapped in a closure with a docstring, exactly like any other tool) as a tool on another Chat via register_tool() (chatlas/_chat.py). This pattern currently isn't documented anywhere — not in docs/tool-calling/ (how-it-works.qmd, displays.qmd, approval.qmd) nor docs/misc/.

Proposed approach

Add a docs article, e.g. docs/tool-calling/multi-agent.qmd (added as a 4th entry to the existing "Tool calling" section in docs/_quarto.yml's sidebar, alongside how-it-works.qmd/displays.qmd/approval.qmd — that section is the natural home since this is fundamentally a tool-calling pattern, not new API).

Minimal accurate example to include (verified against _chat.py's register_tool/chat signatures):

from chatlas import ChatOpenAI

sql_specialist = ChatOpenAI(
    system_prompt="You are a SQL expert. Given a natural-language question and a "
    "table schema, write a single correct SQL query. Return only the query.",
)

def ask_sql_specialist(question: str, schema: str) -> str:
    """
    Delegate a natural-language question to a SQL-writing specialist.

    Parameters
    ----------
    question
        The natural-language question to translate into SQL.
    schema
        The relevant table schema(s) as DDL or a plain-text description.
    """
    return str(sql_specialist.chat(f"Schema:\n{schema}\n\nQuestion: {question}", echo="none"))

coordinator = ChatOpenAI(system_prompt="You help users explore their data.")
coordinator.register_tool(ask_sql_specialist)
coordinator.chat("How many orders were placed last week? (orders table: id, placed_at, status)")

Points to cover in the article:

  • System-prompt separation: the specialist gets its own focused system prompt; the coordinator's stays general. This is the main value over "one chat with many tools."
  • Cost accounting across chats: each Chat has its own get_cost() (_chat.py); there is no combined/rollup accounting across a coordinator + specialist(s) today. State this plainly as a limitation — anyone wanting a total spend needs to sum coordinator.get_cost() + sql_specialist.get_cost() themselves.
  • When to prefer this over one chat with many tools: when a sub-task needs a materially different system prompt, tool set, or even a different/cheaper model, or when you want to cap what context a sub-task is exposed to.
  • Note register_tool's model= parameter for cases where the specialist call needs more structured input than plain strings.

Alternatives / prior art

Related: #43 (a gallery/collection of common tool-calling recipes) — this could live as one gallery entry there instead of/in addition to a standalone article; worth cross-linking either way.

Open questions

  • Standalone article vs. a section added to an existing tool-calling page?
  • Should this also mention to_solver()/InspectAI as a tangential way to evaluate sub-agents, or keep scope tight to the delegation pattern itself?

Drafted from a competitive review of llm / Pydantic AI / LangChain / LiteLLM (July 2026); filed via Claude Code on behalf of @cpsievert.

Lingua principale
Python
Stelle
179
Fork
32
Merge medio
1g 3h
PR unite (30g)
10

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di posit-dev/chatlas

Tutte le issue di posit-dev/chatlas

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.