Skip to content

PyAgenity Tutorials

Welcome to PyAgenity! This tutorial series will guide you through building intelligent agents and multi-agent workflows, from basic graph construction to advanced patterns like streaming, persistence, and tool integration.

🎯 What You'll Learn

PyAgenity is a lightweight Python framework for building agent graphs on top of LiteLLM. By the end of these tutorials, you'll understand how to:

  • Build and execute agent workflows using StateGraph and nodes
  • Manage conversation state and message flow with AgentState
  • Create tool-calling agents using ToolNode and dependency injection
  • Add persistence with checkpointers and memory stores
  • Stream real-time responses and monitor execution events
  • Use prebuilt agent patterns for common scenarios

🚀 Prerequisites

Before diving in, ensure you have:

  • Python 3.12+ installed
  • Basic familiarity with async/await patterns
  • Experience with LLM APIs (OpenAI, Gemini, etc.)
  • Comfort with command-line tools and environment variables

Quick Setup

  1. Install PyAgenity with your preferred LLM provider:

    pip install pyagenity[litellm]
    # Optional: add persistence and tools
    pip install pyagenity[pg_checkpoint,mcp]
    

  2. Set up environment variables in .env:

    # For LiteLLM examples
    OPENAI_API_KEY=your_openai_key
    # Or use Gemini
    # GEMINI_API_KEY=your_gemini_key
    

  3. Clone examples to experiment:

    git clone https://github.com/Iamsdt/PyAgenity.git
    cd PyAgenity/examples/react
    python react_sync.py  # Your first agent!
    

📚 Tutorial Path

Follow these tutorials in order for the best learning experience:

🏗️ Foundation

  1. Graph Fundamentals - Build your first agent with StateGraph, nodes, and edges
  2. State & Messages - Master conversation state and message schemas
  3. Tools & Dependency Injection - Create tool-calling agents with ToolNode
  4. React Agent Patterns - Complete guide to ReAct agents: basic patterns, DI, MCP, streaming

🔀 Control & Flow

  1. Control Flow & Routing - Conditional edges, interrupts, and error handling
  2. Persistence & Memory - Save state with checkpointers and stores
  3. Streaming & Events - Real-time responses and observability

🎯 Advanced Patterns

  1. Prebuilt Agents & Orchestration - Ready-to-use patterns and multi-agent workflows

💡 Learning Tips

  • Run the examples: Every tutorial references working code in examples/. Clone, modify, and experiment!
  • Start simple: Build a basic graph first, then add complexity gradually
  • Use the console: The ConsolePublisher shows you what's happening under the hood
  • Debug with state: Use ResponseGranularity.FULL to inspect complete execution state

📖 Additional Resources

🔗 Quick Navigation

Tutorial Focus Key Files
Graph Fundamentals StateGraph, nodes, compilation examples/react/react_sync.py
State & Messages AgentState, message handling pyagenity/state/, pyagenity/utils/message.py
Tools & DI ToolNode, dependency injection examples/react-injection/, examples/react-mcp/
React Agents Complete ReAct guide: basic, DI, MCP, streaming examples/react*/
Control Flow Conditional routing, interrupts examples/react/react_weather_agent.py
Persistence Checkpointers, stores pyagenity/checkpointer/, pyagenity/store/
Streaming Real-time responses, events examples/react_stream/
Advanced Prebuilt agents, orchestration pyagenity/prebuilt/agent/

Ready to build your first agent? Start with Graph Fundamentals!