ReActSingleInputOutputParser Class — langchain Architecture
Architecture documentation for the ReActSingleInputOutputParser class in react_single_input.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 44a4a52d_37e0_f939_5bc2_6364be670573["ReActSingleInputOutputParser"] d9685a4b_26b0_bca9_f857_03bb2ffc9dd4["AgentOutputParser"] 44a4a52d_37e0_f939_5bc2_6364be670573 -->|extends| d9685a4b_26b0_bca9_f857_03bb2ffc9dd4 6f95aa69_05b0_b1f7_29cf_f2fc2f4a69d4["react_single_input.py"] 44a4a52d_37e0_f939_5bc2_6364be670573 -->|defined in| 6f95aa69_05b0_b1f7_29cf_f2fc2f4a69d4 0fb507b9_753f_6cee_63fc_4dbef7a03dd1["get_format_instructions()"] 44a4a52d_37e0_f939_5bc2_6364be670573 -->|method| 0fb507b9_753f_6cee_63fc_4dbef7a03dd1 7d02b89a_0f19_a4f4_59fd_ff7b5791e7cf["parse()"] 44a4a52d_37e0_f939_5bc2_6364be670573 -->|method| 7d02b89a_0f19_a4f4_59fd_ff7b5791e7cf 1dedd586_8f43_c091_c584_1bd5ef6bc1cd["_type()"] 44a4a52d_37e0_f939_5bc2_6364be670573 -->|method| 1dedd586_8f43_c091_c584_1bd5ef6bc1cd
Relationship Graph
Source Code
libs/langchain/langchain_classic/agents/output_parsers/react_single_input.py lines 22–101
class ReActSingleInputOutputParser(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?
```
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
```
"""
@override
def get_format_instructions(self) -> str:
return FORMAT_INSTRUCTIONS
@override
def parse(self, text: str) -> AgentAction | AgentFinish:
includes_answer = FINAL_ANSWER_ACTION in text
regex = (
r"Action\s*\d*\s*:[\s]*(.*?)[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)"
)
action_match = re.search(regex, text, re.DOTALL)
if action_match:
if includes_answer:
msg = f"{FINAL_ANSWER_AND_PARSABLE_ACTION_ERROR_MESSAGE}: {text}"
raise OutputParserException(msg)
action = action_match.group(1).strip()
action_input = action_match.group(2)
tool_input = action_input.strip(" ")
tool_input = tool_input.strip('"')
return AgentAction(action, tool_input, text)
if includes_answer:
return AgentFinish(
{"output": text.rsplit(FINAL_ANSWER_ACTION, maxsplit=1)[-1].strip()},
text,
)
if not re.search(r"Action\s*\d*\s*:[\s]*(.*?)", text, re.DOTALL):
msg = f"Could not parse LLM output: `{text}`"
raise OutputParserException(
msg,
observation=MISSING_ACTION_AFTER_THOUGHT_ERROR_MESSAGE,
llm_output=text,
send_to_llm=True,
)
if not re.search(
r"[\s]*Action\s*\d*\s*Input\s*\d*\s*:[\s]*(.*)",
text,
re.DOTALL,
):
msg = f"Could not parse LLM output: `{text}`"
raise OutputParserException(
msg,
observation=MISSING_ACTION_INPUT_AFTER_ACTION_ERROR_MESSAGE,
llm_output=text,
send_to_llm=True,
)
msg = f"Could not parse LLM output: `{text}`"
raise OutputParserException(msg)
@property
def _type(self) -> str:
return "react-single-input"
Extends
Source
Frequently Asked Questions
What is the ReActSingleInputOutputParser class?
ReActSingleInputOutputParser is a class in the langchain codebase, defined in libs/langchain/langchain_classic/agents/output_parsers/react_single_input.py.
Where is ReActSingleInputOutputParser defined?
ReActSingleInputOutputParser is defined in libs/langchain/langchain_classic/agents/output_parsers/react_single_input.py at line 22.
What does ReActSingleInputOutputParser extend?
ReActSingleInputOutputParser extends AgentOutputParser.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free