Letta Code SDK quickstart
Get started with the Letta Code SDK
Installation
Section titled “Installation”npm install @letta-ai/letta-code-sdkQuick start
Section titled “Quick start”One-shot prompt
Section titled “One-shot prompt”import { prompt } from "@letta-ai/letta-code-sdk";
const result = await prompt("What is 2 + 2?");console.log(result.result);Multi-turn session
Section titled “Multi-turn session”import { createAgent, resumeSession } from "@letta-ai/letta-code-sdk";
const agentId = await createAgent();await using session = resumeSession(agentId);
await session.send("What is 5 + 3?");for await (const msg of session.stream()) { if (msg.type === "assistant") console.log(msg.content);}Concepts
Section titled “Concepts”- Agent (
agentId): A persistent entity with memory. - Conversation (
conversationId): A message thread within an agent. - Session: A single execution/connection.
- Default conversation: Always exists after
createAgent(); useresumeSession(agentId).
Configuration
Section titled “Configuration”System prompt
Section titled “System prompt”createSession(agentId, { systemPrompt: { type: "preset", preset: "letta-claude" },});
createSession(agentId, { systemPrompt: { type: "preset", preset: "letta-claude", append: "Always respond in Spanish." },});
createSession(agentId, { systemPrompt: "You are a helpful Python expert.",});Presets:
default/letta-claudeletta-codexletta-geminiclaude,codex,gemini(minimal prompts)
Memory blocks
Section titled “Memory blocks”createSession(agentId, { memory: ["project", "persona"],});
createSession(agentId, { memory: [ { label: "context", value: "API docs for Acme Corp..." }, { label: "rules", value: "Always use TypeScript." }, ],});Tool execution
Section titled “Tool execution”createSession(agentId, { allowedTools: ["Glob", "Bash"], permissionMode: "bypassPermissions", cwd: "/path/to/project",});API reference
Section titled “API reference”Functions
Section titled “Functions”| Function | Description |
|---|---|
createAgent() | Create a new agent with a default conversation |
createSession() | New conversation on default agent |
createSession(agentId) | New conversation on specified agent |
resumeSession(id) | Resume session (pass agent-xxx or conv-xxx) |
prompt(message) | One-shot query with default agent |
prompt(message, agentId) | One-shot query with specific agent |
Session
Section titled “Session”| Property/Method | Description |
|---|---|
send(message) | Send user message |
stream() | Async generator yielding messages |
close() | Close the session |
agentId | Agent ID |
sessionId | Current session ID |
conversationId | Conversation ID |
Options
Section titled “Options”interface SessionOptions { model?: string; systemPrompt?: string | { type: "preset"; preset: string; append?: string }; memory?: Array<string | CreateBlock | { blockId: string }>; persona?: string; human?: string; project?: string; cwd?: string;
allowedTools?: string[]; permissionMode?: "default" | "acceptEdits" | "bypassPermissions"; canUseTool?: (toolName: string, toolInput: object) => Promise<CanUseToolResponse>; maxTurns?: number;}