-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed as not planned
Closed as not planned
Copy link
Labels
feature:chat-completionsfeature:lite-llmquestionQuestion about using the SDKQuestion about using the SDKstale
Description
Hi,
I'm facing issues when making my agent perform tool calls when using structured outputs.
Bug description
When we use output_type for structured outputs, the agent doesn't perform tool calling; even if we've asked it to explicitly call and passed the tools.
Here during the first run I was using output_type=WeatherOutput; in the second I commented that line out.
Debug information
- Agents SDK version:
0.3.1 - Python version:
3.10
When using output_type=WeatherOutput
VS when not using output_type=WeatherOutput
Repro steps
from agents import Agent, function_tool, Runner
from agents.extensions.models.litellm_model import LitellmModel
from pydantic import BaseModel, Field
import os
import asyncio
from dotenv import load_dotenv
load_dotenv()
class WeatherOutput(BaseModel):
is_good_weather: bool = Field(..., description='Is the weather good for travel or outdoor activitied?')
details: str = Field(..., description='Give the detailed weather report.')
@function_tool
def get_weather(city: str) -> str:
"""
Use this tool to get the weather for a city
"""
return f'Current weather in {city} is jublious like a rainbow.'
async def weather_friend(prompt: str):
model = LitellmModel(
model=os.getenv("CHAT_MODEL_NAME"), # doesn't matter which LLM but I'm using nvidia_nim/moonshotai/kimi-k2-instruct
api_key=os.getenv("PROVIDER_API_KEY")
)
agent = Agent(
name="Weather Agent",
instructions=(
"You are a helpful weather assistant. "
"Always call the available tools to gather weather data. "
"Do not fabricate answers. "
"Only use the structured output (WeatherOutput) after tool results are retrieved."
),
model=model,
tools=[get_weather], ## <--- this tool won't be called
output_type=WeatherOutput ## <--- however if we remove this line, the above tool will be called
)
result = await Runner.run(agent, prompt)
return result.final_output
async def main():
prompt = 'What is the weather in London?'
weather = await weather_friend(prompt)
print(weather)
if __name__ == '__main__':
asyncio.run(main())Expected behavior
The expected behavior is that, the agent should autonomously call the tool (here get_weather tool) and then use the output of this tool to finally give a structured output.
Metadata
Metadata
Assignees
Labels
feature:chat-completionsfeature:lite-llmquestionQuestion about using the SDKQuestion about using the SDKstale