Loading...
const res = await llm.generate({ prompt: transcript });
const finalAnswer = res.text.split('Final Answer:')[1];const res = await llm.generate({ prompt: transcript, stop: ['Observation:'] });
const action = parseAction(res.text);
const observation = await tools[action.name](action.input);
transcript += `${res.text}Observation: ${JSON.stringify(observation)}\n`;Stopping at 'Observation:' makes the code run the real tool, so the model cannot invent the result.
A thought about what to do, an action with a tool and its input, and an observation with the tool result. The loop repeats until a final answer.
Chain-of-thought only reasons. ReAct interleaves reasoning with actions, so the model can look facts up instead of guessing them.
No. With native tool calling the API returns structured actions, so the same loop runs without parsing 'Action:' lines from text.