agentleFS
Azure-SamplesAzure-Samples/python-agentframework-demos/AGENTS.md

python-agentframework-demos

AGENTS.md248 starsChanged 7 months agoMITView on GitHub

This repository contains many examples of using the Microsoft Agent Framework in Python (agent-framework), sometimes abbreviated as MAF. The agent-framework GitHub repo is here: https://github.com/microsoft/agent-framework It contains both Python and .NET agent framework code, but we are only using the Python packages in this repo. MAF is changing rapidly still, so we sometimes need to check the repo changelog and issues to see if there are any breaking changes that might affect our code. The Python changelog is here: https://github.com/microsoft/agent-framework/blob/main/python/CHANGELOG.md

  • Reads credentials
  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 31,774 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When available, the MS Learn MCP server can be used to explore the documentation, ask questions, and get code examples.

    line 15
  2. Distinctive:

    Use informal (tuteo) LATAM Spanish, tu not usted, puedes not podes, etc.

    line 43
  3. Very specific:

    When debugging HTTP interactions between Azure Python SDKs (like azure-ai-evaluation) and Azure services, there are three levels of logging …

    line 49
  4. Very specific:

    After upgrading dependencies or making changes across examples, use this plan to verify everything works.

    line 98
  5. Very specific:

    Start the MCP server first: uv run python examples/mcp_server.py

    line 157

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

Instructions for coding agents

This repository contains many examples of using the Microsoft Agent Framework in Python (agent-framework), sometimes abbreviated as MAF.

The agent-framework GitHub repo is here: https://github.com/microsoft/agent-framework It contains both Python and .NET agent framework code, but we are only using the Python packages in this repo.

MAF is changing rapidly still, so we sometimes need to check the repo changelog and issues to see if there are any breaking changes that might affect our code. The Python changelog is here: https://github.com/microsoft/agent-framework/blob/main/python/CHANGELOG.md

MAF documentation is available on Microsoft Learn here: https://learn.microsoft.com/agent-framework/ When available, the MS Learn MCP server can be used to explore the documentation, ask questions, and get code examples.

Package management

This project uses uv for dependency management. Use uv commands instead of pip:

uv add <package>
uv sync

Spanish translations

There are Spanish equivalents of each example in /examples/spanish.

Each example .py file should have a corresponding file with the same name under /examples/spanish/ that is the translation of the original, but with the same code. Here's a guide on what should be translated vs. what should be left in English:

  • Comments: Spanish
  • Docstrings: Spanish
  • System prompts (agent instructions): Spanish
  • Identifiers (functions/classes/vars): English
  • User-facing output/data (e.g., example responses, sample values): Spanish
  • @tool function names: English
  • @tool parameter descriptions (Field(description=...)): English
  • @tool docstrings: Spanish
  • HITL control words: bilingual (approve/aprobar, exit/salir)
  • Agent and workflow names: English ("TravelPlannerAgent" should be the same in both versions, not "AgentePlanificadorDeViajes")

Use informal (tuteo) LATAM Spanish, tu not usted, puedes not podes, etc. The content is technical so if a word is best kept in English, then do so.

The /examples/spanish/README.md corresponds to the root README.md and should be kept in sync with it, but translated to Spanish.

Debugging Azure Python SDK HTTP requests

When debugging HTTP interactions between Azure Python SDKs (like azure-ai-evaluation) and Azure services, there are three levels of logging you can enable:

1. Azure SDK logger (request headers and URLs)

Set the Azure SDK loggers to DEBUG level to see request URLs, headers, and status codes:

import logging

logging.basicConfig(level=logging.WARNING)
logging.getLogger("azure").setLevel(logging.DEBUG)
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.DEBUG)

2. Raw HTTP wire data (request/response headers)

Enable http.client debug logging to see the raw HTTP wire protocol, including request and response headers:

import http.client
http.client.HTTPConnection.debuglevel = 1

Note: Response bodies will typically not be visible at this level because Azure SDKs use gzip compression, and http.client logs the raw compressed bytes.

3. Decompressed response bodies

To see actual response bodies, monkey-patch the Azure SDK's HttpLoggingPolicy.on_response method. This works because response.http_response.body() returns the decompressed content:

from azure.core.pipeline.policies import HttpLoggingPolicy

_original_on_response = HttpLoggingPolicy.on_response

def _on_response_with_body(self, request, response):
    _original_on_response(self, request, response)
    try:
        body = response.http_response.body()
        if body:
            _logger = logging.getLogger("azure.core.pipeline.policies.http_logging_policy")
            _logger.debug("Response body: %s", body[:4096].decode("utf-8", errors="replace"))
    except Exception:
        pass

HttpLoggingPolicy.on_response = _on_response_with_body

Manual test plan

After upgrading dependencies or making changes across examples, use this plan to verify everything works. Run each example with uv run python examples/<file>.py.

No extra setup (Azure OpenAI only)

These work with just API_HOST=azure and the standard .env from azd up:

ExamplesNotes
agent_basic.pyInteractive chat loop
agent_tool.py, agent_tools.pyTool calling
agent_session.pySession persistence
agent_with_subagent.py, agent_without_subagent.pySub-agent patterns
agent_supervisor.pySupervisor pattern
agent_middleware.pyMiddleware pipeline
agent_summarization.pySummarization middleware
agent_tool_approval.pyTool approval
workflow_agents.py, workflow_agents_sequential.py, workflow_agents_concurrent.py, workflow_agents_streaming.pyBasic workflows
workflow_conditional.py, workflow_conditional_state.py, workflow_conditional_state_isolated.py, workflow_conditional_structured.pyConditional workflows
workflow_switch_case.pySwitch/case workflow
workflow_converge.py, workflow_fan_out_fan_in_edges.pyConverge / fan-out patterns
workflow_aggregator_ranked.py, workflow_aggregator_structured.py, workflow_aggregator_summary.py, workflow_aggregator_voting.pyAggregator workflows
workflow_multi_selection_edge_group.pyMulti-selection edges
workflow_handoffbuilder.py, workflow_handoffbuilder_rules.pyHandoff builder
workflow_hitl_handoff.py, workflow_hitl_requests.py, workflow_hitl_requests_structured.py, workflow_hitl_tool_approval.pyHITL workflows
workflow_hitl_checkpoint.pyHITL with file-based checkpoints
agent_knowledge_sqlite.pySQLite knowledge provider
agent_history_sqlite.pySQLite history provider (no tools — see agent-framework#3295)
agent_memory_mem0.pyMem0 memory provider

Requires Redis (dev container)

Redis runs automatically in the dev container at redis://redis:6379.

ExamplesNotes
agent_history_redis.pyRedis history provider (no tools — see agent-framework#3295)
agent_memory_redis.pyRedis memory provider

Requires PostgreSQL (dev container)

PostgreSQL runs automatically in the dev container at postgresql://admin:LocalPasswordOnly@db:5432/postgres.

ExamplesNotes
agent_knowledge_pg.pyPG + pgvector knowledge
agent_knowledge_pg_rewrite.pyPG knowledge with query rewrite
agent_knowledge_postgres.pyPG knowledge (alternative)
workflow_hitl_checkpoint_pg.pyHITL with PG-backed checkpoints

Requires Azure AI Search

Needs AZURE_SEARCH_ENDPOINT and AZURE_SEARCH_KNOWLEDGE_BASE_NAME in .env.

ExamplesNotes
agent_knowledge_aisearch.pyAzure AI Search knowledge base (agentic mode)

Requires MCP server

Start the MCP server first: uv run python examples/mcp_server.py

ExamplesNotes
agent_mcp_local.pyLocal MCP server (stdio)
agent_mcp_remote.pyRemote MCP server (SSE)

Requires OTel / Aspire

ExamplesNotes
agent_otel_aspire.pyAspire dashboard (runs in dev container at http://aspire-dashboard:18888)
agent_otel_appinsights.pyNeeds APPLICATIONINSIGHTS_CONNECTION_STRING in .env

Slow-running examples (⏱ 2–10 minutes)

These take significantly longer than other examples:

ExamplesNotes
agent_evaluation.pyRuns agent + evaluators inline. ~2–3 min.
agent_evaluation_generate.pyGenerates eval data JSONL. ~2 min.
agent_evaluation_batch.pyBatch evaluators on JSONL. ~3–5 min. Needs eval_data.jsonl from agent_evaluation_generate.py.
agent_redteam.pyRed team attack simulation. ~5–10 min.
workflow_magenticone.pyMulti-agent MagenticOne orchestration. ~2–5 min.

Spanish examples

Spanish files under examples/spanish/ mirror the English examples exactly (same code, translated strings). After changes, spot-check 3–5 Spanish files to confirm they run correctly.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.