> ## Documentation Index
> Fetch the complete documentation index at: https://docs.veadk.xyz/llms.txt
> Use this file to discover all available pages before exploring further.

# Long-term memory retrieval

## Overview

Tool identifier `load_memory`.

System tools are built-in tools that VeADK mounts **automatically** based on the agent's configuration — you don't add them to the `tools` list yourself. When you pass a `long_term_memory` to the agent, VeADK mounts the `load_memory` tool. Across sessions, the agent decides on its own when to query long-term memory to retain user preferences, history, and other long-lived state.

For long-term memory backends and configuration, see the [long-term memory docs](/productions/veadk/preview/en/components/memory).

## Prerequisites

Install `python -m pip install "veadk-python[extensions]"`, then configure the [model](/productions/veadk/preview/en/components/agent/model) and [local backend](/productions/veadk/preview/en/components/memory/local). Local storage still sends text to the configured embedding service. Ingest data before the first search.

## Usage

```python lines theme={null}
import asyncio
from google.adk.events import Event
from google.adk.sessions import Session
from google.genai import types
from veadk import Agent, Runner
from veadk.memory.long_term_memory import LongTermMemory

memory = LongTermMemory(backend="local", index="ltm_demo")
agent = Agent(
    name="memory_agent",
    instruction="Call load_memory to find the user's saved language preference before answering.",
    long_term_memory=memory,
)
runner = Runner(agent=agent, app_name="ltm_demo")

async def main():
    previous = Session(
        id="previous_chat", app_name="ltm_demo", user_id="user_42",
        events=[Event(author="user", content=types.Content(
            role="user", parts=[types.Part(text="My preferred language is Chinese")]
        ))],
    )
    await memory.add_session_to_memory(previous)
    result = await runner.run(
        "What is my preferred language?", user_id="user_42", session_id="new_chat"
    )
    print(result)

asyncio.run(main())
```

## Notes

<Note>
  System tools are managed by the framework: just provide a `long_term_memory` — you don't add `load_memory` to the `tools` list yourself. The agent decides when to call it based on its instruction and user input.
</Note>

## Retrieval input and checks

| Parameter | Type | Default | Description |
| :- | :- | :- | :- |
| `query` | `str` | Required | Search terms or question generated by the agent |
| `tool_context` | `ToolContext` | Injected | Current invocation context, not supplied by the model |

The `memories` list contains retrieved long-term memories. This example stores a language preference and retrieves it from another session; the expected answer includes Chinese. A `local` instance does not filter by user or application, so do not mix private memories from different users. Select appropriate isolation and persistence for production.

The model still decides whether to call the tool. If the answer does not reflect the data, inspect tool events and retrieval results. If direct retrieval fails, check ingestion, embedding configuration, and backend permissions first.
