feat(product-assistant): better failover for the ReAct agent #25903
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Since the ReAct agent doesn't use the structured output, we have to parse manually the response. There are three potential pitfalls:
action
oraction_input
fields.For the first two cases, LangChain provides a parser. However, the parser is very basic and doesn't guide the agent on what it should do when the output's format is incorrect. We frequently are in situations when the agent does 5 to 10 iterations until it corrects itself.
The improved guidelines should help to recover after the first unsuccessful attempt.
Example conversation where the agent generated a final answer on the first run without formatting
Improve the previously generated plan based on the feedback: filter out the us from all eventsThought:
To filter out the US from all events, I need to apply the same property filter to each event in the series.
Events:
Formula:
A/(B+C)
, whereA
is the $pageview event,B
is the signed_up event, andC
is the $identify event.Action: I didn't output the
Action:
block.Observation:
Your previous answer didn't output the
Action:
block. You must always follow the format described in the system prompt.Thought:
Action:
Changes
Added detailed observations based on the improved parsing of the output:
Action:
block, we now append the block to the prompt and output an observation that the output had a wrong format.Does this work well for both Cloud and self-hosted?
N/A
How did you test this code?
Unit tests, manual testing, Langfuse traces.