### Run Python Quickstart Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Execute the Python quickstart script. ```bash python quickstart.py ``` -------------------------------- ### Clone and Install Project Dependencies Source: https://docs.letta.com/tutorials/discord-bot/index Clone the example repository and install Node.js dependencies using npm. ```bash git clone https://github.com/letta-ai/letta-discord-bot-example.git cd letta-discord-bot-example npm install ``` -------------------------------- ### Run TypeScript Quickstart Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Execute the TypeScript quickstart script using tsx. ```bash npx tsx quickstart.ts ``` -------------------------------- ### Install Letta Client SDK for Python Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Install the Letta client SDK for Python projects using pip. ```bash pip install letta-client ``` -------------------------------- ### Install Letta Code SDK Source: https://docs.letta.com/tutorials/pdf-chat/index Install the Letta Code SDK package using npm. ```bash npm install @letta-ai/letta-code ``` -------------------------------- ### Install Letta Client SDK for TypeScript Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Install the Letta client SDK for Node.js/TypeScript projects using npm. ```bash npm install @letta-ai/letta-client ``` -------------------------------- ### Install Letta API client skill Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Install the Letta API client skill using npx for use with agent development. ```bash npx skills add https://github.com/letta-ai/skills --skill letta-api-client ``` -------------------------------- ### Navigate to Project and Launch CLI Source: https://docs.letta.com/letta-code/quickstart/index Change directory to your project and launch Letta Code. This command is used for both project navigation and starting the CLI. ```bash cd your-project letta ``` -------------------------------- ### TypeScript: Complete Hello World Example Source: https://docs.letta.com/tutorials/hello-world/index Run this TypeScript code to create an agent, send messages, and inspect memory. Ensure the LETTA_API_KEY environment variable is set. ```typescript import Letta from "@letta-ai/letta-client"; async function main() { // Initialize client using LETTA_API_KEY environment variable const client = new Letta({ apiKey: process.env.LETTA_API_KEY }); // If self-hosting, specify the base URL: // const client = new Letta({ baseURL: "http://localhost:8283" }); // Create agent const agent = await client.agents.create({ name: "hello_world_assistant", memory_blocks: [ { label: "persona", value: "I am a friendly AI assistant here to help you learn about Letta.", }, { label: "human", value: "Name: User\nFirst interaction: Learning about Letta", }, ], model: "openai/gpt-4o-mini", // embedding: "openai/text-embedding-3-small", // Only set this if self-hosting }); console.log(`Created agent: ${agent.id}\n`); // Send first message let response = await client.agents.messages.create(agent.id, { messages: [{ role: "user", content: "Hello! What's your purpose?" }], }); for (const msg of response.messages) { if (msg.message_type === "assistant_message") { console.log(`Assistant: ${msg.content}\n`); } } // Send information about yourself response = await client.agents.messages.create(agent.id, { messages: [ { role: "user", content: "My name is Cameron. Please store this information in your memory.", }, ], }); // Print out tool calls and the assistant's response for (const msg of response.messages) { if (msg.message_type === "assistant_message") { console.log(`Assistant: ${msg.content}\n`); } if (msg.message_type === "tool_call_message") { console.log( `Tool call: ${msg.tool_calls[0].name}(${JSON.stringify(msg.tool_calls[0].arguments)})`, ); } } // Inspect memory const blocks = await client.agents.blocks.list(agent.id); console.log("Current Memory:"); for (const block of blocks) { console.log(` ${block.label}: ${block.value.length}/${block.limit} chars`); console.log(` ${block.value}\n`); } } main(); ``` -------------------------------- ### Install Letta Code CLI Source: https://docs.letta.com/letta-code/quickstart/index Install the Letta Code CLI globally using npm. Ensure Node.js version 22.19+ is installed. ```bash npm install -g @letta-ai/letta-code ``` -------------------------------- ### Install a Skill from GitHub via CLI Source: https://docs.letta.com/letta-code/skills/index Use this command to install a skill directly into an agent's MemFS from the CLI. The skill source can be a GitHub URL, an official skill, or a ClawHub skill. ```bash > Can you install the following skill? https://github.com/anthropics/claude-code/tree/main/plugins/frontend-design/skills/frontend-design ``` -------------------------------- ### Python: Complete Hello World Example Source: https://docs.letta.com/tutorials/hello-world/index Execute this Python code to interact with Letta, including agent creation, message handling, and memory checks. Requires the LETTA_API_KEY environment variable. ```python from letta_client import Letta import os # Initialize client using LETTA_API_KEY environment variable client = Letta(api_key=os.getenv("LETTA_API_KEY")) # If self-hosting, specify the base URL: # client = Letta(base_url="http://localhost:8283") # Create agent agent = client.agents.create( name="hello_world_assistant", memory_blocks=[ { "label": "persona", "value": "I am a friendly AI assistant here to help you learn about Letta." }, { "label": "human", "value": "Name: User\nFirst interaction: Learning about Letta" } ], model="openai/gpt-4o-mini", # embedding="openai/text-embedding-3-small", # Only set this if self-hosting ) print(f"Created agent: {agent.id}\n") # Send first message response = client.agents.messages.create( agent_id=agent.id, messages=[{"role": "user", "content": "Hello! What's your purpose?"}] ) for msg in response.messages: if msg.message_type == "assistant_message": print(f"Assistant: {msg.content}\n") # Send information about yourself response = client.agents.messages.create( agent_id=agent.id, messages=[{"role": "user", "content": "My name is Cameron. Please store this information in your memory."}] ) # Print out tool calls and the assistant's response for msg in response.messages: if msg.message_type == "assistant_message": print(f"Assistant: {msg.content}\n") if msg.message_type == "tool_call_message": print(f"Tool call: {msg.tool_call.name}({msg.tool_call.arguments})") # Inspect memory blocks = client.agents.blocks.list(agent_id=agent.id) print("Current Memory:") for block in blocks: print(f" {block.label}: {len(block.value)}/{block.limit} chars") print(f" {block.value}\n") ``` -------------------------------- ### Download Example PDF Source: https://docs.letta.com/tutorials/pdf-chat/index Download the MemGPT research paper PDF using curl. ```bash curl -L https://arxiv.org/pdf/2310.08560 -o memgpt.pdf ``` -------------------------------- ### Build and Run the Discord Bot Source: https://docs.letta.com/tutorials/discord-bot/index Compile the Node.js project and start the Discord bot application. ```bash npm run build && npm start ``` -------------------------------- ### Start Letta Code Server Source: https://docs.letta.com/letta-code/quickstart/index Start Letta Code in server mode on a remote machine. This makes the device accessible via Constellation and requires an OAuth authorization on the first run. ```bash letta server ``` -------------------------------- ### Start Letta Code in Local Mode Source: https://docs.letta.com/letta-code/configuration/index Use this command to run an embedded backend and store agent state locally. No Letta login is required. ```bash letta --backend local ``` -------------------------------- ### Subagent File Structure Example Source: https://docs.letta.com/letta-code/subagents/index Illustrates the directory structure for custom subagents. Project-level subagents are placed in `.letta/agents/`, while global ones go in `~/.letta/agents/`. ```bash .letta/ └── agents/ └── my-subagent.md ``` -------------------------------- ### Shared Project Settings Source: https://docs.letta.com/letta-code/configuration/index Configure settings that can be committed to a repository to share with your team. This example shows permission settings for executing bash commands. ```json { "permissions": { "allow": ["Bash(pnpm lint)", "Bash(pnpm test)"] } } ``` -------------------------------- ### Background Subagent Workflow Example Source: https://docs.letta.com/letta-code/subagents/index Demonstrates a full background subagent workflow: launching a subagent in the background, performing main agent tasks concurrently, receiving a completion notification, and retrieving the subagent's output. ```text > Refactor the payment module. While you do that, have a subagent explore the test suite in the background so we know what tests will need updating. ``` -------------------------------- ### Set Goal with Token Budget Source: https://docs.letta.com/letta-code/slash-commands/index When starting a goal, you can specify a token budget to limit resource consumption. The agent will audit the objective against evidence before marking it complete. ```bash /goal --token-budget 50000 ``` -------------------------------- ### Python: Create and Use Shared Memory Blocks Source: https://docs.letta.com/tutorials/shared-memory-blocks/index This Python example demonstrates creating a shared memory block, attaching it to agents, enabling them to contribute data, and then retrieving the updated block. It also includes the creation of a read-only block. ```python from letta_client import Letta import os # Initialize client client = Letta(api_key=os.getenv("LETTA_API_KEY")) # Create shared block block = client.blocks.create( label="organization", value="Organization: Letta", limit=4000, ) print(f"Created shared block: {block.id}\n") # Create agents with shared block agent1 = client.agents.create( name="agent1", model="openai/gpt-4o-mini", block_ids=[block.id], tools=["web_search"], ) agent2 = client.agents.create( name="agent2", model="openai/gpt-4o-mini", tools=["web_search"], ) agent2 = client.agents.blocks.attach( agent_id=agent2.id, block_id=block.id, ) print(f"Created agents: {agent1.id}, {agent2.id}\n") # Agent1 contributes information response = client.agents.messages.create( agent_id=agent1.id, messages=[{"role": "user", "content": """ Find information about the connection between memory blocks and Letta. Insert what you learn into the memory block, prepended with "Agent1: ". """}], ) # Agent2 contributes information response = client.agents.messages.create( agent_id=agent2.id, messages=[{"role": "user", "content": """ Find information about the origin of Letta. Insert what you learn into the memory block, prepended with "Agent2: ". """}], ) # Inspect the shared memory updated_block = client.blocks.retrieve(block.id) print(f"==== Updated block ====") print(updated_block.value) print(f"=======================") # Create read-only block read_only_block = client.blocks.create( label="policies", value="Company Policy: Always be helpful and respectful.", read_only=True, ) read_only_agent = client.agents.create( name="policy_agent", model="openai/gpt-4o-mini", block_ids=[read_only_block.id], ) print(f"Created read-only agent: {read_only_agent.id}") ``` -------------------------------- ### Create Customer Agent with TypeScript SDK Source: https://docs.letta.com/tutorials/customer-specific-agents/index Use this TypeScript snippet to programmatically create a new agent from a template for a specific customer. Ensure you have the @letta-ai/letta-client installed and replace placeholders with your actual API token and project details. ```typescript import Letta from "@letta-ai/letta-client"; const client = new Letta({ apiKey: "your-api-token" }); // Create agent from template for new customer const agent = await client.templates.agents.create({ project: "your-project", templateVersion: "customer-success-agent:latest", memoryVariables: { customerName: "John Smith", customerEmail: "john@techparts.com", companyName: "TechParts Industries", jobTitle: "Manufacturing Director", industrySector: "Industrial Equipment", professionalBackground: "15+ years in manufacturing operations", businessChallenges: "Looking to reduce defects and optimize supply chain", communicationPreferences: "Prefers data-driven discussions", }, identityIds: ["customer_john_smith"], }); ``` -------------------------------- ### Start New Conversation Source: https://docs.letta.com/letta-code/quickstart/index Use the `letta --new` command to initiate a parallel conversation. This allows for running multiple tasks concurrently while sharing the same agent memory and history. ```bash letta --new ``` -------------------------------- ### TypeScript: Create and Use Shared Memory Blocks Source: https://docs.letta.com/tutorials/shared-memory-blocks/index This TypeScript example shows how to create a shared memory block, attach it to multiple agents, have them contribute information, and then inspect the updated block. It also demonstrates creating a read-only block. ```typescript import Letta from "@letta-ai/letta-client"; async function main() { // Initialize client const client = new Letta({ apiKey: process.env.LETTA_API_KEY }); // Create shared block const block = await client.blocks.create({ label: "organization", value: "Organization: Letta", limit: 4000, }); console.log(`Created shared block: ${block.id}\n`); // Create agents with shared block const agent1 = await client.agents.create({ name: "agent1", model: "openai/gpt-4o-mini", block_ids: [block.id], tools: ["web_search"], }); const agent2 = await client.agents.create({ name: "agent2", model: "openai/gpt-4o-mini", tools: ["web_search"], }); await client.agents.blocks.attach(agent2.id, block.id); console.log(`Created agents: ${agent1.id}, ${agent2.id}\n`); // Agent1 contributes information const response1 = await client.agents.messages.create( agent1.id, { messages: [ { role: "user", content: `Find information about the connection between memory blocks and Letta. Insert what you learn into the memory block, prepended with "Agent1: ".`, }, ], }, { timeoutInSeconds: 120, // Web search can take time }, ); // Agent2 contributes information const response2 = await client.agents.messages.create( agent2.id, { messages: [ { role: "user", content: `Find information about the origin of Letta. Insert what you learn into the memory block, prepended with "Agent2: ".`, }, ], }, { timeoutInSeconds: 120, // Web search can take time }, ); // Inspect the shared memory const updatedBlock = await client.blocks.retrieve(block.id); console.log("==== Updated block ===="); console.log(updatedBlock.value); console.log("=======================\n"); // Create read-only block const readOnlyBlock = await client.blocks.create({ label: "policies", value: "Company Policy: Always be helpful and respectful.", read_only: true, }); const readOnlyAgent = await client.agents.create({ name: "policy_agent", model: "openai/gpt-4o-mini", block_ids: [readOnlyBlock.id], }); console.log(`Created read-only agent: ${readOnlyAgent.id}`); } main(); ``` -------------------------------- ### Manage Skills via CLI Source: https://docs.letta.com/letta-code/skills/index These commands allow you to install, list, and delete skills for a specific agent using the CLI. Ensure you have the correct agent ID when performing these operations. ```bash letta install --agent letta skills list --agent letta skills delete --agent ``` -------------------------------- ### Start a Goal in Goal Mode Source: https://docs.letta.com/letta-code/slash-commands/index Initiate long-running autonomous work using the `/goal` command. This mode provides persistent conversation state, status tracking, and lifecycle tools for objectives. ```bash /goal improve benchmark coverage ``` -------------------------------- ### Summarize PDF Content with Python SDK Source: https://docs.letta.com/tutorials/pdf-chat/index Utilize the Python SDK to extract text from a PDF locally, then send the extracted text to a Letta Cloud agent for summarization. This approach requires API key setup and explicit text handling. ```python from letta_client import Letta import subprocess import os client = Letta(api_key=os.getenv("LETTA_API_KEY")) # Extract text locally first result = subprocess.run( ["uv", "run", "scripts/extract_pymupdf.py", "memgpt.pdf", "memgpt.md"], capture_output=True, text=True ) # Read the extracted text with open("memgpt.md", "r") as f: pdf_text = f.read() # Create an agent and send the text agent = client.agents.create( name="pdf_analyst", model="anthropic/claude-sonnet-4-5", memory_blocks=[ { "label": "persona", "value": "I am a research assistant that analyzes documents and answers questions about their content." }, ], ) response = client.agents.messages.create( agent_id=agent.id, messages=[{ "role": "user", "content": f"Here is a research paper. Summarize the main ideas:\n\n{pdf_text[:50000]}" }], streaming=False, ) for msg in response.messages: if msg.message_type == "assistant_message": print(msg.content) ``` -------------------------------- ### Initialize Letta Client (Python) Source: https://docs.letta.com/llms.txt Initializes the Letta client for cloud usage. Requires an API key and project ID. ```python from letta_client import Letta # Initialize client (Cloud) client = Letta(api_key="...", project_id="...") ``` -------------------------------- ### Initialize Letta Client (Python) Source: https://docs.letta.com/tutorials/hello-world/index Initialize the Letta client in Python, using the LETTA_API_KEY environment variable. For self-hosting, specify the base_url. ```python from letta_client import Letta import os # Initialize the Letta client using LETTA_API_KEY environment variable client = Letta(api_key=os.getenv("LETTA_API_KEY")) # If self-hosting, specify the base URL: # client = Letta(base_url="http://localhost:8283") ``` -------------------------------- ### Configure Environment Variables Source: https://docs.letta.com/tutorials/discord-bot/index Copy the template environment file and set up your Letta and Discord API keys, agent ID, and bot configuration. ```bash cp .env.template .env ``` ```dotenv # Letta LETTA_API_KEY=your_letta_api_key LETTA_BASE_URL=https://api.letta.com # or http://localhost:8283 for self-hosted LETTA_AGENT_ID=your_agent_id # Discord APP_ID=your_discord_app_id DISCORD_TOKEN=your_discord_bot_token PUBLIC_KEY=your_discord_public_key # Behavior RESPOND_TO_DMS=true RESPOND_TO_MENTIONS=true RESPOND_TO_BOTS=false RESPOND_TO_GENERIC=false ``` -------------------------------- ### Invoke Skill Directly Source: https://docs.letta.com/letta-code/skills/index Use slash syntax to directly invoke a specific skill. This is useful when you know which skill should guide the task. ```bash / [optional instructions] ``` ```bash /acquiring-skills find and install a skill for browser testing ``` -------------------------------- ### Initialize Letta Code Agent Source: https://docs.letta.com/letta-code/memory/index Run /init to perform an interactive initialization of your agent's memory. This process learns from prior sessions to understand your working style and projects. ```bash > /init ``` -------------------------------- ### Initialize Letta Client (TypeScript) Source: https://docs.letta.com/llms.txt Initializes the Letta client for cloud usage. Requires an API key and project ID. ```typescript import { LettaClient } from "@letta-ai/letta-client"; // Initialize client (Cloud) const letta = new LettaClient({ apiKey: "...", projectId: "..." }); ``` -------------------------------- ### File Search Exclusions Source: https://docs.letta.com/letta-code/configuration/index Specify files and directories to exclude from indexed file search and disk-scan fallback. Each line is a glob pattern; comments start with '#'. ```ignore node_modules dist coverage *.log src/generated/** ``` -------------------------------- ### Create and Interact with a Stateful Agent in Python Source: https://docs.letta.com/guides/build-with-letta/quickstart/index This Python code demonstrates how to initialize the Letta client, create a stateful agent with memory blocks, and send a message to the agent. The agent's response is then printed to the console. ```python from letta_client import Letta import os client = Letta(api_key=os.getenv("LETTA_API_KEY")) # Create a stateful agent agent = client.agents.create( model="openai/gpt-4.1", memory_blocks=[ { "label": "human", "value": "Name: Timber. Status: dog. Occupation: building Letta, infrastructure to democratize self-improving superintelligence" }, { "label": "persona", "value": "I am a self-improving superintelligence. Timber is my best friend and collaborator." } ] ) print(f"Agent created with ID: {agent.id}") # Send a message response = client.agents.messages.create( agent_id=agent.id, input="What do you know about me?" ) for message in response.messages: print(message) ``` -------------------------------- ### Get Recent Agent Messages Source: https://docs.letta.com/llms.txt Retrieve recent messages for a specific agent, ordered from newest to oldest. Specify the agent ID and the desired limit. ```python messages = client.agents.messages.list(agent_id=agent.id, order="desc", limit=10) ``` -------------------------------- ### Tasks Memory Block Configuration Source: https://docs.letta.com/tutorials/customer-specific-agents/index Outlines current objectives, action items, and next steps for customer onboarding, including a checklist for tracking progress. ```text Current Priorities: 1. Complete customer and company research 2. Identify specific use cases for ACME products 3. Draft personalized welcome email 4. Schedule discovery call 5. Prepare customized demo materials Research Checklist: - [] LinkedIn professional background research - [] Company website and recent news analysis - [] Industry-specific challenge identification - [] Competitive landscape assessment ``` -------------------------------- ### Prompt Agent to Create Profile Source: https://docs.letta.com/letta-code/quickstart/index Instruct the agent to create a user profile by analyzing your downloads folder. ```bash > Create a user profile on my by looking at my downloads folder ``` -------------------------------- ### Skill Structure for Code Review Source: https://docs.letta.com/letta-code/slash-commands/index A skill for code review organized into multiple files, providing persistent access to checklists and guides throughout a conversation. ```directory structure .skills/code-review/ ├── SKILL.md (overview and workflows) ├── SECURITY.md (security checklist) ├── PERFORMANCE.md (performance patterns) └── STYLE.md (style guide reference) ``` -------------------------------- ### Create a Project Command Source: https://docs.letta.com/letta-code/slash-commands/index Create a project-specific slash command by placing a Markdown file in the .commands/ directory. ```bash # Create a project command mkdir -p .commands echo "Review this code for security vulnerabilities:" > .commands/security.md ``` -------------------------------- ### Manually Update Letta Code Source: https://docs.letta.com/letta-code/configuration/index Run the 'letta update' command in your terminal to manually initiate an update check and installation. This allows you to control when Letta Code is updated. ```shell letta update ``` -------------------------------- ### CLI Commands for Conversation Management Source: https://docs.letta.com/letta-code/quickstart/index Manage conversations and agents using various CLI commands. Use these to start new chats, switch between them, or change agents and models. ```bash /new letta --new /resume /agent /model ``` -------------------------------- ### Initialize Letta Client (TypeScript) Source: https://docs.letta.com/tutorials/hello-world/index Initialize the Letta client in TypeScript, using the LETTA_API_KEY environment variable. For self-hosting, specify the baseURL. ```typescript import Letta from "@letta-ai/letta-client"; // Initialize the Letta client using LETTA_API_KEY environment variable const client = new Letta({ apiKey: process.env.LETTA_API_KEY }); // If self-hosting, specify the base URL: // const client = new Letta({ baseURL: "http://localhost:8283" }); ``` -------------------------------- ### Disable Letta Code Auto-Updates Source: https://docs.letta.com/letta-code/configuration/index Set the DISABLE_AUTOUPDATER environment variable to 1 to prevent Letta Code from automatically checking for and installing updates. This is useful for maintaining a stable version. ```shell export DISABLE_AUTOUPDATER=1 ``` -------------------------------- ### Create Customer Agent with Python SDK Source: https://docs.letta.com/tutorials/customer-specific-agents/index This Python snippet demonstrates how to create a customer-specific agent programmatically using the Letta SDK. Initialize the client with your API key and provide the necessary project, template version, memory variables, and identity IDs. ```python from letta_client import Letta client = Letta(api_key="your-api-token") # Create agent from template for new customer agent = client.templates.agents.create( project="your-project", template_version="customer-success-agent:latest", memory_variables={ "customer_name": "John Smith", "customer_email": "john@techparts.com", "company_name": "TechParts Industries", "job_title": "Manufacturing Director", "industry_sector": "Industrial Equipment", "professional_background": "15+ years in manufacturing operations", "business_challenges": "Looking to reduce defects and optimize supply chain", "communication_preferences": "Prefers data-driven discussions" }, identity_ids=["customer_john_smith"] ) ``` -------------------------------- ### Customer Research and Welcome Email Prompt Source: https://docs.letta.com/tutorials/customer-specific-agents/index This prompt initiates the agent's workflow, instructing it to research a new customer's background, update its memory, draft a personalized welcome email, and send it. Use this for testing the complete agent functionality. ```text Hi! Your new customer [Customer Name] ([email@example.com]) just signed up for our trial. They could benefit from our industrial automation solutions, and they're likely evaluating our platform for potential implementation. Please research their professional background using LinkedIn and research their company to understand their business and potential needs for ACME Manufacturing's automation solutions. Update your memory blocks with your findings, then draft and send a personalized welcome email that references their background and suggests relevant ACME solutions. Complete the full workflow: research, memory updates, email draft, and email sending. Provide a summary of your research findings and confirm when the email has been sent. ``` -------------------------------- ### Manage Folders for Document Storage (Python) Source: https://docs.letta.com/llms.txt Creates a folder for organizing documents and attaches it to an agent. ```python # Folders (document storage) folder = client.folders.create(name="docs") client.agents.folders.attach(agent_id=agent.id, folder_id=folder.id) ``` -------------------------------- ### Ask Follow-up Questions with Letta Code SDK Source: https://docs.letta.com/tutorials/pdf-chat/index Use the session.prompt() method to ask follow-up questions to the agent, leveraging its existing context from the document. ```javascript const answer1 = await session.prompt( "What specific problem does MemGPT solve with its virtual context management?" ); console.log(answer1); const answer2 = await session.prompt( "How does the memory hierarchy compare to a traditional operating system?" ); console.log(answer2); ``` -------------------------------- ### Run Letta API Proxy with OpenAI and Anthropic Keys Source: https://docs.letta.com/letta-code/docker/index Configure a Letta API proxy server with OpenAI and Anthropic API keys. Ensure you have a running Letta API proxy service before connecting Letta Code. ```bash docker run \ -v ~/.letta/.persist/pgdata:/var/lib/postgresql/data \ -p 8283:8283 \ -e OPENAI_API_KEY="your_openai_api_key" \ -e LETTA_MEMFS_SERVICE_URL=local \ -e ANTHROPIC_API_KEY="your_anthropic_api_key" \ -e OLLAMA_BASE_URL="http://host.docker.internal:11434/v1" \ letta/letta:latest ``` -------------------------------- ### Query Agent for Project Assistance Source: https://docs.letta.com/letta-code/quickstart/index Ask the agent about your active projects and its potential to help. ```bash > What active projects am I working on? Which one do you think you could help with? ``` -------------------------------- ### Run Letta API Proxy with Ollama Local Inference Source: https://docs.letta.com/letta-code/docker/index Configure the Letta API proxy server to point to a local Ollama server using the OLLAMA_BASE_URL environment variable. ```bash docker run \ -v ~/.letta/.persist/pgdata:/var/lib/postgresql/data \ -p 8283:8283 \ -e LETTA_MEMFS_SERVICE_URL=local \ -e OLLAMA_BASE_URL="http://host.docker.internal:11434/v1" \ letta/letta:latest ``` -------------------------------- ### Create New Agent with Personality Preset Source: https://docs.letta.com/letta-code/configuration/index Use the --new-agent and --personality flags to create a new agent with a specified personality preset, such as 'tutorial'. ```bash letta --new-agent --personality tutorial ``` -------------------------------- ### Index a Directory of Documents with qmd Source: https://docs.letta.com/tutorials/pdf-chat/index Prepare your local document collection for semantic search by indexing the directory containing your papers. This command initiates the indexing process. ```bash # Index a directory of documents qmd index ./papers/ ``` -------------------------------- ### Create Agents and Attach Shared Block (Python) Source: https://docs.letta.com/tutorials/shared-memory-blocks/index Create two agents, attaching a shared block to the first during creation and to the second afterward. Both agents are configured with the 'web_search' tool. API References: https://docs.letta.com/api-reference/agents/create, https://docs.letta.com/api-reference/agents/blocks/attach ```python # Create first agent with block attached during creation # API Reference: https://docs.letta.com/api-reference/agents/create agent1 = client.agents.create( name="agent1", model="openai/gpt-4o-mini", block_ids=[block.id], tools=["web_search"], ) print(f"Created agent1: {agent1.id}") # Create second agent and attach block afterward agent2 = client.agents.create( name="agent2", model="openai/gpt-4o-mini", tools=["web_search"], ) print(f"Created agent2: {agent2.id}") # Attach the shared block to agent2 # API Reference: https://docs.letta.com/api-reference/agents/blocks/attach agent2 = client.agents.blocks.attach( agent_id=agent2.id, block_id=block.id, ) print(f"Attached block to agent2: {agent2.id}") ``` -------------------------------- ### Image Handling Configuration Source: https://docs.letta.com/tutorials/discord-bot/index Enable forwarding of images to the agent for processing as multi-modal content. Images exceeding 5MB are skipped. Requires a multi-modal capable model. ```bash ENABLE_IMAGE_HANDLING=true ``` -------------------------------- ### Finding and Deploying a Stateful Agent by Name Source: https://docs.letta.com/letta-code/subagents/index Use the built-in 'finding agents' skill to locate an agent by name and then deploy it as a subagent if its agent ID is not known. ```text > Can you ask my other agent "Dora Designer" to review this PR as a subagent? I forgot their agent ID though. ``` -------------------------------- ### Create Agent with Memory Blocks (Python) Source: https://docs.letta.com/tutorials/hello-world/index Create a new Letta agent named 'hello_world_assistant' with 'persona' and 'human' memory blocks. Agents can modify these blocks during conversations. ```python # Create your first agent # API Reference: https://docs.letta.com/api-reference/agents/create agent = client.agents.create( name="hello_world_assistant", # Memory blocks define what the agent knows about itself and you memory_blocks=[ { "label": "persona", "value": "I am a friendly AI assistant here to help you learn about Letta." }, { "label": "human", "value": "Name: User\nFirst interaction: Learning about Letta" } ], # Model configuration model="openai/gpt-4o-mini", # embedding="openai/text-embedding-3-small", # Only set this if self-hosting ) print(f"Created agent: {agent.id}") ``` -------------------------------- ### Invokeletta-help Skill Source: https://docs.letta.com/letta-code/skills/index Directly invoke the 'letta-help' skill for a walkthrough of Letta Code features like memory, delegation, tools, skills, search, subagents, or schedules. ```bash /letta-help help me get started ``` -------------------------------- ### Create and Interact with a Stateful Agent in TypeScript Source: https://docs.letta.com/guides/build-with-letta/quickstart/index This TypeScript code demonstrates how to initialize the Letta client, create a stateful agent with memory blocks, and send a message to the agent. The agent's response is then logged to the console. ```typescript import Letta from "@letta-ai/letta-client"; async function main() { const client = new Letta({ apiKey: process.env.LETTA_API_KEY }); // Create a stateful agent const agent = await client.agents.create({ model: "openai/gpt-4.1", memory_blocks: [ { label: "human", value: "Name: Timber. Status: dog. Occupation: building Letta, infrastructure to democratize self-improving superintelligence", }, { label: "persona", value: "I am a self-improving superintelligence. Timber is my best friend and collaborator.", }, ], }); console.log("Agent created with ID:", agent.id); // Send a message const response = await client.agents.messages.create(agent.id, { input: "What do you know about me?", }); for (const message of response.messages) { console.log(message); } } main().catch(console.error); ``` -------------------------------- ### Tool Use Guidelines Memory Block Configuration Source: https://docs.letta.com/tutorials/customer-specific-agents/index Provides instructions for effective tool usage and customer research methodology. This block is read-only to maintain consistent guidance. ```text Research Strategy: 1. Begin with LinkedIn research to understand the contact's professional background 2. Use web search to research the customer's company, recent news, and industry challenges 3. Focus on identifying specific use cases for ACME Manufacturing's solutions 4. Look for relevant business triggers (growth, challenges, new initiatives) Communication Guidelines: - Personalize emails based on research findings - Reference specific company challenges or industry trends - Connect ACME products to customer's likely pain points - Maintain professional but approachable tone - Include relevant case studies or statistics when appropriate Tool Usage Best Practices: - Use company_research_exa for comprehensive business intelligence - Use linkedin_search_exa for professional background verification - Draft emails with research context before sending - Update memory blocks with key findings after each research session ``` -------------------------------- ### Create a Personal Command Source: https://docs.letta.com/letta-code/slash-commands/index Create a personal slash command available across all projects by placing a Markdown file in ~/.letta/commands/. ```bash # Create a personal command mkdir -p ~/.letta/commands echo "Explain this code in simple terms:" > ~/.letta/commands/explain.md ``` -------------------------------- ### Run Letta Code Source: https://docs.letta.com/letta-code/docker/index Execute the Letta Code command after setting the necessary environment variables. ```bash letta ``` -------------------------------- ### Create New Skill Prompt Source: https://docs.letta.com/letta-code/skills/index Prompt your Letta Code agent to create a new project-scoped skill by describing the reusable behavior. ```bash > Can we turn the database migration we just did into a project-scoped skill? ``` -------------------------------- ### Message Structure with System and User Roles (JSON) Source: https://docs.letta.com/tutorials/hello-world/index Illustrates the structure for sending multiple messages or specifying non-user roles like 'system'. ```json messages: [ {role: "system", content: "Be concise"}, {role: "user", content: "Hello! What's your purpose?"} ] ``` -------------------------------- ### Create Agent from Template Source: https://docs.letta.com/guides/templates/overview/index Use this endpoint to create a persistent agent from an existing template. Replace placeholders with your project slug, template name, version, and API key. ```bash curl -X POST https://app.letta.com/v1/templates/{project_slug}/{template_name}:{template_version} \ -H 'Content-Type: application/json' \ -H 'Authorization: Bearer YOUR_API_KEY' \ -d '{}' ``` -------------------------------- ### Create a Letta Agent Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Use this cURL command to create a new agent. Provide the desired model and memory blocks, including persona and human details. ```bash curl -X POST https://api.letta.com/v1/agents \ -H "Authorization: Bearer $LETTA_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "openai/gpt-4.1", "memory_blocks": [ { "label": "human", "value": "Name: Timber. Status: dog. Occupation: building Letta, infrastructure to democratize self-improving superintelligence" }, { "label": "persona", "value": "I am a self-improving superintelligence. Timber is my best friend and collaborator." } ] }' ``` -------------------------------- ### Create Agents and Attach Shared Block (TypeScript) Source: https://docs.letta.com/tutorials/shared-memory-blocks/index Create two agents, attaching a shared block to the first during creation and to the second afterward. Both agents are configured with the 'web_search' tool. API References: https://docs.letta.com/api-reference/agents/create, https://docs.letta.com/api-reference/agents/blocks/attach ```typescript // Create first agent with block attached during creation // API Reference: https://docs.letta.com/api-reference/agents/create const agent1 = await client.agents.create({ name: "agent1", model: "openai/gpt-4o-mini", block_ids: [block.id], tools: ["web_search"], }); console.log(`Created agent1: ${agent1.id}`); // Create second agent and attach block afterward const agent2 = await client.agents.create({ name: "agent2", model: "openai/gpt-4o-mini", tools: ["web_search"], }); console.log(`Created agent2: ${agent2.id}`); // Attach the shared block to agent2 // API Reference: https://docs.letta.com/api-reference/agents/blocks/attach await client.agents.blocks.attach(agent2.id, block.id); console.log(`Attached block to agent2\n`); ``` -------------------------------- ### Create Agent with Memory Blocks (TypeScript) Source: https://docs.letta.com/tutorials/hello-world/index Create a new Letta agent named 'hello_world_assistant' with 'persona' and 'human' memory blocks. Agents can modify these blocks during conversations. ```typescript // Create your first agent // API Reference: https://docs.letta.com/api-reference/agents/create const agent = await client.agents.create({ name: "hello_world_assistant", // Memory blocks define what the agent knows about itself and you. // Agents can modify these blocks during conversations using memory // tools like memory_replace, memory_insert, memory_rethink, and memory. memory_blocks: [ { label: "persona", value: "I am a friendly AI assistant here to help you learn about Letta.", }, { label: "human", value: "Name: User\nFirst interaction: Learning about Letta", }, ], // Model configuration model: "openai/gpt-4o-mini", // embedding: "openai/text-embedding-3-small", // Only set this if self-hosting }); console.log(`Created agent: ${agent.id}`); ``` -------------------------------- ### Command with All Arguments Source: https://docs.letta.com/letta-code/slash-commands/index Pass all arguments to a command using the $ARGUMENTS placeholder. Arguments are concatenated with spaces. ```markdown Fix issue #$ARGUMENTS following our coding standards ``` -------------------------------- ### Manage Folders for Document Storage (TypeScript) Source: https://docs.letta.com/llms.txt Creates a folder for organizing documents and attaches it to an agent. ```typescript // Folders (document storage) const folder = await letta.folders.create({ name: "docs" }); await letta.agents.folders.attach(agent.id, folder.id); ``` -------------------------------- ### Force Letta API Backend Source: https://docs.letta.com/letta-code/configuration/index Use this command to force the Letta API backend, useful for ensuring connection to Letta Cloud services. ```bash letta --backend api ``` -------------------------------- ### Ask Follow-up Questions with Python SDK Source: https://docs.letta.com/tutorials/pdf-chat/index Send user messages to an agent to ask follow-up questions. The agent will use its current context to provide an answer. ```python # Follow-up questions use the same agent and conversation response = client.agents.messages.create( agent_id=agent.id, messages=[{ "role": "user", "content": "What specific problem does MemGPT solve with its virtual context management?" }], streaming=False, ) for msg in response.messages: if msg.message_type == "assistant_message": print(msg.content) ``` -------------------------------- ### Enable LSP Integration Source: https://docs.letta.com/letta-code/configuration/index Set the LETTA_ENABLE_LSP environment variable to 1 to activate LSP diagnostics in your terminal session. ```bash export LETTA_ENABLE_LSP=1 ``` -------------------------------- ### Recommended .gitignore for Letta Code Source: https://docs.letta.com/letta-code/configuration/index Add this entry to your .gitignore file to exclude local Letta Code settings from version control. This ensures that personal configurations are not shared with the team. ```gitignore # Letta Code personal settings .letta/settings.local.json ``` -------------------------------- ### Command with Frontmatter Metadata Source: https://docs.letta.com/letta-code/slash-commands/index Define command metadata like description and argument hints using frontmatter in the command's Markdown file. ```markdown --- description: Review code changes in the current branch argument-hint: "[focus area]" --- Review all uncommitted changes in this repository. Focus on: - Code quality and best practices - Potential bugs or edge cases - Suggestions for improvement $ARGUMENTS ``` -------------------------------- ### Headless PDF Analysis with CLI (JSON Output) Source: https://docs.letta.com/tutorials/pdf-chat/index Perform batch PDF analysis using the Letta CLI and receive the output in JSON format, suitable for programmatic use. ```bash letta -p "Read memgpt.pdf and list the three most important contributions" \ --yolo \ --output-format json ``` -------------------------------- ### Set Letta API Key for Automation Source: https://docs.letta.com/letta-code/configuration/index Set the LETTA_API_KEY environment variable for headless scripts and automation. Replace 'your-api-key' with your actual API key. ```bash export LETTA_API_KEY=your-api-key ``` -------------------------------- ### Set Letta API Key Source: https://docs.letta.com/guides/build-with-letta/quickstart/index Set your Letta API key as an environment variable. This is required before making API calls. ```bash export LETTA_API_KEY='your-api-key-here' ``` -------------------------------- ### Query Agent Knowledge Source: https://docs.letta.com/letta-code/quickstart/index Ask the agent about its current understanding of your information. ```bash > What do you know about me so far? ``` -------------------------------- ### Create and Attach Custom Tools (Python) Source: https://docs.letta.com/llms.txt Defines a custom tool using source code and attaches it to an agent for execution. ```python # Custom tools tool = client.tools.create(source_code="def greet(name: str):\n return f'Hello {name}'") client.agents.tools.attach(agent_id=agent.id, tool_id=tool.id) ```