Graph based execution for Autogen agentchat agents
Project description
autogen-graph
Directed Graph-based execution engine for Autogen agents, with optional message filtering.
autogen-graph lets you design deterministic, conditional, and cyclic workflows between Autogen-compatible agents. It supports both graph-based execution control and message filtering to precisely govern when agents run and what messages they see.
💡 What Does This Provide?
Autogen’s default group chats use a broadcast model. While powerful, it lacks precision:
- Agents can't be triggered conditionally.
- Message history grows without control.
- Parallelism and loops require manual workarounds.
autogen-graph solves this by introducing:
🔹 1. Graph-Based Execution (DiGraph)
Define who runs next using nodes and edges.
- Control execution order
- Support parallel fan-outs, joins, conditionals
- Handle loops with runtime-safe cycles
🔹 2. Message Filtering (MessageFilterAgent)
Control what messages each agent sees before they're invoked.
- Restrict to last N messages from a source
- Include only specific message types or senders
- Prevent irrelevant context from leaking
This decouples execution routing from message visibility.
✨ Features
- ✅ Directed graph with support for:
- ⏩ Sequential flows
- 🔀 Parallel branches and joins
- 🔀 Loops with runtime-safe cycles
- ❓ Conditional edge activation
- 🧹
MessageFilterAgentto control per-agent context - 🧪 Test-friendly with
ReplayChatCompletionClient - 💾 CLI-friendly with
Consolestreaming
📆 Quickstart: Graph-based Flow
from autogen_graph import DiGraph, DiGraphNode, DiGraphEdge, DiGraphGroupChat
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.conditions import TextMentionTermination
from autogen_ext.models.openai import OpenAIChatCompletionClient
from autogen_agentchat.ui import Console
import asyncio
model_client = OpenAIChatCompletionClient(model="gpt-4o")
# Define agents
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="Critique the poem and say APPROVE or revise.")
improver = AssistantAgent(name="improve", model_client=model_client, system_message="Improve the poem.")
# Define graph
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."))
asyncio.run(main())
🔍 Message Filtering Example
You can use MessageFilterAgent to restrict what messages an agent receives.
from autogen_graph import MessageFilterAgent, MessageFilterConfig, PerSourceFilter
filtered_critic = MessageFilterAgent(
name="critic",
wrapped_agent=critic,
filter=MessageFilterConfig(
per_source=[
PerSourceFilter(source="poet", position="last", count=1), # only last poet message
PerSourceFilter(source="user", position="first", count=1), # only first user message
]
)
)
team = DiGraphGroupChat(
participants=[poet, filtered_critic, improver],
graph=graph,
termination_condition=TextMentionTermination("APPROVE"),
)
This ensures critic only sees the last message from poet and the first message from user.
🧠 Conceptual Summary
| Concept | Purpose | Component |
|---|---|---|
| Execution control | Decides when an agent runs | DiGraph, DiGraphGroupChat |
| Context filtering | Decides what messages an agent sees | MessageFilterAgent |
Both can be combined seamlessly.
🧪 Tests
pytest tests/
📁 Project Structure
src/autogen_graph/
├── _digraph_group_chat.py # Main graph runner
├── _message_filter_agent.py # Message filtering agent
├── __init__.py
📜 License
MIT ©MIT \xa9 A Somaraju
🙌 Contributions
Welcome! Especially around:
- Graph editors or visualizations
- New agent container wrappers (e.g., summarizer)
- Message transformation logic
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.1.tar.gz.
File metadata
- Download URL: autogen_graph-0.1.1.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6cab427bdbc9abc8f97a0681ea9ba9dac9b25a243581c380206eecddfe7c8751
|
|
| MD5 |
d19be18767cf3ef25fe929572ddf7cc8
|
|
| BLAKE2b-256 |
f3d12fd2e9d3455e663581532a8b40dd1b4a54346b82dd14096a38aa294f121c
|
Provenance
The following attestation bundles were made for autogen_graph-0.1.1.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.1.tar.gz -
Subject digest:
6cab427bdbc9abc8f97a0681ea9ba9dac9b25a243581c380206eecddfe7c8751 - Sigstore transparency entry: 195937902
- Sigstore integration time:
-
Permalink:
abhinav-aegis/autogen-graph@6004ebe28cd4456f92641d3d1496e8100655eb10 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/abhinav-aegis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@6004ebe28cd4456f92641d3d1496e8100655eb10 -
Trigger Event:
release
-
Statement type:
File details
Details for the file autogen_graph-0.1.1-py3-none-any.whl.
File metadata
- Download URL: autogen_graph-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 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 |
56b9fd1613f604ddd66931bceee2535f8e76ee8ad3e32992d85812c49dd5eecc
|
|
| MD5 |
1ff820963ce4b3a3e9f3372aa2e5daeb
|
|
| BLAKE2b-256 |
4b1add00f53e2f979e555c787812f2237336e402afb583cd1ffd3346bc6ad15d
|
Provenance
The following attestation bundles were made for autogen_graph-0.1.1-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.1-py3-none-any.whl -
Subject digest:
56b9fd1613f604ddd66931bceee2535f8e76ee8ad3e32992d85812c49dd5eecc - Sigstore transparency entry: 195937903
- Sigstore integration time:
-
Permalink:
abhinav-aegis/autogen-graph@6004ebe28cd4456f92641d3d1496e8100655eb10 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/abhinav-aegis
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yaml@6004ebe28cd4456f92641d3d1496e8100655eb10 -
Trigger Event:
release
-
Statement type: