Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Openrouter: Error inside tool result when using functions without arguments #5666

Open
philippHorn opened this issue Feb 22, 2025 · 0 comments
Assignees
Milestone

Comments

@philippHorn
Copy link
Contributor

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

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

@philippHorn philippHorn changed the title Openrouter: Crash when using functions without arguments Openrouter: Error inside tool result when using functions without arguments Feb 22, 2025
@ekzhu ekzhu added this to the 0.4.8-python milestone Feb 23, 2025
ekzhu added a commit that referenced this issue Feb 24, 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants