Writing the Core While-Loop Calling Anthropic/OpenAI APIs
The primary control loop that calls the model API, inspects stop_reason (e.g. tool_use vs end_turn), and determines next actions.
Cognitive ReAct Cycle
- 1Thought (Reasoning)Analyzes current state and plans next tactical subgoal.
- 2Action (Tool Invocation)Dispatches validated JSON Schema call to external API.
- 3Observation (Environment)Ingests raw ground-truth API response into memory.
- 4Reflection (Convergence)Evaluates goal completion or iterates to next subgoal.