Agent Framework Samples
This repository contains small, focused samples that demonstrate how to build agents and workflows using Agent Framework. The examples cover sequential and concurrent workflows, branching and switching, human-in-the-loop interactions, visualization, multi-agent orchestration (Magentic), and basic agent patterns.
Prerequisites
- Python 3.11+ recommended
- Create and activate a virtual environment
- Windows PowerShell:
python -m venv .venv && .venv\\Scripts\\Activate.ps1 - bash/zsh:
python -m venv .venv && source .venv/bin/activate
- Windows PowerShell:
- Install dependencies (typical):
pip install agent-framework-core azure-identity pydantic aioconsole httpx- For A2A sample:
pip install a2a-client(or the appropriate package providinga2a.client)
- Azure credentials for Azure OpenAI clients used by the samples
- Install Azure CLI and sign in:
az login - Samples use
AzureCliCredential()orDefaultAzureCredential()
- Install Azure CLI and sign in:
- Optional: OPENAI-style API key if using the OpenAI clients in
Agent/- Set
OPENAI_API_KEYif needed
- Set
Configuration
- Update endpoints and deployments in
Workflow/agent_client_factory.pyandAgent/agent_client_factory.pyto match your Azure OpenAI resource, project endpoint, and deployment names. - Some samples generate diagrams into
Workflow/diagrams/. Ensure the folder exists (it is included) and that graphviz or required tooling is available viaagent_frameworkif exporting to PNG/PDF.
How to Run
- From the repo root, with your virtual environment active:
python <path-to-script>.py - Most scripts run standalone and print results to the console. Some prompt for input.
Agent Samples
Agent/agent_minimal.py— Minimal agent that responds to a simple prompt.Agent/agent_basic.py— Agent with text and image content, shows both streaming and non‑streaming calls.Agent/agent_to_agent.py— Agent2Agent (A2A) protocol integration. Requires an external A2A‑compliant agent andA2A_AGENT_HOSTenv var.Agent/agent_tools.py— ChatAgent using tools: Microsoft Learn MCP + Web Search to gather up‑to‑date info (requires network access).Agent/agent_observability.py— Minimal agent with observability enabled viasetup_observability(uses OpenTelemetry under the hood).Agent/agent_multi_threads.py— Demonstrates multiple concurrent conversation threads on a single agent instance.Agent/agent_middleware.py— Shows function middleware logging with a simple tool (get_time).
Workflow Samples
Workflow/workflow_sequential.py— Sequential workflow of simple executors that transform text (uppercase -> uppercase -> reverse) and yield final output.Workflow/workflow_concurrent.py— Fan‑out/fan‑in numeric example computing count, sum, and average concurrently, then aggregating outputs.Workflow/workflow_agents.py— Simple two‑agent chain: Writer -> Reviewer. Generates a diagram inWorkflow/diagrams/workflow_agents.svg.Workflow/workflow_visualization.py— Fan‑out/fan‑in with three agent executors (research/marketing/legal). Demonstrates visualization to SVG, Mermaid, and Digraph.Workflow/workflow_request_and_response.py— Human‑in‑the‑loop “number guessing” game usingRequestInfoExecutor. Streams turns and waits for your input.Workflow/workflow_branching_conditional.py— Conditional branching based on a spam detection agent’s JSON output; routes to email drafting or spam handling. Reads samples fromWorkflow/mail/.Workflow/workflow_branching_switch_case.py— Switch‑case branching with three outcomes: NotSpam, Spam, Default (Uncertain). Chains to email assistant for legitimate emails.Workflow/workflow_branching_multi_selection.py— Showsadd_multi_selection_edge_groupplaceholder (TODO) plus active switch‑case flow as above.Workflow/workflow_magentic.py— Magentic multi‑agent orchestration (researcher + code interpreter). Streams planning, agent messages, and a final synthesized result. Auto‑approves plan review.Workflow/world_cup_2026.py— Multi‑expert analysis and aggregation workflow for World Cup 2026 favorites. Includes a simple user‑prediction manager and streaming synthesis.Workflow/workflow_handoff.py— WIP handoff/triage pattern (triage agent to domain tutors). This file contains placeholder code and unresolved references; treat as in‑progress.Workflow/workflow_checkpoints.py— Demonstrates checkpointing: run until a human approval is requested, list checkpoints, and resume from the latest checkpoint by supplying the pending response.
Diagrams and Utilities
Workflow/agent_utilities.py—generate_workflow_visualization(workflow, type, name)saves/export diagrams (SVG/PNG/PDF) or prints Mermaid/Digraph.get_input_text()reads from stdin, CLI args, or interactive prompt.
- Diagrams are saved under
Workflow/diagrams/(e.g.,workflow_branching_conditional.svg).
Email Samples
Workflow/mail/containsemail.txt,spam.txt, andambiguous_email.txtused by the branching samples.
Environment Notes
- Azure
- Ensure
az loginhas been run and your subscription has access to the configured Azure OpenAI resource. - Edit endpoints and deployment names in
agent_client_factory.pyfiles as needed.
- Ensure
- OpenAI‑style API
- If you switch to the OpenAI client variants, set
OPENAI_API_KEYand adjust base URLs accordingly.
- If you switch to the OpenAI client variants, set
- A2A Sample
- Set
A2A_AGENT_HOSTto an A2A‑compliant agent URL and ensure/.well-known/agent.jsonis available.
- Set
Quick Start Commands
- Sequential:
python Workflow/workflow_sequential.py - Concurrent:
python Workflow/workflow_concurrent.py - Agents chain:
python Workflow/workflow_agents.py - Visualization:
python Workflow/workflow_visualization.py - Human‑in‑loop:
python Workflow/workflow_request_and_response.py - Branching (conditional):
python Workflow/workflow_branching_conditional.py - Switch‑case:
python Workflow/workflow_branching_switch_case.py - Checkpoints:
python Workflow/workflow_checkpoints.py - Magentic:
python Workflow/workflow_magentic.py - World Cup:
python Workflow/world_cup_2026.py - Agent basics:
python Agent/agent_basic.pyorpython Agent/agent_minimal.py - Agent tools:
python Agent/agent_tools.py - Agent observability:
python Agent/agent_observability.py - Agent multi‑threads:
python Agent/agent_multi_threads.py - Agent middleware:
python Agent/agent_middleware.py - A2A:
python Agent/agent_to_agent.py(withA2A_AGENT_HOSTset)
Troubleshooting
- Import errors for agent_framework or Azure clients: verify
agent-framework-coreandazure-identityare installed and your Python interpreter matches the virtual environment. - Credential issues: run
az loginagain or switch toDefaultAzureCredentialwith proper environment variables. - Diagram export errors: some formats may require Graphviz or OS packages; try SVG first or install Graphviz.
- Endpoint/Deployment errors: update
Workflow/agent_client_factory.pyto match your Azure OpenAI resource configuration.