Skip to content

Latest commit

 

History

History

README.md

Sequential Agents Pattern

This demo showcases the Sequential Agents pattern using the Azure AI Agent Framework. Sequential workflows chain multiple agents together where the output of one agent becomes the input for the next, maintaining a shared conversation context throughout.

Features

  • Shared Conversation Context: All agents share and build upon the same conversation history
  • Agent Chaining: Agents execute in a defined sequence (writer → reviewer)
  • Custom Executors: Extend with custom executor classes for specialized processing
  • Participant Factories: Create stateful workflows with proper isolation between instances

Samples Included

File Description
sequential_agents.py Basic sequential workflow with writer and reviewer agents
sequential_custom_executors.py Mixing agents with custom summarizer executors
sequential_participant_factory.py Using participant factories for stateful workflows
sequential_workflow_as_agent.py Wrap sequential workflow as a reusable agent

Prerequisites

  • Python 3.10 or later
  • Azure OpenAI resource with a deployed model
  • Azure CLI authenticated (az login)

Setup

See the main README for complete setup instructions. Quick start:

# From project root
cp .env.example .env  # Then edit with your Azure OpenAI settings
python -m venv venv
venv\Scripts\activate  # Windows (or source venv/bin/activate on Linux/Mac)
pip install -r requirements.txt
az login

Running the Demos

# Basic sequential workflow
python sequential_agents.py

# With custom executors
python sequential_custom_executors.py

# With participant factories
python sequential_participant_factory.py

# Workflow as reusable agent
python sequential_workflow_as_agent.py

How It Works

Basic Sequential Flow

User Input → Writer Agent → Reviewer Agent → Final Output
                 ↓               ↓
         [Shared Conversation Context]

Architecture

  1. SequentialBuilder: Constructs the workflow by chaining participants
  2. Shared Conversation: list[ChatMessage] flows through each participant
  3. Agent Responses: Each agent appends its assistant message to the context
  4. Final Output: Complete conversation history returned when workflow completes

Sample Output

===== Final Conversation =====
------------------------------------------------------------
01 [user]
Write a tagline for a budget-friendly eBike.
------------------------------------------------------------
02 [writer]
Ride farther, spend less—your affordable eBike adventure starts here.
------------------------------------------------------------
03 [reviewer]
This tagline clearly communicates affordability and the benefit of extended 
travel, making it appealing to budget-conscious consumers.

Key Concepts

  • Internal Adapters: The orchestration includes adapter nodes for input normalization and completion
  • Custom Executors: Implement @handler accepting list[ChatMessage] and WorkflowContext
  • Participant Factories: Use lambdas to create stateful participants with proper isolation

Troubleshooting

Authentication errors:

az login --tenant <your-tenant-id>

Module not found: Ensure root-level virtual environment is activated:

cd ..  # Go to project root
venv\Scripts\activate
cd 01-SequentialAgents
python sequential_agents.py

Azure OpenAI errors:

  • Verify AZURE_OPENAI_ENDPOINT is correct
  • Ensure your deployment name matches AZURE_OPENAI_CHAT_DEPLOYMENT_NAME
  • Check that your Azure subscription has access to Azure OpenAI

Learn More