Find answers from the community

Updated 3 months ago

How can I force OpenAiAgent to always use query engine tool

How can I force OpenAiAgent to always use query engine tool
k
L
t
7 comments
Please stand by @tugay as I search the knowledge base. We are experiencing especially high traffic right now and might take longer than usual. :wave:
----------------------
To force the OpenAIAgent to always use a query engine tool, you need to initialize the agent with the query engine tools. Here's how you can do it:

First, import the necessary modules and classes:

Plain Text
from llama_index.agent import OpenAIAgent
from llama_index.tools import QueryEngineTool, ToolMetadata


Next, define your query engine tools. Here's an example of how to do it:

Plain Text
query_engine_tools = [
    QueryEngineTool(
        query_engine=lyft_engine,
        metadata=ToolMetadata(
            name="lyft_10k",
            description="Provides information about Lyft financials for year 2021. "
            "Use a detailed plain text question as input to the tool.",
        ),
    ),
    QueryEngineTool(
        query_engine=uber_engine,
        metadata=ToolMetadata(
            name="uber_10k",
            description="Provides information about Uber financials for year 2021. "
            "Use a detailed plain text question as input to the tool.",
        ),
    ),
]


Finally, initialize the OpenAIAgent with the query engine tools:

Plain Text
agent = OpenAIAgent.from_tools(query_engine_tools, verbose=True)


Now, the OpenAIAgent will always use the query engine tools you've defined.

For more details, you can refer to the documentation ().
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
There's an API option to force tool usage, but last time I checked openai wasn't properly supporting it :PSadge:

Hopefully soon!
thanks @Logan M , I am trying to use correct prompt to make it use only the tool I have given it, but sometimes it doesn't use it and the answer is based solely on openai knowledge
Yea, that's a pretty common "feature" of agents :PSadge: Very tricky
Actually I have an upcoming new chat engine that may help! Will keep you updated πŸ™‚
Add a reply
Sign up and join the conversation on Discord