Description
When using allowed_tools with function calling, mode should be allowed to be set to either auto or required, as is the case in the core package:
|
raise ContentError("tool_choice 'allowed_tools' is only valid when mode is 'auto' or 'required'") |
However, the OpenAI client only supports allowed_tools with mode: auto, and drops the allowed tools if mode: required is set.
Code Sample
In this example, you would expect the function subtract_numbers to be called, but you get add_numbers {"number1":3,"number2":5}.
import asyncio
from agent_framework import Agent, FunctionTool
from agent_framework.foundry import FoundryChatClient
from azure.identity import AzureCliCredential
from pydantic import BaseModel
class NumberInput(BaseModel):
number1: int
number2: int
async def main() -> None:
client = FoundryChatClient(
credential=AzureCliCredential(),
)
agent = Agent(
client=client,
name="CalculatorAgent",
instructions="You are a helpful calculator agent. Use the tools to answer questions.",
tools=[
FunctionTool(
name="add_numbers",
description="Add two numbers together.",
input_model=NumberInput,
),
FunctionTool(
name="subtract_numbers",
description="Subtract the second number from the first number.",
input_model=NumberInput,
),
],
)
outputs = await agent.run(
"Add 3 and 5.",
options={
"tool_choice": {
"mode": "required",
"allowed_tools": ["subtract_numbers"],
}
},
)
print(outputs.messages[0].contents[0].name, outputs.messages[0].contents[0].arguments) # add_numbers {"number1":3,"number2":5}
if __name__ == "__main__":
asyncio.run(main())
Error Messages / Stack Traces
Package Versions
agent-framework-core: 1.10.0, agent-framework-openai: 1.10.0
Python Version
3.13.13
Additional Context
No response
Description
When using
allowed_toolswith function calling,modeshould be allowed to be set to eitherautoorrequired, as is the case in the core package:agent-framework/python/packages/core/agent_framework/_types.py
Line 3739 in fbaa346
However, the OpenAI client only supports
allowed_toolswithmode: auto, and drops the allowed tools ifmode: requiredis set.Code Sample
In this example, you would expect the function
subtract_numbersto be called, but you getadd_numbers {"number1":3,"number2":5}.Error Messages / Stack Traces
Package Versions
agent-framework-core: 1.10.0, agent-framework-openai: 1.10.0
Python Version
3.13.13
Additional Context
No response