Skip to content

SDK API Reference

Fresh

Source: Letta Code SDK

Core Functions

prompt(message, agentId?)

One-shot query for immediate responses without persistence.

typescript
import { prompt } from '@letta-ai/letta-code-sdk';

// Simple query
const result = await prompt('What is this codebase about?');

// Query with specific agent
const result = await prompt('Summarize recent changes', 'agent-123');
ParameterTypeRequiredDescription
messagestringYesThe query to send
agentIdstringNoTarget a specific agent

Returns: Promise<string> - The agent's response


createAgent(options?)

Create a persistent agent with optional configuration.

typescript
import { createAgent } from '@letta-ai/letta-code-sdk';

const session = await createAgent({
  memoryBlocks: [
    { label: 'persona', value: 'You are a code reviewer.' },
    { label: 'human', value: 'Prefers concise feedback.' }
  ],
  systemPrompt: 'letta-claude',
  model: 'claude-opus-4-7'
});

Options

OptionTypeDescription
memoryBlocksArray<{label, value}> or 'preset'Initial memory configuration
systemPromptstringCustom prompt or preset name
modelstringModel identifier
embeddingstringEmbedding model for memory search

Returns: Promise<Session> - An active session connected to the new agent


createSession(agentId?, options?)

Start a new conversation thread with an agent.

typescript
import { createSession } from '@letta-ai/letta-code-sdk';

const session = await createSession('agent-123', {
  permissionMode: 'plan',
  allowedTools: ['Read', 'Glob', 'Grep']
});
ParameterTypeRequiredDescription
agentIdstringNoTarget agent (creates new if omitted)
optionsSessionOptionsNoRuntime configuration

resumeSession(id, options?)

Reconnect to an agent's default conversation or a specific conversation.

typescript
import { resumeSession } from '@letta-ai/letta-code-sdk';

// Resume default conversation
const session = await resumeSession('agent-123');

// Resume specific conversation
const session = await resumeSession('conversation-456');

Session Interface

Properties (Read-Only)

PropertyTypeDescription
agentIdstringThe agent's unique identifier
conversationIdstringCurrent conversation identifier
sessionIdstringThis session's unique identifier

Methods

session.send(message)

Send a message and wait for the complete response.

typescript
const response = await session.send('Review this function for bugs');
console.log(response);

session.stream(message)

Send a message and receive a streaming response.

typescript
for await (const chunk of session.stream('Explain the architecture')) {
  process.stdout.write(chunk);
}

session.close()

Close the session and persist state.

typescript
await session.close();

Session Runtime Options

OptionTypeDescription
allowedToolsstring[]Whitelist of tools the agent can use
disallowedToolsstring[]Blacklist of tools
permissionModestring'acceptEdits', 'plan', etc.
canUseTool(tool) => booleanCustom permission callback
workingDirectorystringSet the agent's working directory
reflectionbooleanEnable/disable reflection
sleeptimeobjectConfigure sleep/reflection settings
memfsbooleanToggle MemFS for file operations

Type Definitions

typescript
interface MemoryBlock {
  label: string;
  value: string;
}

interface AgentOptions {
  memoryBlocks?: MemoryBlock[] | 'preset';
  systemPrompt?: string;
  model?: string;
  embedding?: string;
}

interface SessionOptions {
  allowedTools?: string[];
  disallowedTools?: string[];
  permissionMode?: string;
  canUseTool?: (tool: string) => boolean;
  workingDirectory?: string;
  reflection?: boolean;
  sleeptime?: SleeptimeConfig;
  memfs?: boolean;
}

interface Session {
  readonly agentId: string;
  readonly conversationId: string;
  readonly sessionId: string;
  send(message: string): Promise<string>;
  stream(message: string): AsyncIterable<string>;
  close(): Promise<void>;
}

Verification Checklist

  • [ ] SDK installed: npm install @letta-ai/letta-code-sdk
  • [ ] prompt() returns responses for one-shot queries
  • [ ] createAgent() creates persistent agents
  • [ ] resumeSession() restores prior context
  • [ ] session.stream() delivers incremental output
  • [ ] session.close() persists state correctly

See Also