nat.plugins.langchain.agent.react_agent.output_parser#

Attributes#

Exceptions#

ReActAgentParsingFailedError

Raised when the ReAct agent fails to parse the LLM output after exhausting all retries.

ReActOutputParserException

Inappropriate argument value (of correct type).

Classes#

ReActOutputParser

Parses ReAct-style LLM calls that have a single tool input.

Module Contents#

FINAL_ANSWER_ACTION = 'Final Answer:'#
FINAL_ANSWER_PATTERN#
MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGE = "Invalid Format: Missing 'Action:' after 'Thought:'"#
MISSING_ACTION_INPUT_AFTER_ACTION_ERROR_MESSAGE = "Invalid Format: Missing 'Action Input:' after 'Action:'"#
FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE = 'Parsing LLM output produced both a final answer and a parse-able action:'#
exception ReActAgentParsingFailedError(
observation: str,
llm_output: str,
attempts: int,
)#

Bases: RuntimeError

Raised when the ReAct agent fails to parse the LLM output after exhausting all retries.

This exception allows callers to programmatically detect parsing failures instead of receiving error messages as “successful” answers.

Attributes:

observation: The error message describing the parsing failure. llm_output: The original LLM output that failed to parse. attempts: The number of parsing attempts made before failing.

Initialize self. See help(type(self)) for accurate signature.

observation#
llm_output#
attempts#
exception ReActOutputParserException(
observation: str | None = None,
missing_action: bool = False,
missing_action_input: bool = False,
final_answer_and_action: bool = False,
llm_output: str | None = None,
)#

Bases: ValueError, langchain_core.exceptions.LangChainException

Inappropriate argument value (of correct type).

Initialize self. See help(type(self)) for accurate signature.

observation = None#
missing_action = False#
missing_action_input = False#
final_answer_and_action = False#
llm_output = None#
class ReActOutputParser#

Bases: langchain_classic.agents.agent.AgentOutputParser

Parses ReAct-style LLM calls that have a single tool input.

Expects output to be in one of two formats.

If the output signals that an action should be taken, should be in the below format. This will result in an AgentAction being returned.

Thought: agent thought here

Action: search

Action Input: what is the temperature in SF?

Observation: Waiting for the tool response...

If the output signals that a final answer should be given, should be in the below format. This will result in an AgentFinish being returned.

Thought: agent thought here

Final Answer: The temperature is 100 degrees
get_format_instructions() str#
parse(
text: str,
) langchain_core.agents.AgentAction | langchain_core.agents.AgentFinish#

Parse text into agent action/finish.

property _type: str#