Appearance
Multi-Agent API
Graph
python
from elsai.multiagent import GraphDeterministic, 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 msSwarm
python
from elsai.multiagent import SwarmAutonomous, collaborative agent orchestration.
Swarm.__init__
python
Swarm(
agents,
*,
swarm_id=None,
state=None,
hooks=None,
plugins=None,
session_manager=None,
trace_attributes=None,
)| Parameter | Type | Description |
|---|---|---|
agents | list[Agent] | The agents in the swarm |
swarm_id | str | None | Swarm identifier |
state | AgentState | dict | None | Shared state |
hooks | list | None | Lifecycle 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.
| Parameter | Default | Description |
|---|---|---|
name | agent.name | Tool name shown to the model |
description | agent.description | Tool description |
preserve_context | False | Preserve 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.
| Attribute | Type | Description |
|---|---|---|
node | Agent | The agent about to execute |
input | str | Input being passed to the agent |
AfterNodeCallEvent
Fires after each agent (node) finishes.
| Attribute | Type | Description |
|---|---|---|
node | Agent | The agent that just executed |
result | NodeResult | The result from this node |