-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Python: FoundryAgent returns 400 if both agent_reference and tools are present in request body #5087
Copy link
Copy link
Open
Description
Description
FoundryAgent fails with 400 when both agent_reference (agent specified) and tools are present in the request body.
RawFoundryAgentChatClient._prepare_options() validates that only FunctionTool objects are passed, but does not strip them from the serialized request. super()._prepare_options() includes them in the request body, and Foundry rejects tools when agent_reference is present.
Expected Behavior
_prepare_options() should strip tools from the outgoing request when agent_reference is present, while keeping them available in memory for FunctionInvocationLayer to execute locally.
Code Sample
from agent_framework import tool
from agent_framework.foundry import FoundryAgent
from azure.identity import AzureCliCredential
@tool(approval_mode="never_require")
async def get_weather(location: str) -> str:
return f"Sunny in {location}"
agent = FoundryAgent(
project_endpoint="https://...",
agent_name="MyAgent", # has get_weather defined server-side
agent_version="1",
credential=AzureCliCredential(),
tools=[get_weather], # local implementation
)
# This fails:
async for update in agent.run("What's the weather?", session=agent.create_session()):
passError Messages / Stack Traces
agent_framework.exceptions.ChatClientException: service failed to complete the prompt:
Error code: 400 - {'error': {'code': 'invalid_payload',
'message': 'Not allowed when agent is specified.', 'param': 'tools'}}
Package Versions
agent-framework: 1.0.0, agent-framework-foundry: 1.0.0
Python Version
3.10
Additional Context
OS: Windows
Reactions are currently unavailable