Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(product-assistant): better failover for the ReAct agent #25903

Merged
merged 8 commits into from
Oct 30, 2024

Conversation

skoob13
Copy link
Contributor

@skoob13 skoob13 commented Oct 30, 2024

Problem

Since the ReAct agent doesn't use the structured output, we have to parse manually the response. There are three potential pitfalls:

  • The agent can completely omit the action block.
  • The agent can output a malformed JSON, e.g., missing action or action_input fields.
  • The agent can hallucinate and output non-existing tools or use a wrong schema for the tool input.

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 events

Thought:
To filter out the US from all events, I need to apply the same property filter to each event in the series.

Events:

  • $pageview
    • math operation: total count
    • property filter:
      • entity: event
      • property name: $geoip_country_code
      • property type: String
      • operator: doesn't equal
      • property value: US
  • signed_up
    • math operation: total count
    • property filter:
      • entity: event
      • property name: $geoip_country_code
      • property type: String
      • operator: doesn't equal
      • property value: US
  • $identify
    • math operation: total count
    • property filter:
      • entity: event
      • property name: $geoip_country_code
      • property type: String
      • operator: doesn't equal
      • property value: US

Formula:
A/(B+C), where A is the $pageview event, B is the signed_up event, and C 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:

{
  "action": "final_answer",
  "action_input": "Events:\n- $pageview\n    - math operation: total count\n    - property filter:\n        - entity: event\n        - property name: $geoip_country_code\n        - property type: String\n        - operator: doesn't equal\n        - property value: US\n- signed_up\n    - math operation: total count\n    - property filter:\n        - entity: event\n        - property name: $geoip_country_code\n        - property type: String\n        - operator: doesn't equal\n        - property value: US\n- $identify\n    - math operation: total count\n    - property filter:\n        - entity: event\n        - property name: $geoip_country_code\n        - property type: String\n        - operator: doesn't equal\n        - property value: US\n\nFormula:\n`A/(B+C)`, where `A` is the $pageview event, `B` is the signed_up event, and `C` is the $identify event."
}

Changes

Added detailed observations based on the improved parsing of the output:

  • When the agent omits the Action: block, we now append the block to the prompt and output an observation that the output had a wrong format.
  • When the agent outputs a malformed JSON, add the observation to remind that it must follow the format instruction.
  • When the agent outputs a non-existing tool or tool's schema that doesn't match the input, return the descriptive observation describing the Pydantic exception.

Does this work well for both Cloud and self-hosted?

N/A

How did you test this code?

Unit tests, manual testing, Langfuse traces.

@skoob13 skoob13 requested a review from Twixes October 30, 2024 13:40
@skoob13 skoob13 enabled auto-merge (squash) October 30, 2024 14:24
@skoob13 skoob13 merged commit 1fbc799 into master Oct 30, 2024
85 of 86 checks passed
@skoob13 skoob13 deleted the feat/improved-failover-for-taxonomy-agent branch October 30, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants