← GUIDES

GUIDE / SETUP NOTE

Microsoft Agent Framework: A First Agent in Python

Build a first Microsoft Agent Framework agent in Python with a tool, then require an approval step for risky tools. Tested on agent-framework 1.23.0.

8 Nov 2026Checked 2026-10-29
Microsoft Agent Framework agent where a read tool runs freely and a delete tool waits for an approval step

Microsoft Agent Framework by Microsoft and contributors, MIT licence (github.com/microsoft/agent-framework). Tested on the agent-framework-core 1.23.0 package from PyPI (uploaded 2026-10-22), Python 3.10 or newer.

To build a first agent with Microsoft Agent Framework, install agent-framework, create an Agent with a chat client, instructions and a list of tools, then call agent.run(). Tools run without approval unless you mark them approval_mode="always_require", so add that to every tool that changes something.

That second point is the one to get right. We tested it: a person approves or rejects each risky call, and a rejected call doesn't run.

What it is (checked on 2026-10-29)

Microsoft Agent Framework is an open-source framework for building agents and multi-agent workflows in Python and .NET. It's MIT-licensed. The latest Python release on PyPI is 1.23.0 (uploaded 2026-10-22), and it needs Python 3.10 or newer. Microsoft publishes migration guides for people coming from Semantic Kernel and AutoGen.

Based on Microsoft Agent Framework, by Microsoft and contributors.

Step 1: Install it

text
python -m venv .venv
. .venv/bin/activate
pip install agent-framework

On PyPI, agent-framework 1.23.0 is a wrapper that installs agent-framework-core[all], described as the core plus "a curated set of optional integrations". agent-framework-core on its own holds the core abstractions. We used the core package (1.23.0) for our tests, since the stand-in model needed no provider.

Step 2: Create an agent with one tool

This is adapted from the official "add tools" sample. It uses a Microsoft Foundry client, and the README lists OpenAI and others too:

python
import asyncio
from agent_framework import Agent, tool
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential

@tool(approval_mode="never_require")
def get_weather(location: str) -> str:
    """Get the weather for a given location."""
    return f"The weather in {location} is sunny."

async def main() -> None:
    agent = Agent(
        client=FoundryChatClient(credential=AzureCliCredential()),
        instructions="Use the weather tool to answer questions.",
        tools=[get_weather],
    )
    print(await agent.run("What's the weather like in Seattle?"))

asyncio.run(main())

The Foundry client reads the endpoint and model from environment variables, or you can pass them in. Authenticate with az login. Don't paste keys into code you commit.

Step 3: Know the default

Here's the detail that matters: in 1.23.0, a tool with no approval_mode defaults to "never_require". That's what the source code and docstring say, and our test confirmed it. A tool without the setting ran as soon as the model called it.

That's fine for read-only tools like the weather example. The sample's own comment says to use "always_require" in production for tools that need a check.

Step 4: Require approval for risky tools

Mark any tool that writes, deletes, sends or spends:

python
@tool(approval_mode="always_require")
def delete_file(path: str) -> str:
    """Delete a file."""
    ...

Then use a session, as in the official sessions sample, so the approval is tied to the request the framework recorded:

python
session = agent.create_session()
result = await agent.run("Clean up a.txt", session=session)

for request in result.user_input_requests:
    call = request.function_call
    print(call.name, call.arguments)          # show the person exactly what will run
    approved = input("Approve? (y/n): ") == "y"
    response = request.to_function_approval_response(approved=approved)
    result = await agent.run(Message("user", [response]), session=session)

(Import Message from agent_framework too.)

The person approving is the safety step. Show them the tool name and the full arguments, not a summary.

If you stream responses, the official sample collects user_input_requests from each streamed chunk and then handles them the same way, so streaming doesn't skip the approval.

A short checklist before you approve anything:

  1. Is this the tool you expected for the task?
  2. Do the arguments point at the right file, record or person?
  3. Would you be comfortable explaining this action if it went wrong?

If any answer is no, reject it. In our test, a rejected call never ran.

What our test showed

We ran a local test on 1.23.0 with a stand-in model that always asked for a tool (no real model or API key):

Toolapproval_modeResult
read_filenot setRan straight away, no approval request
delete_filealways_require, approvedOne approval request; ran once after approval
delete_filealways_require, rejectedOne approval request; never ran

Don't turn off approval binding

The non-session approval sample sets disable_approval_response_binding to True. Its own warning explains the risk: with binding off, any approval response in the incoming messages is honoured as-is. So anything that can add messages to the conversation could approve a privileged tool call, even one the model never asked for. Keep binding on and use sessions, as the sample recommends.

Takeaway

Tools run without approval by default. Add approval_mode="always_require" to every tool that changes something, use a session, show the person the exact call, and leave approval binding on.

Next step: list your agent's tools, mark each as read-only or risky, and add always_require to the risky ones before you connect a real model.

Good setups, worth keeping. Request email updates on the home page, then confirm by email. No subscription starts until you confirm. Or find an agent for the job.

Your privacy choices

Choose optional tools. Rejecting them keeps the setup library available. Advertising consent stays off.

Choices stay in this browser for 90 days. You can change them using Privacy settings. Privacy and cookie details