mellea.stdlib.frameworks.react
ReACT (Reason + Act) agentic pattern implementation.
Provides the react() async function, which drives a tool-use loop: the model
reasons about a goal, selects a tool, receives the result as an observation, and
repeats until it calls final_answer or the loop_budget is exhausted. Accepts
any list of AbstractMelleaTool instances and a ChatContext for multi-turn
history tracking. Raises RuntimeError if the loop ends without a final answer.
Functions
FUNC react
react(goal: str, context: ChatContext, backend: Backend) -> tuple[ComputedModelOutputThunk[str], ChatContext]
Asynchronous ReACT pattern (Think -> Act -> Observe -> Repeat Until Done); attempts to accomplish the provided goal given the provided tools.
Args:
goal: the goal to be accomplished or the question to answercontext: the context being used; a type of ChatContextbackend: the backend used to generate the response.format: if set, the BaseModel to use for constrained decoding.model_options: additional model options, which will upsert into the model/backend's defaults.tools: the list of tools to useloop_budget: the number of steps allowed; use -1 for unlimited
Returns:
- A (ModelOutputThunk, Context) if
return_sampling_resultsisFalse, else returns aSamplingResult.
Raises:
RuntimeError: if the loop ends before a final answer is found