Graph based execution for Autogen agentchat agents
Project description
autogen-graph
Directed Graph-based execution engine for Autogen agents.
autogen-graph allows you to coordinate multi-agent interactions using a flexible, cycle-aware graph structure. It is designed for modeling complex flows, including sequential chains, loops, conditionals, and fan-out/join patterns, using Autogen-compatible agents.
๐ก Why Graph-Based Workflows?
Autogen currently provides powerful abstractions for team-based agent interaction via group chats. However, its default broadcast-style message flow lacks precise control over agent execution order, branching, and routing.
A graph-based execution model brings:
- Explicit control over execution flow: You define exactly what runs when and where.
- Agent context isolation: Each node is an independent unit that takes one input and emits one output, improving predictability and modularity.
- Reusability and clarity: Each node can encapsulate logic (including group chats) and expose only the final output.
- Support for loops, conditions, and escalations: Graph edges can dynamically route based on message content.
- Extensibility: Enables hybrid orchestration models combining autonomy, rule-based flow, and parallelism.
This aligns with future directions proposed by the Autogen team (issue #4623), creating a middle ground between full autonomy and deterministic workflow execution.
โจ Features
- ๐ Supports agent loops, cycles, and feedback workflows
- ๐ Execute parallel fan-outs, join-any/join-all, and content-based branching
- ๐งฉ Seamlessly integrates with
AssistantAgent,GroupChat, and Autogen runtimes - ๐งช Easily testable using
ReplayChatCompletionClient - ๐ฅ CLI-friendly with built-in
Consolestreaming
๐ฆ Installation
pip install autogen-graph
๐ Quickstart
import asyncio
from autogen_graph import DiGraph, DiGraphNode, DiGraphEdge, DiGraphGroupChat
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import TextMentionTermination
from autogen_agentchat.ui import Console
from autogen_ext.models.openai import OpenAIChatCompletionClient
# Create OpenAI-backed agents
model_client = OpenAIChatCompletionClient(model="gpt-4o")
poet = AssistantAgent(
name="poet",
model_client=model_client,
system_message="Write a poem about the ocean."
)
critic = AssistantAgent(
name="critic",
model_client=model_client,
system_message="Give feedback on the poem. Respond with 'APPROVE' if it's good, otherwise explain what to improve."
)
improver = AssistantAgent(
name="improve",
model_client=model_client,
system_message="Improve the poem based on the critic's feedback."
)
# Define a graph: poet โ critic โ improve
graph = DiGraph(
nodes={
"poet": DiGraphNode(name="poet", edges=[DiGraphEdge(target="critic")]),
"critic": DiGraphNode(name="critic", edges=[DiGraphEdge(target="improve")]),
"improve": DiGraphNode(name="improve", edges=[]),
},
default_start_node="poet"
)
team = DiGraphGroupChat(
participants=[poet, critic, improver],
graph=graph,
termination_condition=TextMentionTermination("APPROVE"),
)
async def main():
await Console(team.run_stream("Please write a poem about the ocean."))
if __name__ == "__main__":
asyncio.run(main())
๐ Project Structure
โโโ LICENSE.md
โโโ README.md
โโโ examples
โ โโโ conditional.py
โ โโโ loop.py
โ โโโ parallel.py
โ โโโ sequential.py
โโโ main.py
โโโ pyproject.toml
โโโ src
โ โโโ autogen_graph
โ โโโ __init__.py
โ โโโ _digraph_group_chat.py
โโโ tests
โ โโโ test_digraph_group_chat.py
โโโ uv.lock
๐ Core Components
- DiGraph โ Encodes node-to-node agent execution paths (allows cycles)
- DiGraphNode โ Represents an agent + outgoing edges
- DiGraphEdge โ Supports optional
conditionfor dynamic routing - DiGraphGroupChat โ Executes the graph using agent runtime (optionally threaded)
๐งช Examples
Available in examples/:
sequential.pyโ A โ B โ Cparallel.pyโ fan-out, join-any, join-allconditional.pyโ conditional branching using content triggersloop.pyโ loops and escalation workflows
Run with:
python examples/loop.py
โ Running Tests
pytest tests/
๐ License
MIT ยฉ A Somaraju
๐ Contributions
We welcome PRs! Especially around:
- graph visualization utilities
- debugging and trace visualization
- new edge activation strategies or runtime policies
๐๏ธ TODO
- Build a fluent API to simplify graph construction (e.g.,
graph.add_node(...).connect(...)chaining) - Add examples for handling structured messages, including conditional edge routing based on message fields and source filtering (e.g., only forward messages from specific agents)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file autogen_graph-0.1.0.tar.gz.
File metadata
- Download URL: autogen_graph-0.1.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f27c01a3905cb1609af0c3404d62572aa1efedc7b5efaba635bde32dcdc80f74
|
|
| MD5 |
1173d6adf2d0bdcc064dc1a2ad84759a
|
|
| BLAKE2b-256 |
30a9a3358a7c6c949f4d1c000a6f826f33a8fbae239e4b93c71b491404677d31
|
Provenance
The following attestation bundles were made for autogen_graph-0.1.0.tar.gz:
Publisher:
release.yaml on abhinav-aegis/autogen-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autogen_graph-0.1.0.tar.gz -
Subject digest:
f27c01a3905cb1609af0c3404d62572aa1efedc7b5efaba635bde32dcdc80f74 - Sigstore transparency entry: 195346908
- Sigstore integration time:
-
Permalink:
abhinav-aegis/autogen-graph@5ec891e3ac80393d1fdd5b83c4e2f46f08e6be4e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/abhinav-aegis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@5ec891e3ac80393d1fdd5b83c4e2f46f08e6be4e -
Trigger Event:
release
-
Statement type:
File details
Details for the file autogen_graph-0.1.0-py3-none-any.whl.
File metadata
- Download URL: autogen_graph-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4552de6993afb8b0026d7cd560f66bd2bc233e7c3163d9b30d91546d6498aeb
|
|
| MD5 |
a5cea4c5fce41506d0d94ca467baf558
|
|
| BLAKE2b-256 |
78ec46021bb49260e1e80e4b082b6e9a0c40c0aa4c39d656b3c7bdc22d4c6107
|
Provenance
The following attestation bundles were made for autogen_graph-0.1.0-py3-none-any.whl:
Publisher:
release.yaml on abhinav-aegis/autogen-graph
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autogen_graph-0.1.0-py3-none-any.whl -
Subject digest:
f4552de6993afb8b0026d7cd560f66bd2bc233e7c3163d9b30d91546d6498aeb - Sigstore transparency entry: 195346909
- Sigstore integration time:
-
Permalink:
abhinav-aegis/autogen-graph@5ec891e3ac80393d1fdd5b83c4e2f46f08e6be4e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/abhinav-aegis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@5ec891e3ac80393d1fdd5b83c4e2f46f08e6be4e -
Trigger Event:
release
-
Statement type: