Skip to main content

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 Console streaming

๐Ÿ“ฆ 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 condition for dynamic routing
  • DiGraphGroupChat โ€“ Executes the graph using agent runtime (optionally threaded)

๐Ÿงช Examples

Available in examples/:

  • sequential.py โ€“ A โ†’ B โ†’ C
  • parallel.py โ€“ fan-out, join-any, join-all
  • conditional.py โ€“ conditional branching using content triggers
  • loop.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autogen_graph-0.1.0.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autogen_graph-0.1.0-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

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

Hashes for autogen_graph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f27c01a3905cb1609af0c3404d62572aa1efedc7b5efaba635bde32dcdc80f74
MD5 1173d6adf2d0bdcc064dc1a2ad84759a
BLAKE2b-256 30a9a3358a7c6c949f4d1c000a6f826f33a8fbae239e4b93c71b491404677d31

See more details on using hashes here.

Provenance

The following attestation bundles were made for autogen_graph-0.1.0.tar.gz:

Publisher: release.yaml on abhinav-aegis/autogen-graph

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for autogen_graph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4552de6993afb8b0026d7cd560f66bd2bc233e7c3163d9b30d91546d6498aeb
MD5 a5cea4c5fce41506d0d94ca467baf558
BLAKE2b-256 78ec46021bb49260e1e80e4b082b6e9a0c40c0aa4c39d656b3c7bdc22d4c6107

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page