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 got "No I need to use a tool? No" response from llmm,which CANNOT be parsed #10572

Closed
14 tasks
JxKim opened this issue Sep 14, 2023 · 2 comments
Closed
14 tasks
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: models Related to LLMs or chat model modules

Comments

@JxKim
Copy link

JxKim commented Sep 14, 2023

System Info

def parse(self, text: str) -> Union[AgentAction, AgentFinish]:
    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:
        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)

Who can help?

No response

Information

  • The official example notebooks/scripts
  • My own modified scripts

Related Components

  • LLMs/Chat Models
  • Embedding Models
  • Prompts / Prompt Templates / Prompt Selectors
  • Output Parsers
  • Document Loaders
  • Vector Stores / Retrievers
  • Memory
  • Agents / Agent Executors
  • Tools / Toolkits
  • Chains
  • Callbacks/Tracing
  • Async

Reproduction

  1. init an agent
  2. ask the agent a simple question which it can solve without using any tools

Expected behavior

DONT RAISE ERROR

@JxKim JxKim changed the title agent got "No I need to user a too? No" response from llmm,which CANNOT be parsed agent got "No I need to use a tool? No" response from llmm,which CANNOT be parsed Sep 14, 2023
@dosubot dosubot bot added Ɑ: models Related to LLMs or chat model modules 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature labels Sep 14, 2023
@dosubot
Copy link

dosubot bot commented Sep 14, 2023

🤖

Hello,

Thank you for bringing this issue to our attention. It seems like the error you're encountering is related to the way LangChain's agent parses the output from the language model. If the language model's response includes an action that is not defined in the agent's tools, the agent will raise an error.

This behavior is demonstrated in the test_agent_invalid_tool function in the LangChain's test suite. Here is the relevant code:

def test_agent_invalid_tool() -> None:
    """Test agent invalid tool and correct suggestions."""
    fake_llm = FakeListLLM(responses=["FooBarBaz\nAction: Foo\nAction Input: Bar"])
    tools = [
        Tool(
            name="Search",
            func=lambda x: x,
            description="Useful for searching",
            return_direct=True,
        ),
    ]
    agent = initialize_agent(
        tools=tools,
        llm=fake_llm,
        agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
        return_intermediate_steps=True,
        max_iterations=1,
    )

    resp = agent("when was langchain made")
    resp["intermediate_steps"][0][1] == "Foo is not a valid tool, try one of [Search]."

In this test, the agent is initialized with a single tool named "Search". When the agent runs with the input "when was langchain made", the language model's response includes an action named "Foo". Since "Foo" is not a valid tool in the agent's toolset, the agent raises an error.

This issue has been encountered before in the LangChain repository. Here are some similar issues that have been resolved:

  1. ChatAgent gets "Would you like me to search for more information on it?" instead of Action: or FinalAnswer:
  2. Error: raise ValueError(f"Could not parse LLM output: {text}")
  3. Vertex ChatVertexAI() doesn't support initialize_agent() as OutputParserException error

Unfortunately, I couldn't find the exact error message that is being raised in your case. Could you please provide more details about the error message you're seeing? This will help us better understand the issue and find a solution.

Best,
Dosu

Sources


This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

If you want to continue the conversation, start your reply with @dosu-bot.

Copy link

dosubot bot commented Dec 14, 2023

Hi, @JxKim,

I'm helping the LangChain team manage their backlog and am marking this issue as stale. From what I understand, you raised an issue about difficulty parsing a response from a tool, and Dosubot responded with an explanation of the error, requested more details, and referenced similar resolved issues in the LangChain repository.

Could you please confirm if this issue is still relevant to the latest version of the LangChain repository? If it is, kindly let the LangChain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days. Thank you!

@dosubot dosubot bot added the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 14, 2023
@JxKim JxKim closed this as completed Dec 15, 2023
@dosubot dosubot bot removed the stale Issue has not had recent activity or appears to be solved. Stale issues will be automatically closed label Dec 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature Ɑ: models Related to LLMs or chat model modules
Projects
None yet
Development

No branches or pull requests

1 participant