Find answers from the community

Updated 3 months ago

how do i debug the ReAct agent? it's not creating the correct action

how do i debug the ReAct agent? it's not creating the correct action
k
t
7 comments
Please stand by @tomi as I search the knowledge base. I normally take about 20 seconds or so. :wave:
----------------------
To debug the ReAct agent, you can set the verbose parameter to True when creating the agent. This will allow you to see what's going on during the agent's operation. Here's an example of how to do this:

Plain Text
from llama_index.core.agent import ReActAgent
from llama_index.llms.openai import OpenAI

llm = OpenAI(model="gpt-3.5-turbo-0613")
agent = ReActAgent.from_tools([multiply_tool, add_tool], llm=llm, verbose=True)


In this example, multiply_tool and add_tool are the tools that the agent will use. Replace these with the tools you're using in your project.

If the agent is not creating the correct action, it could be due to the reasoning loop entering an incorrect state. The ReAct agent combines chain-of-thought reasoning with action planning, and sometimes it can enter the incorrect reasoning loop to answer the question. You can run some example queries to see if this is the case.

If you're still having trouble, you might want to check the prompts used by the agent. You can do this with the get_prompts method:

Plain Text
prompt_dict = agent.get_prompts()
for k, v in prompt_dict.items():
    print(f"Prompt: {k}\n\nValue: {v.template}")


This will print out all the prompts used by the agent, which might help you identify any issues.
Sources:
  • LlamaIndex Docs: Initialize the agent ()
  • GitHub: Fine-tuning a gpt-3.5 ReAct Agent ()
  • GitHub: ReAct Agent - A Simple Intro with Calculator Tools ()
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
@kapa.ai i get this sometimes:

Plain Text
Observation: Error: Error code: 400 - {'error': {'message': "Invalid 'tools': empty array. Expected an array with minimum length 1, but got an empty array instead.", 'type': 'invalid_request_error', 'param': 'tools', 'code': 'empty_array'}}
Let me check the knowledge base for you. One moment! :books:
----------------------
The error message you're seeing indicates that the 'tools' array you're passing to a function or method is empty. In the context of LlamaIndex, tools are often used to define the capabilities of a Query Engine or an Agent.

Here's an example of how tools are defined:

Plain Text
from llama_index.core.tools import ToolMetadata

tools = [
    ToolMetadata(
        name="march_22",
        description="Provides information about Uber quarterly financials ending March 2022",
    ),
    # More tools...
]


And here's how they might be used when creating a Query Engine:

Plain Text
query_engine_tools = [
    QueryEngineTool(
        query_engine=vector_query_engine,
        metadata=ToolMetadata(
            name="vector_tool",
            description=f"Useful for retrieving specific context from {wiki_title}",
        ),
    ),
    # More tools...
]


If you're seeing an error about an empty 'tools' array, it means that you're not providing any tools when they're expected. Make sure that you're defining your tools and passing them to the appropriate function or method.

If you're still having trouble, you might want to check the documentation for the specific function or method you're using. The LlamaIndex documentation provides detailed information about how to use each part of the library.
Sources:
  • LlamaIndex Docs: OpenAI function calling for Sub-Question Query Engine ()
  • LlamaIndex Docs: Define tools for Query Engine ()
  • LlamaIndex Docs: Define tools for Agent ()
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
Add a reply
Sign up and join the conversation on Discord