Get Started with Microsoft Agent Framework
Highlights
- Flexible Agent Framework: build, orchestrate, and deploy AI agents and multi-agent systems
- Multi-Agent Orchestration: Group chat, sequential, concurrent, and handoff patterns
- Plugin Ecosystem: Extend with native functions, OpenAPI, Model Context Protocol (MCP), and more
- LLM Support: OpenAI, Foundry, Anthropic, and more
- Runtime Support: In-process and distributed agent execution
- Multimodal: Text, vision, and function calling
- Cross-Platform: .NET and Python implementations
Quick Install
pip install agent-framework-core
# Optional: Add Microsoft Foundry integration
pip install agent-framework-foundry
# Optional: Add OpenAI integration
pip install agent-framework-openai
Supported Platforms:
- Python: 3.11–3.15
- OS: Windows, macOS, Linux
Python 3.10 is no longer supported because it has reached upstream end of life. Package metadata still permits Python 3.10 installation, but CI no longer runs unit or integration tests on it and compatibility is not guaranteed. Use Python 3.11–3.15 for supported environments, subject to integration-specific limits. Raising the installation minimum will be handled separately.
1. Setup API Keys
Depending on the client you want to use, there are various environment variables you can set to configure the chat clients. This can be done in the environment itself, or with a .env file in your project root, some examples of environment variables include:
FOUNDRY_PROJECT_ENDPOINT=...
FOUNDRY_MODEL=...
...
OPENAI_API_KEY=sk-...
OPENAI_CHAT_COMPLETION_MODEL=...
OPENAI_CHAT_MODEL=...
...
AZURE_OPENAI_API_KEY=...
AZURE_OPENAI_ENDPOINT=...
AZURE_OPENAI_MODEL=...
You can also override environment variables by explicitly passing configuration parameters to the chat client constructor:
from agent_framework.openai import OpenAIChatClient
client = OpenAIChatClient(
api_key="",
model="",
)
Telemetry controls
Agent Framework adds its package/version User-Agent to supported client requests. Approved Microsoft Foundry and Azure OpenAI request paths can also carry a documented feature-usage token.
AGENT_FRAMEWORK_FEATURE_MASK_DISABLED=truedisables only the feature-usage token while retaining the package/version User-Agent.AGENT_FRAMEWORK_USER_AGENT_DISABLED=truedisables the entire Agent Framework User-Agent contribution, including the feature token.
OpenTelemetry providers configured through configure_otel_providers() share a
resource containing "microsoft.agent-framework": "True" (a string) by default. This
resource attribute applies to logs, traces, and metrics, including other
instrumentation using those providers. Existing environment and explicit resource
attribute overrides retain their precedence. If you configure providers yourself,
use agent_framework.observability.create_resource() for each provider or add the
attribute to your own shared resource.
See the following getting started samples for more information.
2. Create a Simple Agent
Create agents and invoke them directly:
import asyncio
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
agent = Agent(
client=OpenAIChatClient(),
instructions="""
1) A robot may not injure a human being...
2) A robot must obey orders given it by human beings...
3) A robot must protect its own existence...
Give me the TLDR in exactly 5 words.
"""
)
result = asyncio.run(agent.run("Summarize the Three Laws of Robotics"))
print(result)
# Output: Protect humans, obey, self-preserve, prioritized.
3. Directly Use Chat Clients (No Agent Required)
You can use the chat client classes directly for advanced workflows:
import asyncio
from agent_framework.openai import OpenAIChatClient
from agent_framework import Message, Role
async def main():
client = OpenAIChatClient()
response = await client.get_response([
Message("system", ["You are a helpful assistant."]),
Message("user", ["Write a haiku about Agent Framework."])
])
print(response.messages[0].text)
"""
Output:
Agents work in sync,
Framework threads through each task—
Code sparks collaboration.
"""
asyncio.run(main())
4. Build an Agent with Tools and Functions
Enhance your agent with custom tools and function calling:
import asyncio
from typing import Annotated
from random import randint
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
def get_weather(
location: Annotated[str, "The location to get the weather for."],
) -> str:
"""Get the weather for a given location."""
conditions = ["sunny", "cloudy", "rainy", "stormy"]
return f"The weather in {location} is {conditions[randint(0, 3)]} with a high of {randint(10, 30)}°C."
def get_menu_specials() -> str:
"""Get today's menu specials."""
return """
Special Soup: Clam Chowder
Special Salad: Cobb Salad
Special Drink: Chai Tea
"""
async def main():
agent = Agent(
client=OpenAIChatClient(),
instructions="You are a helpful assistant that can provide weather and restaurant information.",
tools=[get_weather, get_menu_specials]
)
response = await agent.run("What's the weather in Amsterdam and what are today's specials?")
print(response)
# Output:
# The weather in Amsterdam is sunny with a high of 22°C. Today's specials include
# Clam Chowder soup, Cobb Salad, and Chai Tea as the special drink.
asyncio.run(main())
You can explore additional agent samples here.
MCP HTTP client ownership and cookies
Breaking change: HTTP clients created by MCPStreamableHTTPTool no longer persist
response cookies. This applies with or without a header_provider, including repeated
calls within the same MCP session. Connection reuse, timeout and redirect defaults,
and cleanup on close or reset are preserved. Explicit Cookie headers supplied through
static_headers or a header_provider are still supported.
Applications relying on cookie-based authentication, sessions, or load-balancer affinity
must supply an httpx.AsyncClient through http_client=. Supplied clients retain their
configuration and response-cookie handling and must be closed by the caller. Scope
cookie-bearing clients and MCP tool sessions to one authenticated principal; do not
share a user-specific cookie jar across users. Rejecting cookies does not partition
MCP protocol sessions or other server-side state between principals.
5. Multi-Agent Orchestration
Coordinate multiple agents to collaborate on complex tasks using orchestration patterns:
import asyncio
from agent_framework import Agent
from agent_framework.openai import OpenAIChatClient
async def main():
# Create specialized agents
writer = Agent(
client=OpenAIChatClient(),
name="Writer",
instructions="You are a creative content writer. Generate and refine slogans based on feedback."
)
reviewer = Agent(
client=OpenAIChatClient(),
name="Reviewer",
instructions="You are a critical reviewer. Provide detailed feedback on proposed slogans."
)
# Sequential workflow: Writer creates, Reviewer provides feedback
task = "Create a slogan for a new electric SUV that is affordable and fun to drive."
# Step 1: Writer creates initial slogan
initial_result = await writer.run(task)
print(f"Writer: {initial_result}")
# Step 2: Reviewer provides feedback
feedback_request = f"Please review this slogan: {initial_result}"
feedback = await reviewer.run(feedback_request)
print(f"Reviewer: {feedback}")
# Step 3: Writer refines based on feedback
refinement_request = f"Please refine this slogan based on the feedback: {initial_result}\nFeedback: {feedback}"
final_result = await writer.run(refinement_request)
print(f"Final Slogan: {final_result}")
# Example Output:
# Writer: "Charge Forward: Affordable Adventure Awaits!"
# Reviewer: "Good energy, but 'Charge Forward' is overused in EV marketing..."
# Final Slogan: "Power Up Your Adventure: Premium Feel, Smart Price!"
if __name__ == "__main__":
asyncio.run(main())
Note: Sequential, Concurrent, Group Chat, Handoff, and Magentic orchestrations are available. See examples in orchestration samples.
More Examples & Samples
- Getting Started with Agents: Basic agent creation and tool usage
- Chat Client Examples: Direct chat client usage patterns
- Foundry Integration: Foundry integration
- Workflows Samples: Advanced multi-agent patterns
Agent Framework Documentation
Metadata
Release files for agent-framework-core 1.24.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| agent_framework_core-1.24.0.tar.gz | 792.0 kB | Without provenance | Details for agent_framework_core-1.24.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agent_framework_core-1.24.0-py3-none-any.whl | Python 3 | none | any | Details for agent_framework_core-1.24.0-py3-none-any.whl |
Total release size: 1.6 MB
Release files / agent_framework_core-1.24.0.tar.gz
| Download URL | agent_framework_core-1.24.0.tar.gz |
|---|---|
| Size | 792.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
04968b955c2d198ea5d7635e0f062d744dbf971d881bb2fe6023a50687c05b4c
|
|
BLAKE2b-256 checksum How to use checksums |
9ad67b700ed0f1cb26ce540660e70a1eec9479932f752d103054eece4cd24c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Release files / agent_framework_core-1.24.0-py3-none-any.whl
| Download URL | agent_framework_core-1.24.0-py3-none-any.whl |
|---|---|
| Size | 853.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
dd8edd14dabbe6c64d807c2d0dece91a8171d31055443ff5f98cc7f902007bee
|
|
BLAKE2b-256 checksum How to use checksums |
6c3935e085321e228fe45e46e5bf6af9a08a5ddc11d5ee175cbe8a5f7ce146d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
RestSharp/106.13.0.0
|
Security for agent-framework-core 1.24.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.