-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closed
Copy link
Labels
Description
Description
I am trying to integrate my MAF Anthropic Agent with AG-UI but I am getting following error TypeError: AsyncMessages.create() got an unexpected keyword argument 'store'. Looks like it passes store argument by default while Anthropic does not expect one. Sharing agent code for reference.
Following article quickstart for enabling CopilotKit UI with MAF Agent.
Can you please confirm on below?
- Does AG-UI work with Anthropic Foundry Agents
- If yes, what is the right way of setting Anthropic Foundry Client and integrating with CopilotKIT
Code Sample
from __future__ import annotations
import os
from agent_framework import ChatAgent
from agent_framework_ag_ui import AgentFrameworkAgent
from anthropic import AsyncAnthropicFoundry
import uvicorn
from agent_framework._clients import ChatClientProtocol
from agent_framework.anthropic import AnthropicClient
from agent_framework.ag_ui import add_agent_framework_fastapi_endpoint
from dotenv import load_dotenv
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.routes import health
load_dotenv()
def _build_chat_client() -> ChatClientProtocol:
try:
if bool(os.getenv("ANTHROPIC_FOUNDRY_API_KEY")):
return AnthropicClient(
anthropic_client=AsyncAnthropicFoundry(
api_key=os.getenv("ANTHROPIC_FOUNDRY_API_KEY"),
resource=os.getenv("ANTHROPIC_FOUNDRY_RESOURCE"),
),
model_id=os.getenv("ANTHROPIC_CHAT_MODEL_ID", "claude-sonnet-4-5"),
)
raise ValueError("ANTHROPIC_FOUNDRY_API_KEY environment variable is required")
except Exception as exc: # pragma: no cover
raise RuntimeError(
"Unable to initialize the chat client. Double-check your API credentials as documented in README.md."
) from exc
client = _build_chat_client()
base_agent = ChatAgent(
name="AIAssistant",
instructions="You are a helpful assistant",
chat_client=client,
)
my_agent = AgentFrameworkAgent(
agent=base_agent,
name="AIAssistant",
description="An AI Assistant",
require_confirmation=False, # Allow immediate state updates with follow-up messages
)
app = FastAPI(title="CopilotKit + Microsoft Agent Framework (Python)")
app.include_router(health.router)
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
add_agent_framework_fastapi_endpoint(
app=app,
agent=my_agent,
path="/",
)
if __name__ == "__main__":
host = os.getenv("AGENT_HOST", "0.0.0.0")
port = int(os.getenv("AGENT_PORT", "8000"))
uvicorn.run("app.main:app", host=host, port=port, reload=True)Error Messages / Stack Traces
Traceback (most recent call last):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/uvicorn/protocols/http/h11_impl.py", line 410, in run_asgi
result = await app( # type: ignore[func-returns-value]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/uvicorn/middleware/proxy_headers.py", line 60, in __call__
return await self.app(scope, receive, send)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/fastapi/applications.py", line 1135, in __call__
await super().__call__(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/applications.py", line 107, in __call__
await self.middleware_stack(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 186, in __call__
raise exc
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/middleware/errors.py", line 164, in __call__
await self.app(scope, receive, _send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/middleware/cors.py", line 85, in __call__
await self.app(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/middleware/exceptions.py", line 63, in __call__
await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/routing.py", line 716, in __call__
await self.middleware_stack(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/routing.py", line 736, in app
await route.handle(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/routing.py", line 290, in handle
await self.app(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 115, in app
await wrap_app_handling_exceptions(app, request)(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
raise exc
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/_exception_handler.py", line 42, in wrapped_app
await app(scope, receive, sender)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/fastapi/routing.py", line 102, in app
await response(scope, receive, send)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/responses.py", line 269, in __call__
with collapse_excgroups():
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/contextlib.py", line 158, in __exit__
self.gen.throw(value)
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/_utils.py", line 85, in collapse_excgroups
raise exc
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/responses.py", line 273, in wrap
await func()
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/starlette/responses.py", line 253, in stream_response
async for chunk in self.body_iterator:
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework_ag_ui/_endpoint.py", line 83, in event_generator
async for event in wrapped_agent.run_agent(input_data):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework_ag_ui/_agent.py", line 182, in run_agent
async for event in orchestrator.run(context):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework_ag_ui/_orchestrators.py", line 633, in run
async for update in context.agent.run_stream(messages_to_run, **run_kwargs):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework/observability.py", line 1411, in trace_run_streaming
async for streaming_agent_response in run_streaming_func(self, messages=messages, thread=thread, **kwargs):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework/_agents.py", line 982, in run_stream
async for update in self.chat_client.get_streaming_response(
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework/_tools.py", line 2120, in streaming_function_invocation_wrapper
async for update in func(self, messages=prepped_messages, options=options, **filtered_kwargs):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework/observability.py", line 1163, in trace_get_streaming_response
async for update in func(self, messages=messages, options=options, **kwargs):
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework/_middleware.py", line 1432, in _stream_generator
async for update in original_get_streaming_response(
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework/_clients.py", line 362, in get_streaming_response
async for update in self._inner_get_streaming_response(
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/agent_framework_anthropic/_chat_client.py", line 369, in _inner_get_streaming_response
async for chunk in await self.anthropic_client.beta.messages.create(**run_options, stream=True):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspaces/ISE-MLOPS-AGENT-PROJECT/.venv/lib/python3.12/site-packages/anthropic/_utils/_utils.py", line 282, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
TypeError: AsyncMessages.create() got an unexpected keyword argument 'store'Package Versions
agent-framework-ag-ui==1.0.0b260116, agent-framework-anthropic==1.0.0b260116, agent-framework-core==1.0.0b260116
Python Version
No response
Additional Context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Done