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

[Bug] Agent used in team crashes if name contains illegal character for OpenAIChat model #2082

Closed
digithree opened this issue Feb 11, 2025 · 2 comments · Fixed by #2088
Closed
Labels
bug Something isn't working

Comments

@digithree
Copy link

Description

If an Agent is used as part of a team in another Agent, it cannot have an illegal character in the name property when using OpenAIChat as model, as this causes a crash. An 'illegal' character is defined as one that does not match this regex: ^[a-zA-Z0-9_-]+$, e.g. &

Note that the issue does not reproduce when an Agent has an illegal character in the name and is used directly, i.e. print_response is called on it. The issue only reproduces when that Agent is on a team of another Agent. (see notes at end of ticket)

Steps to Reproduce

  1. Create an Agent with at least one character in the name property that does not match this regex: ^[a-zA-Z0-9_-]+$, e.g. use a &
  2. Add this Agent in the team list of a second Agent
  3. Call print_response(...) on the second Agent

Agent Configuration (if applicable)

Here is a complete example to reproduce the issue, based closely on the simplest example from your docs:

from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent_news_reporter = Agent(
    name="News Reporter &",
    model=OpenAIChat(id="gpt-4"),
    description="You are an enthusiastic news reporter with a flair for storytelling!",
    markdown=True
)

agent_team = Agent(
    name="News Team",
    team=[agent_news_reporter],
    model=OpenAIChat(id="gpt-4"),
    markdown=True
)

agent_team.print_response("Tell me about a breaking news story from New York.", stream=True)

Expected Behavior

The Agent runs as normal, running the Agent team and generating output successfully.

Actual Behavior

The Agent crashes with fatal error from OpenAI API.

Screenshots or Logs (if applicable)

Console output with crash stack trace:

▰▰▰▰▱▱▱ Thinking...
┏━ Message ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃                                                                                                                                                                                                          ┃
┃ Tell me about a breaking news story from New York.                                                                                                                                                       ┃
┃                                                                                                                                                                                                          ┃
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
Traceback (most recent call last):
  File "error_agent_name.py", line 18, in <module>
    agent_team.print_response("Tell me about a breaking news story from New York.", stream=True)
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/agno/agent/agent.py", line 3285, in print_response
    for resp in self.run(
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/agno/agent/agent.py", line 537, in _run
    for model_response_chunk in self.model.response_stream(messages=run_messages.messages):
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/agno/models/openai/chat.py", line 700, in response_stream
    for response in self.invoke_stream(messages=messages):
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/agno/models/openai/chat.py", line 340, in invoke_stream
    yield from self.get_client().chat.completions.create(
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/openai/_utils/_utils.py", line 279, in wrapper
    return func(*args, **kwargs)
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/openai/resources/chat/completions.py", line 863, in create
    return self._post(
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/openai/_base_client.py", line 1283, in post
    return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/openai/_base_client.py", line 960, in request
    return self._request(
  File "~/.pyenv/versions/3.9.6/lib/python3.9/site-packages/openai/_base_client.py", line 1064, in _request
    raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "Invalid 'tools[0].function.name': string does not match pattern. Expected a string that matches the pattern '^[a-zA-Z0-9_-]+$'.", 'type': 'invalid_request_error', 'param': 'tools[0].function.name', 'code': 'invalid_value'}}

Note that stack trace file paths modified to protect privacy, otherwise as outputted by system.

Environment

  • OS: macOS 14.6.1 (23G93)
  • Browser
  • Agno Version: 1.0.8
  • External Dependency Versions: openai 1.61.1
  • Additional Environment Details: Python 3.9.6, using pyenv

Possible Solutions (optional)

I would guess that you are filtering out 'illegal' characters that are disallowed by the OpenAI API, but this is not happening when there is an Agent within an Agent.

Additional Context

It may be somewhat reasonable to reject this issue since the regex is right there in the error message. However I would encourage a fix for two reasons:

  1. It is not at all clear that it is the Agent.name that is causing the issue, in fact the error is misleading in Invalid 'tools[0].function.name': string does not match pattern. .... I had originally thought it originated with tool use in the actual project I'm working on, and it took a good amount of bisecting to find it
  2. Perhaps most importantly, the issue does not reproduce for an Agent not on a team, which means either you are dealing with this case for an Agent used directly, or it is not picked by the OpenAI API due to the differing structuring of the calls, if that happens (I don't quite know how you're doing this and haven't looked too far under the hood)

For completeness, here is a complete example that has the illegal character but does not reproduce, as I said above in point 2:

from agno.agent import Agent
from agno.models.openai import OpenAIChat

agent_news_reporter = Agent(
    name="News Reporter &",
    model=OpenAIChat(id="gpt-4"),
    description="You are an enthusiastic news reporter with a flair for storytelling!",
    markdown=True
)

agent_news_reporter.print_response("Tell me about a breaking news story from New York.", stream=True)

Thanks for your work, I hope this helps.

@digithree digithree added the bug Something isn't working label Feb 11, 2025
@dirkbrnd
Copy link
Contributor

I'm releasing a fix today. Thanks for raising!

@dirkbrnd
Copy link
Contributor

Fixed in release 1.1.0

MrunmayS pushed a commit to MrunmayS/phidata that referenced this issue Feb 12, 2025
## Description

If you had a team member with a name like "News Reporter &", it would
break.

Fixes agno-agi#2082
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants