Skip to main content
Glama

search_archival_memory

Find relevant information in an agent's stored memories using semantic search. Filter results by tags, date ranges, and other criteria to retrieve contextually similar passages.

Instructions

Search an agent's archival memory using semantic similarity. Returns passages most similar to the query. Use list_passages for text-based search or pagination, create_passage to add memories.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_idYesID of the agent whose archival memory to search
queryYesSearch query for semantic similarity matching
tagsNoOptional list of tags to filter passages by
tag_match_modeNoHow to match tags: "any" returns passages with at least one matching tag, "all" requires all tags to match
top_kNoMaximum number of results to return (default varies by server)
start_datetimeNoFilter passages created after this datetime (ISO 8601 format)
end_datetimeNoFilter passages created before this datetime (ISO 8601 format)
include_embeddingsNoWhether to include the full embedding vectors in the response (default: false)

Implementation Reference

  • The main handler function that implements the search_archival_memory tool logic: validates inputs, constructs API parameters, calls the semantic search endpoint on agent's archival memory, processes results (optionally strips embeddings), and returns JSON-formatted passages.
    export async function handleSearchArchivalMemory(server, args) {
        if (!args?.agent_id) {
            throw new Error('Missing required argument: agent_id');
        }
        if (!args?.query) {
            throw new Error('Missing required argument: query');
        }
    
        try {
            const headers = server.getApiHeaders();
            const agentId = encodeURIComponent(args.agent_id);
    
            // Construct query parameters
            const params = {
                query: args.query,
            };
            if (args.tags) params.tags = args.tags;
            if (args.tag_match_mode) params.tag_match_mode = args.tag_match_mode;
            if (args.top_k) params.top_k = args.top_k;
            if (args.start_datetime) params.start_datetime = args.start_datetime;
            if (args.end_datetime) params.end_datetime = args.end_datetime;
    
            // Use the semantic search endpoint
            const response = await server.api.get(`/agents/${agentId}/archival-memory/search`, {
                headers,
                params,
            });
            // Search endpoint returns {results: [], count: N}
            let passages = response.data.results || [];
    
            // Optionally remove embeddings from the response
            const includeEmbeddings = args?.include_embeddings ?? false;
            if (!includeEmbeddings) {
                passages = passages.map((passage) => {
                    // eslint-disable-next-line no-unused-vars
                    const { embedding, ...rest } = passage;
                    return rest;
                });
            }
    
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            passages: passages,
                        }),
                    },
                ],
            };
        } catch (error) {
            return server.createErrorResponse(error);
        }
    }
  • The tool definition object including name, description, and detailed inputSchema with properties, types, descriptions, and required fields for the search_archival_memory tool.
    export const searchArchivalMemoryDefinition = {
        name: 'search_archival_memory',
        description:
            "Search an agent's archival memory using semantic similarity. Returns passages most similar to the query. Use list_passages for text-based search or pagination, create_passage to add memories.",
        inputSchema: {
            type: 'object',
            properties: {
                agent_id: {
                    type: 'string',
                    description: 'ID of the agent whose archival memory to search',
                },
                query: {
                    type: 'string',
                    description: 'Search query for semantic similarity matching',
                },
                tags: {
                    type: 'array',
                    items: { type: 'string' },
                    description: 'Optional list of tags to filter passages by',
                },
                tag_match_mode: {
                    type: 'string',
                    enum: ['any', 'all'],
                    description:
                        'How to match tags: "any" returns passages with at least one matching tag, "all" requires all tags to match',
                },
                top_k: {
                    type: 'integer',
                    description: 'Maximum number of results to return (default varies by server)',
                },
                start_datetime: {
                    type: 'string',
                    format: 'date-time',
                    description: 'Filter passages created after this datetime (ISO 8601 format)',
                },
                end_datetime: {
                    type: 'string',
                    format: 'date-time',
                    description: 'Filter passages created before this datetime (ISO 8601 format)',
                },
                include_embeddings: {
                    type: 'boolean',
                    description:
                        'Whether to include the full embedding vectors in the response (default: false)',
                    default: false,
                },
            },
            required: ['agent_id', 'query'],
        },
    };
  • The dispatch case in the central MCP tool call handler (registerToolHandlers) that routes 'search_archival_memory' calls to the specific handleSearchArchivalMemory function.
    case 'search_archival_memory':
        return handleSearchArchivalMemory(server, request.params.arguments);
  • The import statement bringing in the handler and definition from the implementation file.
        handleSearchArchivalMemory,
        searchArchivalMemoryDefinition,
    } from './passages/search-archival-memory.js';
  • Inclusion of the tool definition in the allTools array used for listing available tools.
    searchArchivalMemoryDefinition,
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the search returns 'passages most similar to the query' but doesn't disclose important behavioral traits like authentication requirements, rate limits, error conditions, or what happens when no matches are found. The description is adequate but lacks depth for a search tool with 8 parameters.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is perfectly concise with three sentences that each earn their place: states the purpose, describes the return, and provides usage guidelines. It's front-loaded with the core functionality and wastes no words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a search tool with 8 parameters and no output schema, the description is minimally complete. It covers the basic purpose and alternatives but lacks details about return format, pagination, error handling, or performance characteristics. Without annotations or output schema, more behavioral context would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 8 parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema. It mentions semantic similarity for the query but doesn't provide additional context about parameter interactions or usage patterns.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('search', 'returns') and resource ('agent's archival memory'), distinguishing it from siblings like list_passages (text-based search) and create_passage (adding memories). It precisely defines the semantic similarity matching approach.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly provides when-to-use guidance by naming alternatives: 'Use list_passages for text-based search or pagination, create_passage to add memories.' This gives clear context for when this tool is appropriate versus other options.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/oculairmedia/Letta-MCP-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server