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

agent after using tools, when no matches found, outputs 'Sorry' #81

Open
Bebezumni opened this issue Dec 16, 2023 · 2 comments
Open

agent after using tools, when no matches found, outputs 'Sorry' #81

Bebezumni opened this issue Dec 16, 2023 · 2 comments

Comments

@Bebezumni
Copy link

Bebezumni commented Dec 16, 2023

Hello, great project. I am very excited with it.
Question is:
How do I correctly tell parser.py to make a next AgentAction or AgentFinish if there is no matches.
This happens everytime my tool cannot find anything in product_catalog to answer the question

def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
    if self.verbose:
        print("TEXT")
        print(text)
        print("-------")
    if f"{self.ai_prefix}:" in text:
        return AgentFinish(
            {"output": text.split(f"{self.ai_prefix}:")[-1].strip()}, text
        )
    regex = r"Action: (.*?)[\n]*Action Input: (.*)"
    match = re.search(regex, text)
    if not match:
        ## TODO - this is not entirely reliable, sometimes results in an error.
        return AgentFinish(
            {
                "output": "I apologize, I was unable to find the answer to your question. Is there anything else I can help with?"
            },
            text,
        )
        # raise OutputParserException(f"Could not parse LLM output: `{text}`")
    action = match.group(1)
    action_input = match.group(2)
    return AgentAction(action.strip(), action_input.strip(" ").strip('"'), text)

currently this part just outputs "I apologize...." as final answer.

@Bebezumni Bebezumni changed the title Chain, after using tools, when no matches found, outputs 'Sorry' agent after using tools, when no matches found, outputs 'Sorry' Dec 16, 2023
@Bebezumni
Copy link
Author

As I found out this part outputs error, if agent on previous stage generated an answer without correct formatting like below:

Thought: Do i need to you a tool? No
Action:Some action

Here is my fix, not sure if everything is correct but all the systems started to work as expected
Changed this:

if not match:
        ## TODO - this is not entirely reliable, sometimes results in an error.
        return AgentFinish(
            {
                "output": "I apologize, I was unable to find the answer to your question. Is there anything else I can help with?"
            },
            text,
        )
        # raise OutputParserException(f"Could not parse LLM output: `{text}`")

On this:

if not match:
    return AgentAction('Thought: Do I need to use a tool? No', f"{self.ai_prefix}:", text)

@ZuzooVn
Copy link

ZuzooVn commented Dec 27, 2023

@Bebezumni did you change ai_prefix to salesperson_name?

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

No branches or pull requests

2 participants