Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:24kchengYe MemoMind Agentic Tool Calling

From Leeroopedia
Knowledge Sources
Domains LLM_Engineering, Agentic_Systems
Last Updated 2026-10-28 00:00 GMT

Overview

Pattern where an LLM autonomously decides which tools to call, in what order, and how many times, iterating until it has gathered enough information to answer a question.

Description

Unlike a fixed retrieval pipeline (one query → one set of results), an agentic loop lets the LLM drive the retrieval process. The LLM is given a set of tools (search mental models, search observations, recall raw facts, expand context) and decides at each iteration which tool to call with which arguments.

The key advantage is adaptive depth: simple questions may need one recall call, while complex questions ("What patterns do I see in my student lessons?") require multiple decomposed searches ("lessons", "teaching sessions", "student progress") followed by synthesis.

The agent uses a hierarchical retrieval strategy:

  1. Mental models: user-curated summaries (highest quality, try first)
  2. Observations: auto-consolidated knowledge (second priority)
  3. Raw facts: individual memories (ground truth, fallback)

The loop terminates when the agent calls the `done()` tool with its answer, or when a maximum iteration count is reached (forced response).

Usage

Use this principle when a fixed retrieval pipeline is too rigid and the query complexity varies. It is essential for deep reasoning over large memory stores where the optimal retrieval strategy depends on the question.

Theoretical Basis

# Abstract agentic loop (not real implementation)
messages = [system_prompt, user_query]
for iteration in range(max_iterations):
    response = llm.call(messages, tools=tools)
    if response.tool_call == "done":
        return clean_answer(response.answer)
    result = dispatch_tool(response.tool_call)
    messages.append(tool_result(result))
# Force response if max iterations reached
return generate_final_response(messages)

The agent tracks which memory IDs, observation IDs, and mental model IDs were returned by tools, then validates that any IDs cited in the final answer were actually retrieved (anti-hallucination).

Related Pages

Implemented By

Page Connections

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