PyAgenity¶
PyAgenity is a lightweight Python framework for building intelligent agents and orchestrating multi-agent workflows. It's an LLM-agnostic orchestration tool that works with any LLM providerβuse LiteLLM, native SDKs from OpenAI, Google Gemini, Anthropic Claude, or any other provider. You choose your LLM library; PyAgenity provides the workflow orchestration.
β¨ Key Features¶
- π― LLM-Agnostic Orchestration - Works with any LLM provider (LiteLLM, OpenAI, Gemini, Claude, native SDKs)
- π€ Multi-Agent Workflows - Build complex agent systems with your choice of orchestration patterns
- π Structured Responses - Get
content
, optionalthinking
, andusage
in a standardized format - π Streaming Support - Real-time incremental responses with delta updates
- π§ Tool Integration - Native support for function calling, MCP, Composio, and LangChain tools
- π LangGraph-Inspired Engine - Flexible graph orchestration with nodes, conditional edges, and control flow
- πΎ State Management - Built-in persistence with in-memory and PostgreSQL+Redis checkpointers
- π Human-in-the-Loop - Pause/resume execution for approval workflows and debugging
- π Production-Ready - Event publishing (Console, Redis, Kafka, RabbitMQ), metrics, and observability
- π§© Dependency Injection - Clean parameter injection for tools and nodes
- π¦ Prebuilt Patterns - React, RAG, Swarm, Router, MapReduce, SupervisorTeam, and more
π Quick Start¶
Installation¶
Basic installation with uv (recommended):
uv pip install pyagenity
Or with pip:
pip install pyagenity
Optional Dependencies:
PyAgenity supports optional dependencies for specific functionality:
# PostgreSQL + Redis checkpointing
pip install pyagenity[pg_checkpoint]
# MCP (Model Context Protocol) support
pip install pyagenity[mcp]
# Composio tools (adapter)
pip install pyagenity[composio]
# LangChain tools (registry-based adapter)
pip install pyagenity[langchain]
# Individual publishers
pip install pyagenity[redis] # Redis publisher
pip install pyagenity[kafka] # Kafka publisher
pip install pyagenity[rabbitmq] # RabbitMQ publisher
# Multiple extras
pip install pyagenity[pg_checkpoint,mcp,composio,langchain]
Environment Setup¶
Set your LLM provider API key:
export OPENAI_API_KEY=sk-... # for OpenAI models
# or
export GEMINI_API_KEY=... # for Google Gemini
# or
export ANTHROPIC_API_KEY=... # for Anthropic Claude
If you have a .env
file, it will be auto-loaded (via python-dotenv
).
π Documentation Structure¶
π Tutorials¶
Learn PyAgenity step-by-step with practical examples:
- Graph Fundamentals - Build your first agent with StateGraph, nodes, and edges
- React Agent Patterns - Complete guide: basic patterns, DI, MCP, streaming
- State & Messages - Master conversation state and message handling
- Tools & Dependency Injection - Create tool-calling agents with ToolNode
- Persistence & Memory - Save state with checkpointers and stores
- RAG Implementation - Build retrieval-augmented generation systems
- Plan-Act-Reflect - Advanced reasoning patterns
π Concepts¶
Deep dives into PyAgenity's architecture:
- Graph Architecture - StateGraph, nodes, edges, compiled execution
- State Management - AgentState, checkpointers, stores
- Tools & Integration - ToolNode, MCP, Composio, LangChain
- Control Flow - Conditional routing, interrupts
- Human-in-the-Loop - Approval workflows, pause/resume
- Dependency Injection - InjectQ container patterns
- Publishers & Events - Observability and monitoring
- Response Converters - LLM output normalization
π API Reference¶
Complete API documentation for all modules:
- Graph - StateGraph, CompiledGraph, Node, Edge, ToolNode
- State - AgentState, ExecutionState, MessageContext
- Checkpointer - InMemory, PostgreSQL+Redis
- Store - BaseStore, Qdrant, Mem0
- Publisher - Console, Redis, Kafka, RabbitMQ
- Adapters - LiteLLM, MCP, Composio, LangChain
- Utils - Message, Command, Callbacks, Converters
- Prebuilt Agents - Ready-to-use patterns
π‘ Simple Example¶
Here's a minimal React agent with tool calling:
from dotenv import load_dotenv
from litellm import acompletion
from pyagenity.checkpointer import InMemoryCheckpointer
from pyagenity.graph import StateGraph, ToolNode
from pyagenity.state.agent_state import AgentState
from pyagenity.utils import Message
from pyagenity.utils.constants import END
from pyagenity.utils.converter import convert_messages
load_dotenv()
# Define a tool with dependency injection
def get_weather(
location: str,
tool_call_id: str | None = None,
state: AgentState | None = None,
) -> Message:
"""Get the current weather for a specific location."""
res = f"The weather in {location} is sunny"
return Message.tool_message(
content=res,
tool_call_id=tool_call_id,
)
# Create tool node
tool_node = ToolNode([get_weather])
# Define main agent node
async def main_agent(state: AgentState):
prompts = "You are a helpful assistant. Use tools when needed."
messages = convert_messages(
system_prompts=[{"role": "system", "content": prompts}],
state=state,
)
# Check if we need tools
if (
state.context
and len(state.context) > 0
and state.context[-1].role == "tool"
):
response = await acompletion(
model="gemini/gemini-2.5-flash",
messages=messages,
)
else:
tools = await tool_node.all_tools()
response = await acompletion(
model="gemini/gemini-2.5-flash",
messages=messages,
tools=tools,
)
return response
# Define routing logic
def should_use_tools(state: AgentState) -> str:
"""Determine if we should use tools or end."""
if not state.context or len(state.context) == 0:
return "TOOL"
last_message = state.context[-1]
if (
hasattr(last_message, "tools_calls")
and last_message.tools_calls
and len(last_message.tools_calls) > 0
):
return "TOOL"
return END
# Build the graph
graph = StateGraph()
graph.add_node("MAIN", main_agent)
graph.add_node("TOOL", tool_node)
graph.add_conditional_edges(
"MAIN",
should_use_tools,
{"TOOL": "TOOL", END: END},
)
graph.add_edge("TOOL", "MAIN")
graph.set_entry_point("MAIN")
# Compile and run
app = graph.compile(checkpointer=InMemoryCheckpointer())
inp = {"messages": [Message.from_text("What's the weather in New York?")]}
config = {"thread_id": "12345", "recursion_limit": 10}
res = app.invoke(inp, config=config)
for msg in res["messages"]:
print(msg)
π― Use Cases & Patterns¶
PyAgenity includes prebuilt agent patterns for common scenarios:
π€ Agent Types¶
- React Agent - Reasoning and acting with tool calls
- RAG Agent - Retrieval-augmented generation
- Guarded Agent - Input/output validation and safety
- Plan-Act-Reflect - Multi-step reasoning
π Orchestration Patterns¶
- Router Agent - Route queries to specialized agents
- Swarm - Dynamic multi-agent collaboration
- SupervisorTeam - Hierarchical agent coordination
- MapReduce - Parallel processing and aggregation
- Sequential - Linear workflow chains
- Branch-Join - Parallel branches with synchronization
π¬ Advanced Patterns¶
- Deep Research - Multi-level research and synthesis
- Network - Complex agent networks
See the Prebuilt Agents Reference for complete documentation.
π§ Development¶
For Library Users¶
Install PyAgenity as shown above. The pyproject.toml
contains all runtime dependencies.
For Contributors¶
# Clone the repository
git clone https://github.com/10xhub/PyAgenity.git
cd PyAgenity
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install dev dependencies
pip install -r requirements-dev.txt
# or
uv pip install -r requirements-dev.txt
# Run tests
make test
# or
pytest -q
# Build docs
make docs-serve # Serves at http://127.0.0.1:8000
# Run examples
cd examples/react
python react_sync.py
Development Tools¶
The project uses: - pytest for testing (with async support) - ruff for linting and formatting - mypy for type checking - mkdocs with Material theme for documentation - coverage for test coverage reports
See pyproject.dev.toml
for complete tool configurations.
πΊοΈ Roadmap¶
- β Core graph engine with nodes and edges
- β State management and checkpointing
- β Tool integration (MCP, Composio, LangChain)
- β Streaming and event publishing
- β Human-in-the-loop support
- β Prebuilt agent patterns
- π§ Agent-to-Agent (A2A) communication protocols
- π§ Remote node execution for distributed processing
- π§ Enhanced observability and tracing
- π§ More persistence backends (Redis, DynamoDB)
- π§ Parallel/branching strategies
- π§ Visual graph editor
π License¶
MIT License - see LICENSE for details.
π Links & Resources¶
- GitHub Repository - Source code and issues
- PyPI Project - Package releases
- Examples Directory - Runnable code samples
- API Reference - Complete documentation
- Tutorials - Step-by-step guides
π Contributing¶
Contributions are welcome! Please see our GitHub repository for:
- Issue reporting and feature requests
- Pull request guidelines
- Development setup instructions
- Code style and testing requirements
π¬ Support¶
- Documentation: You're reading it! See Tutorials and Concepts
- Examples: Check the examples directory
- Issues: Report bugs on GitHub Issues
- Discussions: Ask questions in GitHub Discussions
Ready to build intelligent agents? Start with the Tutorials or dive into a Quick Example!