Skip to content

Multi-agent ​

One file can hold several Agent blocks and a block that runs them together. There are three ways to combine agents:

PatternBlockLoaderUse it when
Graphtype: Graphyaml_to_graphAgents hand work along edges, including fan-out and loops
Workflowtype: Workflowyaml_to_workflowAgents run as fixed steps, with an optional parallel group
Agent as a tooltype: AgentAsTool in toolsyaml_to_agentA supervisor decides when to call a specialist

Every agent in these blocks is a normal Agent block. It can have its own tools, memory, knowledge, guardrails, and MCP. The Python runtime behind each pattern is in Multi-agent.

Each example below is a complete file. Set OPENAI_API_KEY before running.


Graph ​

nodes maps a node id to an Agent block. edges connects them with from and to. A node runs once all the nodes pointing at it have finished, and it receives their output.

report_graph.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

extractor:
  type: Agent
  name: extractor
  system_prompt: Extract 3-5 bullet facts from the user text. Output bullets only.
  model: ${openai}
  tools: []

analyst:
  type: Agent
  name: analyst
  system_prompt: Given upstream bullets, list one insight per bullet in a short paragraph.
  model: ${openai}
  tools: []

reporter:
  type: Agent
  name: reporter
  system_prompt: Write a 3-sentence executive summary from the analysis. No bullet lists.
  model: ${openai}
  tools: []

report_graph:
  type: Graph
  graph_id: report_graph
  nodes:
    extractor: ${extractor}
    analyst: ${analyst}
    reporter: ${reporter}
  edges:
    - from: extractor
      to: analyst
    - from: analyst
      to: reporter
  reset_on_revisit: false
python
from elsai.config import yaml_to_graph

graph = yaml_to_graph("report_graph.yaml", entry="report_graph")
result = graph("Q3 revenue rose 12%. Churn fell to 3%. Two enterprise deals slipped to Q4.")
print(result)
KeyWhat it does
nodesNode id to ${block} of a type: Agent block
edgesList of from / to node ids
entry_pointsNode ids where a run starts. When unset, every node with no incoming edge is an entry point
max_node_executionsCap on node runs in one graph run. Use it with loops
execution_timeoutSeconds for the whole graph
node_timeoutSeconds for one node
reset_on_revisittrue clears a node's messages when an edge returns to it. false keeps them

An edge condition is rejected, because a condition is a Python function. session_manager, hooks, hook_providers, and plugins are not allowed on the Graph block.


Workflow ​

steps lists Agent blocks that run in order. Each step receives the previous step's output.

Sequential steps ​

report_flow.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

researcher:
  type: Agent
  name: researcher
  system_prompt: Research the given topic in 3 short bullet points. Be factual and concise.
  model: ${openai}
  tools: []

writer:
  type: Agent
  name: writer
  system_prompt: Turn the research bullets into a polished 2-paragraph mini-report for a busy executive.
  model: ${openai}
  tools: []

report_flow:
  type: Workflow
  name: report_flow
  steps:
    - ${researcher}
    - ${writer}
python
from elsai.config import yaml_to_workflow

pipeline = yaml_to_workflow("report_flow.yaml", entry="report_flow")
print(pipeline("Electric vehicle adoption in Europe"))

Without templates, the first step receives the task. Each later step receives the previous output together with the original task.

A parallel group ​

A parallel: entry runs its agents at the same time on the same input. merge_template then builds the input for the next step.

research_flow.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

researcher:
  type: Agent
  name: researcher
  system_prompt: Summarize the topic in exactly 3 bullet points.
  model: ${openai}
  tools: []

sentiment:
  type: Agent
  name: sentiment
  system_prompt: From the input text, state overall sentiment (positive/neutral/negative) in one sentence.
  model: ${openai}
  tools: []

keywords:
  type: Agent
  name: keywords
  system_prompt: From the input text, list 5 comma-separated keywords only.
  model: ${openai}
  tools: []

writer:
  type: Agent
  name: writer
  system_prompt: Using the merged research, sentiment, and keywords, write a 2-sentence headline and one short paragraph.
  model: ${openai}
  tools: []

research_flow:
  type: Workflow
  name: research_flow
  steps:
    - ${researcher}
    - parallel:
        - ${sentiment}
        - ${keywords}
    - ${writer}
  merge_template: |
    Research bullets:
    {step_0}

    Sentiment: {parallel_0}
    Keywords: {parallel_1}
python
from elsai.config import yaml_to_workflow

pipeline = yaml_to_workflow("research_flow.yaml", entry="research_flow")
final, traces = pipeline.run_traced("Launch of a four-day work week at a software company")

print(final)
for trace in traces:
    print(trace.step_number, trace.kind, trace.agent_names)

Templates ​

KeyPlaceholdersWhat it builds
prompt_template{input} (the task), {previous_output}, {step_index}The text each sequential step receives
merge_template{input}, {step_N} (sequential step N), {parallel_N} (member N of the group)The text the step after a parallel group receives

pipeline(task) returns the final text. pipeline.run_traced(task) also returns one trace per step, with step_number, kind, agent_names, input, outputs, and carry_after.


Agent as a tool ​

A supervisor lists another agent in its tools, with type: AgentAsTool. The model decides when to call it, like any other tool.

manager.yaml:

yaml
openai:
  type: OpenAIModel
  model_id: "{{$OPENAI_MODEL:gpt-4o-mini}}"

researcher:
  type: Agent
  name: researcher
  description: Finds concise facts about a topic.
  system_prompt: You are a research specialist. Answer in 2-4 sentences with accurate facts only.
  model: ${openai}
  tools: []

manager:
  type: Agent
  name: manager
  description: Helpful assistant that delegates research.
  system_prompt: |
    You are a helpful manager. When the user asks for factual research, call the researcher tool.
    For simple greetings, reply yourself without calling tools.
  model: ${openai}
  tools:
    - elsai_tools.current_time
    - type: AgentAsTool
      agent: ${researcher}
      mode: queue
      preserve_context: false
python
from elsai.config import yaml_to_agent

manager = yaml_to_agent("manager.yaml", entry="manager")
print(manager("Hi!"))
print(manager("Research the boiling point of water at high altitude."))
KeyWhat it does
agent${block} of the specialist type: Agent block
modeWhat happens when the specialist is already busy. See below
preserve_contexttrue passes the supervisor's conversation into the specialist. false starts it from the tool arguments only
name, descriptionOverride the tool name and description the supervisor sees. They default to the specialist's name and description
modeWhen the specialist is busy
reject (default)The call fails straight away
queueThe call waits until the specialist is free. One shared agent
spawnThe call runs on a fresh copy, so parallel calls do not share state

Prebuilt tools, custom tools, and AgentAsTool entries can share one tools list.


Copyright © 2026 elsai foundry.