Skip to content

Multi-Agent API


Graph

python
from elsai.multiagent import Graph

Deterministic, dependency-driven agent orchestration.

Graph.__init__

python
Graph(
    *,
    graph_id=None,
    state=None,
    hooks=None,
    plugins=None,
    session_manager=None,
    trace_attributes=None,
    max_iterations=None,
)

Graph.add_node

python
graph.add_node(agent)

Add an Agent as a node in the graph.

Graph.add_edge

python
graph.add_edge(source_agent, target_agent)

Create a directed edge so target_agent runs after source_agent and receives its output.

Graph.__call__

python
result = graph(prompt)

Execute the graph synchronously.

Graph.invoke_async

python
result = await graph.invoke_async(prompt)

Execute the graph asynchronously.

GraphResult

python
result.output          # str: final combined output
result.status          # "completed" | "failed" | "interrupted"
result.node_results    # dict[str, NodeResult]: per-node results
result.metrics         # Metrics: total token usage
result.execution_time  # float: total time in ms

Swarm

python
from elsai.multiagent import Swarm

Autonomous, collaborative agent orchestration.

Swarm.__init__

python
Swarm(
    agents,
    *,
    swarm_id=None,
    state=None,
    hooks=None,
    plugins=None,
    session_manager=None,
    trace_attributes=None,
)
ParameterTypeDescription
agentslist[Agent]The agents in the swarm
swarm_idstr | NoneSwarm identifier
stateAgentState | dict | NoneShared state
hookslist | NoneLifecycle hooks

Swarm.__call__

python
result = swarm(prompt)

Swarm.invoke_async

python
result = await swarm.invoke_async(prompt)

SwarmResult

Same shape as GraphResult.


Agent.as_tool

python
tool = agent.as_tool(
    *,
    name=None,
    description=None,
    preserve_context=False,
)

Wraps the agent as an AgentTool that can be passed to another agent's tools parameter.

ParameterDefaultDescription
nameagent.nameTool name shown to the model
descriptionagent.descriptionTool description
preserve_contextFalsePreserve conversation history between calls

Multi-agent hooks

python
from elsai.hooks import (
    BeforeNodeCallEvent,
    AfterNodeCallEvent,
    MultiAgentInitializedEvent,
    BeforeMultiAgentInvocationEvent,
    AfterMultiAgentInvocationEvent,
)

BeforeNodeCallEvent

Fires before each agent (node) starts executing.

AttributeTypeDescription
nodeAgentThe agent about to execute
inputstrInput being passed to the agent

AfterNodeCallEvent

Fires after each agent (node) finishes.

AttributeTypeDescription
nodeAgentThe agent that just executed
resultNodeResultThe result from this node

Copyright © 2026 Elsai Foundry.