Skip to main content
Glama

import_agent

Loads and recreates serialized agent configurations from JSON files into the Letta system for customization and deployment.

Instructions

Import a serialized agent JSON file and recreate the agent in the system. Use export_agent to create the JSON file, then modify_agent or attach_tool to customize the imported agent.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesPath to the agent JSON file to import.
append_copy_suffixNoOptional: If set to True, appends "_copy" to the end of the agent name. Defaults to true.
override_existing_toolsNoOptional: If set to True, existing tools can get their source code overwritten by the uploaded tool definitions. Letta core tools cannot be updated. Defaults to true.
project_idNoOptional: The project ID to associate the uploaded agent with.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameNo
successYes
agent_idYes
warningsNo

Implementation Reference

  • Main handler function that implements the import_agent tool: reads a JSON file, sends it via FormData to /agents/import API endpoint, handles errors, and returns the imported agent state.
    export async function handleImportAgent(server, args) {
        if (!args?.file_path) {
            server.createErrorResponse('Missing required argument: file_path');
        }
    
        const filePath = path.resolve(args.file_path); // Resolve to absolute path
    
        // Check if file exists
        if (!fs.existsSync(filePath)) {
            server.createErrorResponse(`File not found at path: ${filePath}`);
        }
    
        try {
            const headers = server.getApiHeaders();
            // Remove content-type as axios will set it correctly for FormData
            delete headers['Content-Type'];
    
            const form = new FormData();
            form.append('file', fs.createReadStream(filePath), path.basename(filePath));
    
            // Construct query parameters for optional settings
            const params = {};
            if (args.append_copy_suffix !== undefined) {
                params.append_copy_suffix = args.append_copy_suffix;
            }
            if (args.override_existing_tools !== undefined) {
                params.override_existing_tools = args.override_existing_tools;
            }
            if (args.project_id) {
                params.project_id = args.project_id;
            }
    
            // Use the specific endpoint from the OpenAPI spec
            const response = await server.api.post('/agents/import', form, {
                headers: {
                    ...headers,
                    ...form.getHeaders(), // Let FormData set the Content-Type with boundary
                },
                params: params, // Add optional query parameters
            });
    
            const importedAgentState = response.data; // Assuming response.data is the new AgentState object
    
            return {
                content: [
                    {
                        type: 'text',
                        text: JSON.stringify({
                            agent_id: importedAgentState.id,
                            agent: importedAgentState,
                        }),
                    },
                ],
            };
        } catch (error) {
            // Handle potential 422 for validation errors, or other API/file errors
            if (error.response) {
                if (error.response.status === 422) {
                    server.createErrorResponse(
                        `Validation error importing agent from ${args.file_path}: ${JSON.stringify(error.response.data)}`,
                    );
                }
            }
            logger.error('[import_agent] Error:', error.response?.data || error.message);
            server.createErrorResponse(
                `Failed to import agent from ${args.file_path}: ${error.message}`,
            );
        }
    }
  • Tool definition object including name, description, and inputSchema for validation of arguments to import_agent.
    export const importAgentDefinition = {
        name: 'import_agent',
        description:
            'Import a serialized agent JSON file and recreate the agent in the system. Use export_agent to create the JSON file, then modify_agent or attach_tool to customize the imported agent.',
        inputSchema: {
            type: 'object',
            properties: {
                file_path: {
                    type: 'string',
                    description: 'Path to the agent JSON file to import.',
                },
                append_copy_suffix: {
                    type: 'boolean',
                    description:
                        'Optional: If set to True, appends "_copy" to the end of the agent name. Defaults to true.',
                    default: true,
                },
                override_existing_tools: {
                    type: 'boolean',
                    description:
                        'Optional: If set to True, existing tools can get their source code overwritten by the uploaded tool definitions. Letta core tools cannot be updated. Defaults to true.',
                    default: true,
                },
                project_id: {
                    type: 'string',
                    description: 'Optional: The project ID to associate the uploaded agent with.',
                },
            },
            required: ['file_path'],
        },
    };
  • Dispatch registration in the CallToolRequestSchema handler switch statement that routes 'import_agent' calls to the handleImportAgent function.
    case 'import_agent':
        return handleImportAgent(server, request.params.arguments);
  • Inclusion of importAgentDefinition in the allTools array used for ListToolsRequestSchema to expose the tool.
    importAgentDefinition,
  • Import statement that brings in the handler and definition from the implementation file.
    import { handleImportAgent, importAgentDefinition } from './agents/import-agent.js';
Behavior3/5

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

Annotations only provide a title ('Import Agent Configuration'), so the description carries the burden. It describes the core behavior (importing and recreating agents) and hints at customization steps, but lacks details on permissions, error handling, or rate limits. No contradiction with annotations exists.

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 two sentences with zero waste: the first states the purpose, and the second provides usage guidance. It is front-loaded and efficiently structured, with every sentence adding clear value.

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's complexity (importing agents with customization), the description is complete enough with purpose and workflow guidance. Annotations are minimal, but the output schema exists, so return values need not be explained. It could improve by addressing potential errors or constraints.

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 fully documents all parameters. The description does not add any parameter-specific details beyond what the schema provides, such as file format requirements or project context, meeting the baseline for high coverage.

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 ('Import a serialized agent JSON file and recreate the agent in the system') and distinguishes it from sibling tools like 'export_agent', 'modify_agent', and 'attach_tool' by explaining their relationship in the workflow.

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?

It explicitly states when to use this tool ('Use export_agent to create the JSON file, then modify_agent or attach_tool to customize the imported agent'), providing clear workflow context and alternatives for customization, which helps differentiate it from tools like 'create_agent' or 'clone_agent'.

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