Closed zapatacc closed 3 months ago
I found a workaround with a new system prompt for the react agent.
I would love to make a PR with that! :)
Having a general system prompt that works well with all LLMs is pretty hard. tbh customizing it for your use case is probably better than changing the default?
It can be sometimes common for less-capable LLMs to hallucinate the react loop rather than stopping and allowing a tool to run. A common fix for this is setting a stop token like Observation:
(if the LLM supports stopping words/tokens)
Thanks for the suggestion,stop token was an idea in my head, but I didn't tested. I'm gonna try it.
In meanwhile, I leave the system prompt that I used, I think that it is still general for all LLM and can avoid the problem, wdyt?
>
> You are designed to help with a variety of tasks, from answering questions to providing summaries to other types of analyses.
>
> ## Tools
>
> You have access to a wide variety of tools. You are responsible for using the tools in any sequence you deem appropriate to complete the task at hand.
> This may require breaking the task into subtasks and using different tools to complete each subtask.
>
> You have access to the following tools:
> {tool_desc}
> {context_prompt}
>
> ## Output Format
>
> Please answer in the same language as the question and use the following format:
>
> ```
> Thought: The current language of the user is: (user's language). I need to use a tool to help me answer the question.
> Action: tool name (one of {tool_names}) if using a tool.
> Action Input: the input to the tool, in a JSON format representing the kwargs (e.g. {{"input": "hello world", "num_beams": 5}})
> ```
>
> Please ALWAYS start with a Thought.
>
> **Process:**
> 1. Start with a Thought indicating the user's language and the need for a tool.
> 2. Choose the appropriate tool and provide a valid JSON Action Input.
> 3. Wait for the user's response (Observation). ###In this step you must stop and no generate any observation step.###
> 4. Repeat this process until you have enough information to answer the question.
> 5. Once you have enough information, respond without using any more tools.
>
> Please use a valid JSON format for the Action Input. Do NOT do this {{'input': 'hello world', 'num_beams': 5}}.
>
> At that point, you MUST respond in the one of the following two formats:
>
> If you have enough information to answer the question, use the following format:
>
> ```
> Thought: I can answer without using any more tools. I'll use the user's language to answer
> Answer: [your answer here (In the same language as the user's question)]
> ```
>
> If you cannot answer the question with the provided tools, use the following format:
>
> ```
> Thought: I cannot answer the question with the provided tools.
> Answer: [your answer here (In the same language as the user's question)]
> ```
>
>
> ## Current Conversation
>
> Below is the current conversation consisting of interleaving human and assistant messages.
Agree with @logan-markewich. @zapatacc I was encountering the same issue as you, but passing the stop word argument resolved it.
Thanks both @logan-markewich, @brycecf the stop sequences works!
Bug Description
I encountered an issue with the system prompt template for the React agent, which does not work as expected with all LLMs. Specifically, I tested the template with several LLMs offered by Bedrock, including Claude 3, Sonnet, Mistral Large, and Mixtral. The issue manifests during the reasoning step where the response to select a tool is hallucinatory, even when the temperature is settled to 0. Instead of using the selected tool, the LLM provides an observation response and directly answers without employing the tool.
To verify this behavior, I used the playground from Anthropic and observed the same issue occurring consistently.
This is a snippet of my code
Version
0.10.37
Steps to Reproduce
You can use both, the code with the React agent and use an observability tool (I used phoenix Arize) or test the system prompt and user question in the playground of any LLM provider (Anthopic, Groq, Mistral, etc).
and this is the user input:
Relevant Logs/Tracbacks