Skip to main content

Letta Integration

Deploy Letta memory-enabled agents with RunAgent

Prerequisites


Overview

Letta is a framework for building conversational AI agents with persistent memory and context awareness. RunAgent makes it easy to deploy Letta agents and access them from any programming language while maintaining conversation state.

Installation & Setup

1. Install Letta Server

2. Set Environment Variables

Letta requires API keys for LLM providers. Set them before starting the server:

3. Start Letta Server

The Letta server must be running before deploying RunAgent agents:
The server will start on http://localhost:8283. Keep this terminal window open. Note: If you need to use a different port, you can specify it with:

4. Install Letta Client (Optional)

For Python SDK usage, install the client package:

Quick Start with RunAgent

1. Create a Letta Agent Project

2. Install Dependencies

The generated requirements.txt will include:

3. Configure Environment

Create a .env file in your project directory:

4. Review Configuration

The generated runagent.config.json will be pre-configured for Letta:

Basic Letta Agent

Here’s a simple Letta agent demonstrating conversational capabilities:

Advanced: Letta Agent with Custom Tools

Here’s an example with custom tools (keyword extraction, RAG):

Custom Tool Example: Keyword Extraction


Testing Your Letta Agent

Python Client

JavaScript Client

Streaming Example


Project Structure


Configuration Options

Multiple Entrypoints

You can expose multiple entrypoints for different use cases:

Best Practices

1. Memory Management

  • Use appropriate memory blocks for context
  • Clean up agents after use to prevent memory leaks
  • Consider session-based memory for multi-user scenarios

2. Tool Design

  • Create focused, single-purpose tools
  • Provide clear docstrings for tool functions
  • Handle tool errors gracefully with try-catch blocks
  • Return structured dictionaries from tools

3. Error Handling

  • Always wrap Letta operations in try-catch blocks
  • Return meaningful error messages to users
  • Log errors for debugging purposes

4. Server Management

  • Ensure Letta server is running before deploying agents
  • Use environment variables for server URL configuration
  • Monitor server logs for debugging

5. Agent Cleanup

  • Delete temporary agents after use
  • Implement cleanup in both success and error paths
  • Use context managers for resource management

Common Patterns

Conversational Memory

Use Letta’s memory blocks to maintain context across interactions:

Tool Integration

Register custom tools for specialized functionality:

Session Management

For multi-user scenarios, create agents per session:

Troubleshooting

Common Issues

1. Connection Error: “Cannot connect to Letta server”
  • Solution: Ensure Letta server is running (letta server)
  • Check the server URL in your .env file
  • Verify the server is accessible at http://localhost:8283
2. API Key Error
  • Solution: Set OPENAI_API_KEY in your environment
  • Verify the key is valid and has sufficient credits
  • Check that the key is loaded in the Letta server environment
3. Tool Registration Fails
  • Solution: Ensure tool functions have proper docstrings
  • Check that tool function signatures are compatible with Letta
  • Verify all tool dependencies are installed
4. Memory Persistence Issues
  • Solution: Agents are ephemeral by default in this setup
  • Implement custom session storage if needed
  • Use Letta’s built-in persistence features for production
5. Streaming Not Working
  • Solution: Ensure you’re using create_stream method
  • Check that stream_tokens=True is set
  • Verify the entrypoint is correctly configured for streaming

Debug Tips

Enable verbose logging:
Test Letta server connection:

Performance Optimization

1. Connection Pooling

Reuse Letta client connections when possible:

2. Tool Caching

Register tools once and reuse:

3. Memory Management

Clean up agents promptly:

Next Steps


Additional Resources


🎉 Great work! You’ve learned how to deploy Letta memory-enabled agents with RunAgent. Letta’s conversational memory capabilities combined with RunAgent’s multi-language access create powerful, context-aware AI systems!