Microsoft Agent Framework Integration for Claude
The `agent-framework-claude` library provides an integration for using Anthropic's Claude models within Microsoft's Agent Framework. Currently in beta version `1.0.0b260409`, it is part of an actively developed monorepo (`microsoft/agentframework`) with frequent pre-releases, indicating potential for rapid changes and feature updates.
Common errors
-
ModuleNotFoundError: No module named 'agent_framework_claude'
cause Incorrect import path. The package is part of the broader `agentframework` and its module is nested.fixUse `from agentframework.integrations.claude import ClaudeAgent`. -
anthropic.types.errors.AuthenticationError: invalid x-api-key: ...
cause The Anthropic API key is missing or invalid.fixSet the `ANTHROPIC_API_KEY` environment variable or pass a valid key directly to `ClaudeAgent(anthropic_api_key='...')`. Double-check the key for typos and ensure it has the correct permissions. -
TypeError: object NoneType can't be used in 'await' expression
cause Often occurs when an asynchronous method (like `agent.invoke()`) returns `None` due to an error during initialization, and `await` is called on it.fixCheck `ClaudeAgent` initialization parameters, especially `anthropic_api_key` and `model`. Ensure the API key is valid and the model name exists and is accessible.
Warnings
- breaking As a beta package (`1.0.0b...`), `agent-framework-claude` is subject to frequent breaking changes without major version bumps. API signatures, class names, or core functionalities may change between minor pre-release versions.
- gotcha The `ClaudeAgent` constructor requires an `anthropic_api_key`. If this is not provided, or if the `ANTHROPIC_API_KEY` environment variable is not set, API calls will fail with authentication errors.
- gotcha The library is built on `asyncio`. All interactions with the agent (e.g., `agent.invoke()`) are asynchronous and must be `await`ed within an `async` function. Calling them directly will result in a `coroutine object` being returned, not the actual result.
Install
-
pip install agent-framework-claude
Imports
- ClaudeAgent
from agent_framework_claude import ClaudeAgent
from agentframework.integrations.claude import ClaudeAgent
Quickstart
import os
import asyncio
from agentframework.integrations.claude import ClaudeAgent
async def main():
# Ensure ANTHROPIC_API_KEY is set in your environment
anthropic_api_key = os.environ.get('ANTHROPIC_API_KEY', '')
if not anthropic_api_key:
print("Warning: ANTHROPIC_API_KEY environment variable not set. Agent may not function.")
agent = ClaudeAgent(
name="Claude",
description="An agent that uses Claude for general purpose reasoning.",
anthropic_api_key=anthropic_api_key,
model="claude-3-opus-20240229" # Specify your desired Claude model
)
# Example interaction
response = await agent.invoke("What is the capital of France?")
print(f"Claude's response: {response}")
if __name__ == '__main__':
asyncio.run(main())