Microsoft Agent Framework Lab
agent-framework-lab provides experimental modules as part of the Microsoft Agent Framework, focusing on cutting-edge features, benchmarking, reinforcement learning, and research initiatives. It is currently in a beta development stage (1.0.0b251024) and is designed for developers building, learning to build, or exploring AI agents using modern frameworks and tooling.
Common errors
-
ModuleNotFoundError: No module named 'agent_framework.azure'
cause The Azure-specific implementations, especially for `AzureAIProjectAgentProvider`, have been moved or refactored in version 1.0.0 and are no longer directly under `agent_framework.azure`.fixFor Azure AI Foundry, connect directly to a Foundry-hosted agent using `FoundryAgent`. For other Azure-related components, refer to the updated documentation for new import paths and classes in `agent-framework-foundry` or other specific Azure packages. -
TypeError: Message constructor got an unexpected keyword argument 'text'
cause The `text` parameter in the `Message` constructor was deprecated and then removed in later versions (specifically, around the 1.0.0 release).fixUpdate your code to pass the message content as the positional `content` argument, which expects a list of content items (e.g., `Message('user', [TextContent('Your message')])` or simply `Message('user', 'Your message')` if using string for simple text content). -
ImportError: cannot import name 'BaseContextProvider' from 'agent_framework.core'
cause Deprecated aliases like `BaseContextProvider` and `BaseHistoryProvider` were removed from `agent_framework.core` in version 1.0.0.fixRefer to the updated `agent-framework-core` documentation for the correct, non-aliased class names or replacement patterns for context and history providers.
Warnings
- breaking The 1.0.0 release of Microsoft Agent Framework introduced significant architectural changes, particularly around provider-leading client design, the extraction of OpenAI code from core, and standardized naming. Previous beta versions are not directly compatible.
- gotcha `agent-framework-lab` contains experimental modules. Features and APIs within this sub-package are subject to rapid change, may be unstable, and are not guaranteed for long-term support.
- gotcha The Agent Framework does not automatically load environment variables from `.env` files. API keys and other configurations must be explicitly loaded or set in the environment.
- breaking Prior to 1.0.0, there were deprecated kwargs compatibility paths, core dependencies were heavier, and OpenAI provider implementation was bundled. These have been removed or refactored.
Install
-
pip install agent-framework-lab -
pip install agent-framework
Imports
- Agent
from agent_framework.core import Agent
- Message
from agent_framework import Message
- OpenAIChatClient
from agent_framework.openai import OpenAIChatClient
- some_lab_module
from agent_framework.lab import some_lab_module
Quickstart
import os
from agent_framework import Message
from agent_framework.openai import OpenAIChatClient
from agent_framework.core import Agent
# Ensure your OpenAI API key is set as an environment variable
# Or, if using Azure OpenAI, set AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY, etc.
# Agent Framework does not automatically load .env files; use `load_dotenv()` if needed.
OPENAI_API_KEY = os.environ.get('OPENAI_API_KEY', '')
if not OPENAI_API_KEY:
print("Warning: OPENAI_API_KEY environment variable not set. This example may fail.")
async def main():
client = OpenAIChatClient(api_key=OPENAI_API_KEY)
# Create a simple agent
agent = Agent(
name="MyFirstAgent",
instructions="You are a helpful assistant.",
client=client
)
# Send a message to the agent
response = await agent.run(
messages=[Message("user", "Hello, how are you?")]
)
print(f"Agent: {response.content[0].text}")
if __name__ == "__main__":
import asyncio
asyncio.run(main())