Skip to content

LLM misinterprets "Plain text responses are not permitted" message as coming from the user #1993

Closed
@hovi

Description

@hovi

Description

Simple currently working usecase

I am running tool, my LLM responds with plaintext and gets user response:

Plain text responses are not permitted, please include your response in a tool call

Fix the errors and try again.

LLM retries, responds with the correct tool call and everything is fine.

Problem

The problem happens, when the LLM assumes, that this message is from "user" as the rest of chat history (like initial chat message), then it gets confused about the "user" wanting 2 conflicting things. It doesn't understand, that this is not a "real user message", but just a validator feedback.

When I customized the library and modified the feedback text to:

Validator feedback (not from the user):
Plain text responses are not permitted, please include your response in a tool call

Fix the errors and try again.

Suddenly LLM was able to figure out what is happening and my flow works correctly.

Example

Example output, where LLM gets confused and stack between sending plaintext responses and calling the same tool over and over again incorrectly:

<think> Okay, the user wants to connect to a human representative but hasn't provided their email or phone number. The assistant tried to ask for them, but the user's previous message was a tool call that failed because the required info was missing. Now, the user is reminding us to fix the errors and try again.

The problem is that the assistant can't make a tool call without the required info. So the assistant needs to prompt the user to provide their email or phone number. The user's current message is asking for plain text responses to be included in a tool call, but the assistant can't do that without the necessary info.

The assistant should respond by asking the user to provide their email or phone number so that it can proceed with connecting them. This way, the user's information is collected, and the tool call can be made once the required data is available.

The assistant should maintain a polite and helpful tone, ensuring the user understands that they need to provide the necessary details for the connection to happen. Once the user provides the info, the assistant can call the connect_to_human function with the available data. </think>

I'm sorry, but I can't connect you to a human representative right now because I don't have your email or phone number. Could you please provide those details so I can forward your request accordingly?

Solution

I want to be flexible and to use wording that aligns as much as possible with what my agent is trying to achieve and minimize anything confusing, therefore I need to be able to modify these texts (also think about i18n).

I think for now I need to make configurable just this line:

#messages.py
return f'{description}\n\nFix the errors and try again.'

But I may end up wanting to modify even specific tool validation messages in _agent_graph.py like "Plain text responses are not permitted, please include your response in a tool call" mentioned above.

Would be good to do this on per-tool basis rather than global or per-agent. Not sure how to approach this exactly as I am not that much familiar with the library yet. Happy to implement this and make PR, just need some direction to make sure I take the right approach and have good chances of doing it well and merging.

References

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions