Anthropic integration for Microsoft Agent Framework
The `agent-framework-anthropic` library provides seamless integration of Anthropic Claude models with the Microsoft Agent Framework. It enables developers to leverage Claude's advanced reasoning, context handling, and thoughtful responses within their AI agent applications. As part of the broader Microsoft Agent Framework ecosystem, it's under active development, with frequent updates given its current beta status.
Warnings
- breaking The `agent-framework-anthropic` package is currently in a pre-release (beta) state. Breaking changes may occur frequently, especially as the broader Microsoft Agent Framework evolves towards stable releases.
- gotcha The core `agent-framework` package often requires the `--pre` flag during `pip install` to get the latest compatible pre-release versions, as it is also under rapid development. Forgetting this can lead to version conflicts or outdated components.
- gotcha API keys (e.g., `ANTHROPIC_API_KEY`) should never be hardcoded or committed to source control. They must be managed securely, preferably through environment variables or a dedicated secret management service.
- breaking A critical vulnerability has been identified in Anthropic's Model Context Protocol (MCP), which could allow arbitrary command execution on servers running MCP. Since Microsoft Agent Framework integrates with MCP, this is a significant security concern.
- gotcha Long-running AI agents built with Claude models can face challenges with memory and context windows, potentially leading to agents 'forgetting' instructions or previous conversational turns over extended interactions.
- gotcha Integrating deeply with Anthropic's infrastructure or the Microsoft Agent Framework may lead to increased vendor lock-in, making it harder to switch underlying LLM providers or agent frameworks in the future.
- gotcha Costs for Anthropic models vary significantly by model (e.g., Claude Haiku vs. Opus) and token usage (input/output). Inefficient prompting or long contexts can lead to unexpectedly high costs.
Install
-
pip install agent-framework --pre -
pip install agent-framework-anthropic
Imports
- AnthropicClient
from agent_framework.anthropic import AnthropicClient
Quickstart
import asyncio
import os
from agent_framework.anthropic import AnthropicClient
async def main():
# Ensure ANTHROPIC_API_KEY is set in your environment variables.
# For a quick test, you can uncomment and set it directly, but avoid in production.
# os.environ['ANTHROPIC_API_KEY'] = 'your_anthropic_api_key_here'
if not os.environ.get('ANTHROPIC_API_KEY'):
print("Error: ANTHROPIC_API_KEY environment variable is not set.")
print("Please set it before running the quickstart.")
return
client = AnthropicClient()
# Create an agent using the Anthropic client
agent = client.as_agent(
name="HelpfulAssistant",
instructions="You are a helpful assistant that answers questions accurately.",
)
# Run the agent with a prompt
response = await agent.run("What is the capital of France?")
print(f"Assistant: {response}")
if __name__ == "__main__":
asyncio.run(main())