Letta (formerly MemGPT)

repository·main·Indexed 12 days ago

https://github.com/letta-ai/letta

A framework for building AI agents with advanced, self-improving long-term memory and custom tools. Letta provides a CLI for local interaction, a TypeScript Agent SDK for application integration, and a Python-based core for managing agent state, memory blocks, and tool execution. It supports multiple LLM providers including OpenAI, Anthropic, Groq, and Ollama, and can be deployed via Docker Compose with PostgreSQL and ClickHouse integration.

Tokens
21K
Snippets
68
Records
87
Agent score
98%

What's inside Letta

  1. Understanding Letta SDK versions (Agent SDK vs V1 SDK)

    main

    Letta provides two different SDK paths:

    1. Agent SDK (Recommended): The modern TypeScript SDK (@letta-ai/letta-agent-sdk) designed for building stateful agents. It supports cloud, local, and self-hosted backends.
    2. V1 SDKs (Legacy): These target the Letta API directly.
      • TypeScript: @letta-ai/letta-client
      • Python: letta-client

    New projects should use the Agent SDK.

  2. Data collection in Letta hosted services vs self-hosted

    main

    The extent of data collection depends on how you use Letta:

    • Self-hosted / Local Backends: If you are running your own model backends, Letta does not collect data on your messages or prompts.
    • Hosted Services (e.g., hosted endpoints, Discord Bot): Letta collects the data used to render these services, which includes message requests and message responses. This data may be used to improve services and train future models.
  3. How Step Completion Webhooks work

    main

    Letta triggers webhooks based on your execution architecture:

    Webhooks are wrapped as Temporal activities (send_step_complete_webhook). This provides:

    • Built-in retry logic and configurable timeouts (Start-to-close: 15s, Schedule-to-close: 30s).
    • Full observability in the Temporal UI.
    • Durability guarantees and activity history.

    2. Without Temporal (Direct Execution)

    Webhooks are called directly from the StepManager service methods (update_step_success_async, update_step_error_async, or update_step_cancelled_async) after the step status is committed to the database.

    Critical Reliability Note

    Webhook failures do not prevent step completion. The step is always marked as complete in the database before the webhook is attempted. If a webhook times out or returns an error, the agent execution continues uninterrupted.

  4. Configure Letta plugins

    main

    Letta uses a plugin system to enable plug-and-play functionality for various components. Plugin configurations are managed within letta.settings.settings using a delimited string format.

    To configure multiple plugins, provide a semicolon-separated (;) list of individual plugin configuration strings. Each string follows the pattern:

    <plugin_name>.<config_name>=<module_path>:<name>

    In the default configuration structure, the top-level keys represent the plugin_name, and the config_name is a nested key under that plugin. The value assigned to the configuration is a reference to a class or function in the format <module_path>:<name>.

    # Example of the configuration string format used in settings
    # Format: <plugin_name>.<config_name>=<module_path>:<name>
    
    plugins_config = "plugin_a.setting_x=path.to.module:function_name;plugin_b.setting_y=path.to.module:class_name"
  5. Opt out of Letta telemetry

    main

    By default, Letta applications collect basic anonymous telemetry data (such as clicks and crashes) to inform the product roadmap. To opt out of this collection, modify your configuration file to include the following setting:

    telemetry_disabled = True

    telemetry_disabled = True
  6. Set up localhost HTTPS for the Letta ADE

    main

    To establish a secure localhost HTTPS connection to the Agent Deployment Environment (ADE), you must use mkcert to generate valid local certificates. Follow these steps:

    1. Install mkcert.
    2. Run mkcert -install to set up the local Certificate Authority.
    3. Start Letta with the environment variable LOCAL_HTTPS=true.
    4. Open the Letta dashboard at https://app.letta.com/development-servers/local/dashboard.
    5. Click "Add remote server" and use https://localhost:8283 as the URL. Leave the password blank unless you have explicitly secured your ADE with a password.
    LOCAL_HTTPS=true letta run
  7. Set up the TS Server for user-defined tool calls

    main

    The TS Server is a skeleton TypeScript application designed to support user-defined tool call functions. It is intended to run inside a Modal container. The architecture consists of three main components:

    • server.ts: A Node process that listens on a Unix socket.
    • entrypoint.ts: A lightweight function that deserializes JSON-encoded input strings into inputs for your user-defined function.
    • user-function.ts: The file where you define your custom logic.

    To set up and run the server locally, follow these steps:

    npm install
    npm run build
    npm run start
  8. Install the Letta Agent SDK

    main

    Use the Letta Agent SDK (TypeScript) to integrate stateful agents into your applications. You can run agents on the Letta cloud (Constellation), locally on your machine, or against a self-hosted App Server.

    npm install @letta-ai/letta-agent-sdk
  9. Configure Step Completion Webhooks

    main

    You can receive webhook notifications whenever an agent step reaches a terminal state (SUCCESS, FAILED, or CANCELLED). To enable this, set the following environment variables in your Letta environment:

    Required

    • STEP_COMPLETE_WEBHOOK: The full URL endpoint that will receive the POST requests.

    Optional

    • STEP_COMPLETE_KEY: A secret string used for authentication. If provided, Letta will include it in the Authorization header as Bearer {key}.

    Usage Example

    export STEP_COMPLETE_WEBHOOK="https://your-app.com/api/webhooks/step-complete"
    export STEP_COMPLETE_KEY="your-secret-webhook-key-12345"
    
    # Start your Letta server
    python -m letta.server
  10. Test Step Completion Webhooks

    main

    To test your webhook integration:

    1. Use a service like webhook.site to generate a unique URL.
    2. Set STEP_COMPLETE_WEBHOOK to that URL.
    3. Set a STEP_COMPLETE_KEY for testing.
    4. Run your tests or an agent to trigger completions.
    # Example using webhook.site
    export STEP_COMPLETE_WEBHOOK="https://webhook.site/your-unique-url"
    export STEP_COMPLETE_KEY="test-key-123"
    
    # Run tests
    python -m pytest apps/core/letta/services/webhook_service_test.py -v
  11. Privacy rights and data requests

    main

    Depending on your location (e.g., GDPR in the EU or specific US state laws like California), you may have rights regarding your personal data, including:

    • Requesting access to, correction of, or deletion of your data.
    • Objecting to or limiting the processing of your data.
    • Requesting data portability.
    • Opting out of the sale or sharing of personal information.

    To exercise these rights, contact Letta via email at contact@charlespacker.com. You will be required to verify your identity (e.g., by contacting from the email address associated with your account) before any data is disclosed or deleted.

  12. Install and use the Letta Code CLI

    main

    To run agents locally in your terminal with advanced memory, skills, and subagents, use the Letta Code CLI. This requires Node.js 22.19+.

    1. Install the CLI globally via npm: npm install -g @letta-ai/letta-code
    2. Launch an agent by running: letta in your terminal.
    npm install -g @letta-ai/letta-code
    letta