Neural Mastery
← Practice
ReAct Agent Execution Loophard

ReAct Agent Execution Loop

hardAgents & Applications⏱ 20–25 min
Libraries allowed · Pure Python earns +10 bonus XP
🎯 Mission
Build a ReAct parser and tool execution step engine that connects reasoning traces with real function invocation.

Task

Implement `react_agent_step` parsing `Action:`, `Action Input:`, and `Final Answer:`.

Function Signature

react_agent_step(agent_output: str, available_tools: dict) -> dict

Examples

Example 1: Final Answer Detection
Input: {"agent_output":"Thought: I know the answer.\nFinal Answer: 42","available_tools":{}}
Output: {"status":"finished","final_answer":"42","observation":null}

Constraints

  • If "Final Answer:" is in agent_output, return status "finished".
  • Otherwise parse Action and Action Input, call matching tool from available_tools, and return Observation string.
Python3Saved ✓
def react_agent_step(agent_output, available_tools):
"""
Parses agent_output for Action: <name> and Action Input: <input>.
Executes function from available_tools dict if present.
Return dict {"status": "continue"|"finished"|"error", "observation": str, "final_answer": str|None}
"""
# Your implementation here
pass

Case 1: Final Answer Detection
Input: {"agent_output":"Thought: I know the answer.\nFinal Answer: 42","available_tools":{}}
Expected: {"status":"finished","final_answer":"42","observation":null}