Skip to main content
Glama

modify_passage

Update text content in an agent's archival memory store. Use this tool to modify existing memory passages by providing the agent ID, memory ID, and new text content.

Instructions

Modify a memory in the agent's archival memory store. Use list_passages to find memory IDs. Currently only supports updating the text content.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
agent_idYesID of the agent whose passage to modify
memory_idYesID of the passage (memory) to modify
update_dataYesObject containing the fields to update. Currently only supports updating the 'text' field.
include_embeddingsNoWhether to include the full embedding vectors in the response (default: false).

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
successYes
new_textNo
passage_idYes

Implementation Reference

  • The primary handler function executing the modify_passage tool logic: validates inputs, fetches existing passage, constructs update payload, performs PATCH API call, and returns structured response.
    export async function handleModifyPassage(server, args) {
        if (!args?.agent_id) {
            server.createErrorResponse('Missing required argument: agent_id');
        }
        if (!args?.memory_id) {
            server.createErrorResponse('Missing required argument: memory_id');
        }
        if (!args?.update_data || typeof args.update_data.text !== 'string') {
            // Ensure text is provided and is a string
            server.createErrorResponse(
                "Missing or invalid required argument: update_data must contain a 'text' field (string).",
            );
        }
    
        try {
            const headers = server.getApiHeaders();
            const agentId = encodeURIComponent(args.agent_id);
            const memoryId = args.memory_id; // Use for finding, encode for URL
    
            // Step 1: Fetch ALL passages for the agent to find the target one
            let existingPassage = null;
            try {
                // Use list_passages logic internally, ensuring embeddings are included for the PATCH
                const listResponse = await server.api.get(`/agents/${agentId}/archival-memory`, {
                    headers,
                    params: { include_embeddings: true }, // Ensure we get embeddings
                });
                const allPassages = listResponse.data;
                if (Array.isArray(allPassages)) {
                    existingPassage = allPassages.find((p) => p.id === memoryId);
                }
                if (!existingPassage) {
                    throw new Error(`Could not find passage ${memoryId} for agent ${agentId}.`);
                }
                // Basic check for required fields based on the schema provided by the user
                if (
                    !existingPassage.embedding_config ||
                    !existingPassage.id ||
                    existingPassage.text === undefined
                ) {
                    logger.error('Fetched passage object is missing required fields:', existingPassage);
                    throw new Error(
                        `Fetched passage ${memoryId} is missing required fields (embedding_config, id, text).`,
                    );
                }
            } catch (fetchError) {
                if (fetchError.response && fetchError.response.status === 404) {
                    server.createErrorResponse(
                        `Agent not found when listing passages: ${args.agent_id}`,
                    );
                }
                logger.error('Error fetching passages:', fetchError);
                server.createErrorResponse(
                    `Failed to fetch passages for agent ${args.agent_id}: ${fetchError.message}`,
                );
            }
    
            // Step 2: Construct the full update payload based on the fetched passage, modifying only the text
            const updatePayload = {
                ...existingPassage, // Copy all fields from the fetched passage
                text: args.update_data.text, // Update the text field
            };
    
            // Remove fields that shouldn't be sent in PATCH body if necessary (adjust based on API behavior)
            // delete updatePayload.created_at;
            // delete updatePayload.updated_at;
            // delete updatePayload.created_by_id;
            // delete updatePayload.last_updated_by_id;
            // delete updatePayload.organization_id;
            // delete updatePayload.agent_id; // agent_id is in the URL path
    
            logger.info(
                `[modify_passage] Sending payload for memory_id ${memoryId}:`,
                JSON.stringify(updatePayload),
            );
    
            // Step 3: Send the PATCH request with the complete payload
            const patchResponse = await server.api.patch(
                `/agents/${agentId}/archival-memory/${encodeURIComponent(memoryId)}`,
                updatePayload,
                { headers },
            );
            let modifiedPassages = patchResponse.data; // API returns an array of modified Passage objects
    
            // Optionally remove embeddings from the response based on the flag
            const includeEmbeddings = args?.include_embeddings ?? false;
            if (!includeEmbeddings && Array.isArray(modifiedPassages)) {
                modifiedPassages = modifiedPassages.map((passage) => {
                    // eslint-disable-next-line no-unused-vars
                    const { embedding, ...rest } = passage;
                    return rest;
                });
            }
    
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            passages: modifiedPassages,
                        }),
                    },
                ],
            };
        } catch (error) {
            logger.error('[modify_passage] Error:', error.response?.data || error.message);
            if (error.response) {
                if (error.response.status === 404) {
                    server.createErrorResponse(
                        `Agent or Passage not found during update: agent_id=${args.agent_id}, memory_id=${args.memory_id}`,
                    );
                }
                if (error.response.status === 422) {
                    server.createErrorResponse(
                        `Validation error modifying passage ${args.memory_id}: ${JSON.stringify(error.response.data)}`,
                    );
                }
            }
            server.createErrorResponse(error);
        }
    }
  • Tool definition with inputSchema for validating arguments to the modify_passage tool.
    export const modifyPassageDefinition = {
        name: 'modify_passage',
        description:
            "Modify a memory in the agent's archival memory store. Use list_passages to find memory IDs. Currently only supports updating the text content.",
        inputSchema: {
            type: 'object',
            properties: {
                agent_id: {
                    type: 'string',
                    description: 'ID of the agent whose passage to modify',
                },
                memory_id: {
                    type: 'string',
                    description: 'ID of the passage (memory) to modify',
                },
                update_data: {
                    type: 'object',
                    description:
                        "Object containing the fields to update. Currently only supports updating the 'text' field.",
                    properties: {
                        text: {
                            type: 'string',
                            description: 'The new text content for the passage.',
                        },
                        // Add other fields here if the API supports updating them via PassageUpdate schema
                    },
                    required: ['text'], // Require 'text' within the update_data object
                },
                include_embeddings: {
                    type: 'boolean',
                    description:
                        'Whether to include the full embedding vectors in the response (default: false).',
                    default: false,
                },
            },
            required: ['agent_id', 'memory_id', 'update_data'],
        },
    };
  • Registration of the modify_passage handler in the central MCP tool call dispatcher switch statement.
    case 'modify_passage':
        return handleModifyPassage(server, request.params.arguments);
  • Import of the handler and definition from the implementation file.
    import { handleModifyPassage, modifyPassageDefinition } from './passages/modify-passage.js';
  • Output schema for structured responses from the modify_passage tool.
    modify_passage: {
        type: 'object',
        properties: {
            success: { type: 'boolean' },
            passage_id: { type: 'string' },
            new_text: { type: 'string' },
        },
        required: ['success', 'passage_id'],
    },
Behavior4/5

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

Annotations only provide a generic title ('Update Archival Memory'), so the description carries full burden. It discloses key behavioral traits: this is a mutation operation (implied by 'Modify'), it requires specific IDs (agent_id, memory_id), and has a current limitation (text-only updates). However, it doesn't mention permissions, rate limits, or whether changes are reversible.

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?

Two sentences, zero waste. The first sentence states the core purpose, the second adds critical constraints. Both sentences earn their place by providing essential information not obvious from the tool name or annotations.

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

Completeness4/5

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

Given this is a mutation tool with no annotations covering safety/behavior, the description does well by stating the purpose, prerequisite (list_passages), and current limitation. Since an output schema exists, it doesn't need to explain return values. However, it could better address behavioral aspects like permissions or idempotency.

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 4 parameters thoroughly. The description adds minimal value beyond the schema: it reinforces that 'update_data' is for 'text content' updates only, but doesn't provide additional syntax, format, or contextual details not already in the schema descriptions.

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 specific action ('Modify a memory'), resource ('in the agent's archival memory store'), and scope ('Currently only supports updating the text content'). It distinguishes from sibling tools like 'create_passage' (creation), 'delete_passage' (deletion), and 'list_passages' (listing).

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: 'Use list_passages to find memory IDs' (prerequisite) and 'Currently only supports updating the text content' (limitation vs. alternatives like 'update_memory_block' for broader updates). It clearly directs to a specific sibling tool for ID discovery.

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