Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Principle:Openai Openai node Tool Loop Resolution

From Leeroopedia
Knowledge Sources
Domains Function_Calling, Agentic_Patterns
Last Updated 2026-02-15 00:00 GMT

Overview

A principle for resolving a tool execution loop by awaiting the final model response and accessing the complete conversation history including all tool calls and results.

Description

Tool Loop Resolution addresses the end-state of the tool execution loop. After the model has made all necessary tool calls and produced a final text response, the consumer needs to: (1) await completion of the entire loop, (2) access the final model response, and (3) optionally inspect the full conversation history.

The resolution provides both the final response content and the complete message array, which can be persisted for conversation continuity or debugging.

Usage

Use this principle after creating a tool execution runner to await the final result. The finalChatCompletion() method returns a promise that resolves when the tool loop is complete.

Theoretical Basis

Loop resolution follows a Promise Resolution pattern with accumulated state:

// The runner maintains internal state:
runner.messages = []      // Full conversation history
runner.completions = []   // All API responses

// finalChatCompletion() resolves when:
// 1. The model returns a response without tool_calls
// 2. OR maxChatCompletions is reached
// 3. OR an error occurs

result = await runner.finalChatCompletion()
// result: last ChatCompletion from the loop
// runner.messages: complete history including all tool interactions

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment