Content not available for this pattern.
Build This Pattern
Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to implement this pattern.
Build me an autonomous AI agent with a ReAct (Reasoning + Acting) loop. Architecture: implement a loop controller that manages the think-act-observe cycle. The agent has access to tools defined in a registry with schemas, handlers, and access controls. Each iteration: agent thinks about current state, decides which action to take, executes the tool call, observes the result, and updates its plan. Use a context object to carry state across iterations. Include a memory system (tool call history plus observations) so the agent tracks what it has tried. Error handling: on tool failure (timeout or API error), log and let the agent try an alternative approach. Implement a circuit breaker per tool: if a tool fails 3 consecutive times, mark it unavailable. Handle LLM parse errors (malformed tool call JSON) with retry and explicit error messaging. Edge cases: set max iterations limit (default 25) with hard cap that stops the loop and returns partial progress. Handle tool timeouts (15s per call, configurable). Support tools that return no results. Detect infinite loops by tracking repeated action-observation cycles without progress and force a replan. Best practices: log each iteration step, tool call, and observation. Make tools configurable via registry with rate limiting. Include pause/resume for long-running agents. Testing: test with tools that always succeed, always fail, and alternate. Verify max iteration enforcement. Test memory history tracking. TypeScript.