You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Using most models besides openai on openrouter does not work with functions that have no arguments.
To Reproduce
This script reproduces the issue, you just need to change the openrouter API key
import asyncio
from pprint import pprint
from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import (
OpenAIChatCompletionClient,
)
import settings
# Define a model client. You can use other model client that implements
# the `ChatCompletionClient` interface.
model_client = OpenAIChatCompletionClient(
model="anthropic/claude-3.5-sonnet",
api_key=settings.OPENROUTER_KEY,
base_url="https://openrouter.ai/api/v1",
model_info={
"vision": True,
"function_calling": True,
"json_output": False,
"family": "claude-3.5-sonnet",
},
)
def get_weather() -> str:
"""Get the weather for a given city."""
return f"The weather is 73 degrees and Sunny."
# Define an AssistantAgent with the model, tool, system message, and reflection enabled.
# The system message instructs the agent via natural language.
agent = AssistantAgent(
name="weather_agent",
model_client=model_client,
tools=[get_weather],
system_message="You are a helpful assistant.",
)
# Run the agent and stream the messages to the console.
def main() -> None:
result = asyncio.run(agent.run(task="What is the weather in New York?"))
pprint(result)
main()
Result:
TaskResult(messages=[TextMessage(source='user', models_usage=None, content='What is the weather in New York?', type='TextMessage'),
ToolCallRequestEvent(source='weather_agent', models_usage=RequestUsage(prompt_tokens=389, completion_tokens=48), content=[FunctionCall(id='tooluse_crDs0nSRTziC4TS0Wg-JGg', arguments='', name='get_weather')], type='ToolCallRequestEvent'),
ToolCallExecutionEvent(source='weather_agent', models_usage=None, content=[FunctionExecutionResult(content='Error: Expecting value: line 1 column 1 (char 0)', call_id='tooluse_crDs0nSRTziC4TS0Wg-JGg', is_error=True)], type='ToolCallExecutionEvent'),
ToolCallSummaryMessage(source='weather_agent', models_usage=None, content='Error: Expecting value: line 1 column 1 (char 0)', type='ToolCallSummaryMessage')],
stop_reason=None)
Expected behavior
The result of the tool call should be added to the agent messages
Which packages was the bug in?
Python AgentChat (autogen-agentchat>=0.4.0)
AutoGen library version.
Python 0.4.7
Other library version.
No response
Model used
anthropic/claude-3.5-sonnet
Model provider
OpenRouter
Other model provider
No response
Python version
3.10
.NET version
None
Operating system
None
The text was updated successfully, but these errors were encountered:
philippHorn
changed the title
Openrouter: Crash when using functions without arguments
Openrouter: Error inside tool result when using functions without arguments
Feb 22, 2025
## Why are these changes needed?
See issue for a bug description.
The problem was that a lot of openrouter models return `""` as
`tool_call.arguments`, which caused `json.loads` to fail
## Related issue number
#5666
---------
Co-authored-by: Eric Zhu <[email protected]>
What happened?
Describe the bug
Using most models besides openai on openrouter does not work with functions that have no arguments.
To Reproduce
This script reproduces the issue, you just need to change the openrouter API key
Result:
Expected behavior
The result of the tool call should be added to the agent messages
Which packages was the bug in?
Python AgentChat (autogen-agentchat>=0.4.0)
AutoGen library version.
Python 0.4.7
Other library version.
No response
Model used
anthropic/claude-3.5-sonnet
Model provider
OpenRouter
Other model provider
No response
Python version
3.10
.NET version
None
Operating system
None
The text was updated successfully, but these errors were encountered: