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]: OpenAI agent with query engine tools crashes while calling the tool #9411

Closed
vaibhavp4 opened this issue Dec 9, 2023 · 3 comments
Closed
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized

Comments

@vaibhavp4
Copy link

Bug Description

I setup an openai agent with query engine tools

The agent was able to start and enter the chat repl

But it fails as soon as you submit a query
image

(The editor also warns that agent code doesn't see query engine tools as a subclass of BaseTools)

Version

0.9.13

Steps to Reproduce

Relevant Logs/Tracbacks

raise self._make_status_error_from_response(err.response) from None
openai.BadRequestError: Error code: 400 - {'error': {'message': "'Tesla April 2022 Valuation' does not match '^[a-zA-Z0-9_-]{1,64}$' - 'tools.0.function.name'", 'type': 'invalid_request_error', 'param': None, 'code': None}}
@vaibhavp4 vaibhavp4 added bug Something isn't working triage Issue needs to be triaged/prioritized labels Dec 9, 2023
Copy link

dosubot bot commented Dec 9, 2023

🤖

Hello @vaibhavp4! 👋 I'm Dosu, a friendly bot here to lend a hand with bugs, answer your questions, and guide you as a contributor while we wait for a human maintainer. Just a reminder, I'm not a human, but I'll do my best to assist. 🤖🛠️ Let's get coding! 🚀

Based on the error message you provided, it seems like the issue is related to the name of the function you're trying to call with the OpenAI agent. The error message indicates that the name of the function, 'Tesla April 2022 Valuation', does not match the expected pattern '^[a-zA-Z0-9_-]{1,64}$'. This pattern requires the function name to be between 1 and 64 characters long and only contain alphanumeric characters, underscores, and hyphens.

As for the warning that the agent code doesn't see query engine tools as a subclass of BaseTools, this could be due to an incorrect import statement or a missing inheritance declaration in the class definition of the query engine tools.

Regarding the crash when submitting a query, there are a couple of potential reasons based on the context provided:

  1. The index is not initialized before the read function is called. In the read function, it checks if the index is initialized (if not self._index:). If it's not, it returns an error message. This could cause a crash if the error is not properly handled in the code that calls this function. To fix this, ensure that the load function is called before the read function.

  2. The query_engine.query(query) might be causing the crash. This could be due to an issue with the query engine or the query itself. If the query engine is not properly initialized or if the query is not valid, this could cause a crash. To fix this, ensure that the query engine is properly initialized and that the query is valid.

Here is the relevant code:

def read(self, query: str) -> Any:
    # Query the index for the result
    if not self._index:
        return (
            "Error: No content has been loaded into the index. "
            f"You must call {self._metadata.name} first"
        )
    query_engine = self._index.as_query_engine()
    response = query_engine.query(query)
    return str(response)

(Source: llama_index/tools/tool_spec/load_and_search/base.py)

There was a similar issue reported in the LlamaIndex repository: [Bug]: Validation Error for tools in OpenAI Assistant Agent example. This issue was resolved by a pull request: one line fix for wrapping of custom function tools to create OpenAI assistant. The changes made in this pull request might help resolve your issue.

Please try to update your function name to match the required pattern and ensure that the query engine tools are correctly subclassed from BaseTools. If the issue persists, please provide more details about your setup and the steps you're taking so that I can better assist you.

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

@logan-markewich
Copy link
Collaborator

As you can see from the error, the name you gave your tool is invalid

It can only be alpha-numeric with dashes or underscores, but your tool name has spaces

@vaibhavp4
Copy link
Author

Thanks, missed it because the same names were working fine with the sub question query engine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage Issue needs to be triaged/prioritized
Projects
None yet
Development

No branches or pull requests

2 participants