Skip to main content

parse_react_step

Function parse_react_step 

Source
pub fn parse_react_step(response: &str) -> Result<ReActStep, AgentError>
Expand description

Parses a raw LLM response into a ReActStep.

Models usually write several labelled lines in one response, for example Thought: ... followed by Action: .... The most decisive one wins: Final Answer over Action over Thought. Labels must start a line and are matched case-insensitively (**Action:** also works). Anything from an Observation: line on is ignored, because the model is inventing a tool result it has not received.

Supported action forms:

  • Action: tool(input) (one trailing ) is removed, inner parentheses are kept)
  • Action: tool: input
  • Action: tool followed by an Action Input: input line (LangChain style)
  • Action: tool with no input

ยงErrors

Returns AgentError::ParseError if no label is found, or Action: names no tool.