ReAct agents interleave reasoning and tool use in plain text:
Thought: I need the population first.
Action: search[population of Lyon]
or finish with
Thought: I know the answer.
Final Answer: About 520,000 people.
Implement parse_step(text) returning one of:
{"type": "action", "thought": ..., "tool": ..., "input": ...}{"type": "final", "thought": ..., "answer": ...}Rules:
Thought: may span multiple lines, up to the Action: or Final Answer: line. Strip whitespace. It's "" if missing.Action: tool[input]: the tool name is letters, digits and underscores. The input is everything between the first [ and the last ] on that line, so it may contain brackets.Final Answer: line (including following lines) is part of the answer.ValueError with a helpful message if there's neither, or if the Action line is malformed. Agents feed this error back to the model so it can fix itself.