Appearance
SDK API Reference
FreshSource: 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');| Parameter | Type | Required | Description |
|---|---|---|---|
message | string | Yes | The query to send |
agentId | string | No | Target 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
| Option | Type | Description |
|---|---|---|
memoryBlocks | Array<{label, value}> or 'preset' | Initial memory configuration |
systemPrompt | string | Custom prompt or preset name |
model | string | Model identifier |
embedding | string | Embedding 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']
});| Parameter | Type | Required | Description |
|---|---|---|---|
agentId | string | No | Target agent (creates new if omitted) |
options | SessionOptions | No | Runtime 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)
| Property | Type | Description |
|---|---|---|
agentId | string | The agent's unique identifier |
conversationId | string | Current conversation identifier |
sessionId | string | This 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
| Option | Type | Description |
|---|---|---|
allowedTools | string[] | Whitelist of tools the agent can use |
disallowedTools | string[] | Blacklist of tools |
permissionMode | string | 'acceptEdits', 'plan', etc. |
canUseTool | (tool) => boolean | Custom permission callback |
workingDirectory | string | Set the agent's working directory |
reflection | boolean | Enable/disable reflection |
sleeptime | object | Configure sleep/reflection settings |
memfs | boolean | Toggle 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
- SDK Overview - Getting started with the SDK
- Migration Guide - From Claude Agent SDK
- Agents - Agent configuration details