Skip to main content
Glama

update_memory

Atomically edit a memory in-place to correct facts, update deadlines, or re-score importance. Preserves memory_id for referential integrity.

Instructions

Atomically edit an existing memory in-place. Preferred over forget+remember because it preserves memory_id, which matters for session_file_edits links and referential integrity. Use to correct facts, update deadlines in goal entries, refine caveats, or re-score importance. Caveat-layer memories can be updated but cannot have their protected flag removed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
memory_idYesThe memory.id to update
contentNoNew content (plain text or JSON). If omitted, content is kept.
layerNoMove to a different layer (aliases accepted). If omitted, layer is kept.
importanceNoNew importance 0-1. Set to 0.9 or higher to pin.

Implementation Reference

  • The core handler function `handleUpdateMemory` that executes the update_memory tool logic. It looks up the memory by ID, patches content/layer/importance fields (with validation for caveat protection and layer aliases), runs the SQL UPDATE, records an audit event, and returns the result.
    function handleUpdateMemory(args: any): string {
      const memoryId = Number(args.memory_id);
      if (!Number.isFinite(memoryId)) {
        return JSON.stringify({ ok: false, error: 'memory_id (number) required' });
      }
      const existing = db.prepare('SELECT id, entity_id, layer, content, importance, protected FROM memories WHERE id = ?').get(memoryId) as any;
      if (!existing) {
        return JSON.stringify({ ok: false, error: `memory_id ${memoryId} not found` });
      }
    
      const patch: Record<string, any> = {};
      if (typeof args.content === 'string') patch.content = args.content;
      if (typeof args.layer === 'string') {
        const resolved = resolveLayer(args.layer);
        if (!resolved || !(LAYER_ENUM as readonly string[]).includes(resolved)) {
          return JSON.stringify({ ok: false, error: `unknown layer "${args.layer}"` });
        }
        // Cannot demote a caveat out of caveat (caveat is auto-protected by trigger)
        if (existing.layer === 'caveat' && resolved !== 'caveat' && existing.protected === 1) {
          return JSON.stringify({
            ok: false,
            error: 'Cannot move a protected caveat memory to another layer. Create a new memory in the target layer instead.',
          });
        }
        patch.layer = resolved;
      }
      if (args.importance !== undefined) {
        const imp = Math.min(1, Math.max(0, Number(args.importance)));
        patch.importance = imp;
        patch.protected = imp >= 0.9 || existing.protected === 1 ? 1 : 0;
      }
    
      const keys = Object.keys(patch);
      if (keys.length === 0) {
        return JSON.stringify({ ok: false, error: 'no fields to update (provide content, layer, or importance)' });
      }
      const setClause = keys.map((k) => `${k} = ?`).join(', ');
      const values = keys.map((k) => patch[k]);
      db.prepare(`UPDATE memories SET ${setClause} WHERE id = ?`).run(...values, memoryId);
    
      // Record the update as an event for audit trail
      db.prepare('INSERT INTO events (entity_id, kind, payload) VALUES (?, ?, ?)').run(
        existing.entity_id,
        'memory_updated',
        JSON.stringify({ memory_id: memoryId, changed: keys })
      );
    
      return JSON.stringify({
        ok: true,
        memory_id: memoryId,
        updated_fields: keys,
        pinned: (patch.importance ?? existing.importance) >= 0.9,
      });
    }
  • The input schema definition for the update_memory tool — declares parameters (memory_id required, content/layer/importance optional) with descriptions and constraints.
    {
      name: 'update_memory',
      description:
        'Atomically edit an existing memory in-place. Preferred over forget+remember because it preserves memory_id, which matters for session_file_edits links and referential integrity. Use to correct facts, update deadlines in goal entries, refine caveats, or re-score importance. Caveat-layer memories can be updated but cannot have their protected flag removed.',
      inputSchema: {
        type: 'object',
        properties: {
          memory_id: { type: 'number', description: 'The memory.id to update' },
          content: { type: 'string', description: 'New content (plain text or JSON). If omitted, content is kept.' },
          layer: { type: 'string', description: 'Move to a different layer (aliases accepted). If omitted, layer is kept.' },
          importance: { type: 'number', minimum: 0, maximum: 1, description: 'New importance 0-1. Set to 0.9 or higher to pin.' },
        },
        required: ['memory_id'],
      },
    },
  • The dispatch switch-case that routes the 'update_memory' tool name to the handleUpdateMemory handler in the CallToolRequestSchema handler.
    case 'update_memory': text = handleUpdateMemory(args); break;
  • The resolveLayer helper function used by handleUpdateMemory to resolve layer aliases (e.g., 'decisions' to 'learning') before updating.
    function resolveLayer(input: string | undefined): string | undefined {
      if (!input) return undefined;
      const k = String(input).toLowerCase().trim();
      return LAYER_ALIASES[k] ?? k;
    }
Behavior4/5

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

Despite no annotations, description discloses atomicity, preservation of memory_id, and referential integrity. It mentions caveat-layer constraints. Missing details on permissions or error behaviors, but adequate for a mutation tool.

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 concise sentences. First sentence states core purpose and key benefit. Second sentence provides use cases and a constraint. No redundancy or unnecessary details.

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

Completeness5/5

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

Covers purpose, usage, parameter details, and key behavioral traits (atomicity, referential integrity, caveat-layer limitation). Without output schema, return value is unmentioned, but overall completeness is high given the tool's complexity.

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

Parameters4/5

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

Schema description coverage is 100%, but description adds value beyond schema: 'aliases accepted' for layer and 'Set to 0.9 or higher to pin' for importance. This enhances understanding beyond parameter names and types.

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?

Clearly states it atomically edits an existing memory in-place, specifying what actions it performs (update content, layer, importance). It explicitly distinguishes itself from the forget+remember alternative by highlighting preservation of memory_id and referential integrity.

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?

Provides explicit guidance on when to use: for correcting facts, updating deadlines, refining caveats, re-scoring importance. It also states a limitation for caveat-layer memories regarding protected flags, implying when not to fully update.

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/michielinksee/linksee-memory'

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