Skip to main content
Glama

attach_memory_block

Attach a memory block to an agent in the Letta system to provide context, persona, or system information for enhanced interactions.

Instructions

Attach a memory block to an agent. Use list_memory_blocks to find blocks, create_memory_block to make new ones. Common labels: "persona", "human", "system".

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
block_idYesThe ID of the memory block to attach
agent_idYesThe ID of the agent to attach the memory block to
labelNoOptional label for the memory block (e.g., "persona", "human", "system")

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
labelNo
successYes
agent_idNo
block_idNo

Implementation Reference

  • The handler function that implements the core logic of the attach_memory_block tool: validates inputs, verifies the memory block exists, attaches it to the agent via Letta API, fetches updated agent info, and returns a structured response.
    export async function handleAttachMemoryBlock(server, args) {
        try {
            // Validate arguments
            if (!args.block_id) {
                throw new Error('Missing required argument: block_id');
            }
            if (!args.agent_id) {
                throw new Error('Missing required argument: agent_id');
            }
    
            // Headers for API requests
            const headers = server.getApiHeaders();
            headers['user_id'] = args.agent_id;
    
            // Verify block exists
            const blockResponse = await server.api.get(`/blocks/${args.block_id}`, { headers });
            const blockData = blockResponse.data;
            const blockName = blockData.name || 'Unnamed Block';
    
            // Determine label to use
            const label = args.label || blockData.label || 'custom';
    
            // Attach block to agent
            logger.info(
                `Attaching memory block ${blockName} (${args.block_id}) to agent ${args.agent_id} with label ${label}...`,
            );
    
            // Use the core-memory/blocks/attach endpoint
            const attachUrl = `/agents/${args.agent_id}/core-memory/blocks/attach/${args.block_id}`;
    
            // Send an empty object as the request body
            await server.api.patch(attachUrl, {}, { headers });
    
            // Get updated agent data to verify attachment
            const agentInfoResponse = await server.api.get(`/agents/${args.agent_id}`, { headers });
            const agentData = agentInfoResponse.data;
            const agentName = agentData.name || 'Unknown';
    
            // Format the response
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            agent_id: args.agent_id,
                            agent_name: agentName,
                            block_id: args.block_id,
                            block_name: blockName,
                            label: label,
                        }),
                    },
                ],
            };
        } catch (error) {
            server.createErrorResponse(error);
        }
    }
  • The tool definition including name, description, and inputSchema for validation of attach_memory_block tool parameters.
    export const attachMemoryBlockToolDefinition = {
        name: 'attach_memory_block',
        description:
            'Attach a memory block to an agent. Use list_memory_blocks to find blocks, create_memory_block to make new ones. Common labels: "persona", "human", "system".',
        inputSchema: {
            type: 'object',
            properties: {
                block_id: {
                    type: 'string',
                    description: 'The ID of the memory block to attach',
                },
                agent_id: {
                    type: 'string',
                    description: 'The ID of the agent to attach the memory block to',
                },
                label: {
                    type: 'string',
                    description:
                        'Optional label for the memory block (e.g., "persona", "human", "system")',
                },
            },
            required: ['block_id', 'agent_id'],
        },
    };
  • Import of the handler and tool definition for attach_memory_block.
    import {
        handleAttachMemoryBlock,
        attachMemoryBlockToolDefinition,
    } from './memory/attach-memory-block.js';
  • Dispatch case in the central tool handler switch statement that routes calls to attach_memory_block to its handler.
    case 'attach_memory_block':
        return handleAttachMemoryBlock(server, request.params.arguments);
  • Inclusion of the tool definition in the allTools array used for listing available tools via ListToolsRequestSchema.
    attachMemoryBlockToolDefinition,
Behavior3/5

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

The description adds value by mentioning common labels, which provides context beyond the input schema. However, with no annotations provided, it doesn't disclose critical behavioral traits such as whether this operation is read-only, destructive, requires specific permissions, or has rate limits. The description doesn't contradict annotations (none exist), but it fails to fully compensate for the lack of structured behavioral hints.

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 efficiently structured in two sentences: the first states the core purpose, and the second provides practical usage tips and examples. Every sentence adds value without redundancy, making it appropriately concise and front-loaded for quick understanding.

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 the tool has an output schema (not provided in context but indicated as present), the description doesn't need to explain return values. It covers the basic purpose, usage context, and parameter hints adequately. However, for a mutation tool with no annotations, it could benefit from more behavioral details (e.g., idempotency, error cases) to be fully complete, though the presence of an output schema mitigates some gaps.

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?

The input schema has 100% description coverage, with clear documentation for all three parameters (block_id, agent_id, label). The description adds minimal value by reinforcing the label parameter with examples ('persona', 'human', 'system'), but doesn't provide additional semantic context beyond what's already in the schema. This meets the baseline of 3 for high schema coverage.

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

Purpose4/5

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

The description clearly states the action ('Attach') and resource ('memory block to an agent'), making the purpose understandable. However, it doesn't explicitly differentiate this tool from similar siblings like 'attach_tool' or 'bulk_attach_tool_to_agents', which would require more specific context about what makes memory block attachment distinct from tool attachment.

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

Usage Guidelines4/5

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

The description provides helpful context by mentioning 'list_memory_blocks to find blocks' and 'create_memory_block to make new ones', which guides users on prerequisites. It also suggests common labels like 'persona', 'human', 'system'. However, it doesn't explicitly state when to use this tool versus alternatives like 'attach_tool' or clarify if it's for single vs. bulk operations compared to 'bulk_attach_tool_to_agents'.

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