Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Principle:Langchain ai Langchain Conversation Looping

From Leeroopedia
Knowledge Sources
Domains Agentic_AI, Conversation_Management
Last Updated 2026-02-11 00:00 GMT

Overview

An iterative pattern where the model is re-invoked with accumulated conversation history including tool results until it produces a final text response.

Description

After executing tool calls and creating ToolMessages, the conversation loop re-invokes the model with the full message history: the original HumanMessage, the AIMessage containing tool calls, and the ToolMessages with results. The model may respond with additional tool calls (continuing the loop) or with a final text answer (ending the loop).

This pattern implements the core agent loop used in ReAct-style agents.

Usage

Use this pattern whenever tool execution may require multiple rounds of model-tool interaction. The loop continues until the model responds without tool calls or a maximum iteration limit is reached.

Theoretical Basis

# Abstract agent loop (not real code)
messages = [HumanMessage(content=user_query)]
while True:
    response = model.invoke(messages)
    if not response.tool_calls:
        return response.content  # Final answer
    messages.append(response)  # AIMessage with tool_calls
    for tool_call in response.tool_calls:
        result = execute_tool(tool_call)
        messages.append(ToolMessage(content=result, tool_call_id=tool_call.id))

Related Pages

Implemented By

Page Connections

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