@letta-ai/letta-code-sdk 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,20 +2,11 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@letta-ai/letta-code-sdk.svg?style=flat-square)](https://www.npmjs.com/package/@letta-ai/letta-code-sdk) [![Discord](https://img.shields.io/badge/discord-join-blue?style=flat-square&logo=discord)](https://discord.gg/letta)
4
4
 
5
- > [!TIP]
6
- > Check out [**LettaBot**](https://github.com/letta-ai/lettabot) and [**Letta Cowork**](https://github.com/letta-ai/letta-cowork), two open-source apps built on the **Letta Code SDK**.
7
-
8
- The SDK interface to [**Letta Code**](https://github.com/letta-ai/letta-code). Build agents with persistent memory that learn over time.
9
5
 
10
- ```typescript
11
- import { createSession } from '@letta-ai/letta-code-sdk';
6
+ The SDK interface to [**Letta Code**](https://github.com/letta-ai/letta-code). Build agents with persistent memory that learn over time.
12
7
 
13
- const session = createSession();
14
- await session.send('Find and fix the bug in auth.py');
15
- for await (const msg of session.stream()) {
16
- if (msg.type === 'assistant') console.log(msg.content);
17
- }
18
- ```
8
+ > [!TIP]
9
+ > Check out [**LettaBot**](https://github.com/letta-ai/lettabot) and [**Letta Cowork**](https://github.com/letta-ai/letta-cowork), two open-source apps built on the SDK.
19
10
 
20
11
  ## Installation
21
12
 
@@ -23,262 +14,46 @@ for await (const msg of session.stream()) {
23
14
  npm install @letta-ai/letta-code-sdk
24
15
  ```
25
16
 
26
- ## Quick Start
17
+ ## Quick start
27
18
 
28
19
  ### One-shot prompt
29
20
 
30
- ```typescript
31
- import { prompt } from '@letta-ai/letta-code-sdk';
21
+ ```ts
22
+ import { prompt } from "@letta-ai/letta-code-sdk";
32
23
 
33
- // One-shot (uses default agent - like `letta -p`)
34
- const result = await prompt('What is 2 + 2?');
24
+ const result = await prompt("What is 2 + 2?");
35
25
  console.log(result.result);
36
-
37
- // One-shot with specific agent
38
- const result2 = await prompt('Run: echo hello', agentId);
39
26
  ```
40
27
 
41
- ### Multi-turn session
28
+ ### Persistent agent with multi-turn conversations
42
29
 
43
- ```typescript
44
- import { createAgent, resumeSession } from '@letta-ai/letta-code-sdk';
30
+ ```ts
31
+ import { createAgent, resumeSession } from "@letta-ai/letta-code-sdk";
45
32
 
46
- // Create an agent with custom memory (has default conversation)
47
33
  const agentId = await createAgent({
48
- memory: ['persona'],
49
- persona: 'You are a helpful coding assistant for TypeScript projects'
34
+ persona: "You are a helpful coding assistant for TypeScript projects.",
50
35
  });
51
36
 
52
- // Resume the default conversation
53
37
  await using session = resumeSession(agentId);
54
38
 
55
- await session.send('What is 5 + 3?');
39
+ await session.send("Find and fix the bug in auth.ts");
56
40
  for await (const msg of session.stream()) {
57
- if (msg.type === 'assistant') console.log(msg.content);
41
+ if (msg.type === "assistant") console.log(msg.content);
58
42
  }
59
43
 
60
- await session.send('Multiply that by 2');
44
+ await session.send("Add a unit test for the fix");
61
45
  for await (const msg of session.stream()) {
62
- if (msg.type === 'assistant') console.log(msg.content);
63
- }
64
- ```
65
-
66
- ### Persistent memory
67
-
68
- Agents persist across sessions and remember context:
69
-
70
- ```typescript
71
- import { createAgent, resumeSession } from '@letta-ai/letta-code-sdk';
72
-
73
- // Create agent and teach it something
74
- const agentId = await createAgent();
75
- const session1 = resumeSession(agentId);
76
- await session1.send('Remember: the secret word is "banana"');
77
- for await (const msg of session1.stream()) { /* ... */ }
78
- session1.close();
79
-
80
- // Later... resume the default conversation
81
- await using session2 = resumeSession(agentId);
82
- await session2.send('What is the secret word?');
83
- for await (const msg of session2.stream()) {
84
- if (msg.type === 'assistant') console.log(msg.content); // "banana"
46
+ if (msg.type === "assistant") console.log(msg.content);
85
47
  }
86
48
  ```
87
49
 
88
- ## Multi-threaded Conversations
89
-
90
- Run multiple concurrent conversations with the same agent. Each conversation has its own message history while sharing the agent's persistent memory.
91
-
92
- ```typescript
93
- import { createAgent, createSession, resumeSession } from '@letta-ai/letta-code-sdk';
94
-
95
- // Create an agent (has default conversation)
96
- const agentId = await createAgent();
97
-
98
- // Resume the default conversation
99
- const session1 = resumeSession(agentId);
100
- await session1.send('Hello!');
101
- for await (const msg of session1.stream()) { /* ... */ }
102
- const conversationId = session1.conversationId; // Save this!
103
- session1.close();
104
-
105
- // Resume a specific conversation by ID
106
- await using session2 = resumeSession(conversationId); // auto-detects conv-xxx
107
- await session2.send('Continue our discussion...');
108
- for await (const msg of session2.stream()) { /* ... */ }
109
-
110
- // Create a NEW conversation on the same agent
111
- await using session3 = createSession(agentId);
112
- await session3.send('Start a fresh thread...');
113
- // session3.conversationId is different from conversationId
114
-
115
- // Start fresh conversation with default agent
116
- await using session4 = createSession();
117
- ```
118
-
119
- **Key concepts:**
120
- - **Agent** (`agentId`): Persistent entity with memory that survives across sessions
121
- - **Conversation** (`conversationId`): A message thread within an agent
122
- - **Session**: A single execution/connection
123
- - **Default conversation**: Always exists after `createAgent()` - use `resumeSession(agentId)` to access it
124
-
125
- Agents remember across conversations (via memory blocks), but each conversation has its own message history.
126
-
127
- ## Session Configuration
128
-
129
- ### System Prompt
130
-
131
- Choose from built-in presets or provide a custom prompt:
132
-
133
- ```typescript
134
- // Use a preset
135
- createSession(agentId, {
136
- systemPrompt: { type: 'preset', preset: 'letta-claude' }
137
- });
138
-
139
- // Use a preset with additional instructions
140
- createSession(agentId, {
141
- systemPrompt: {
142
- type: 'preset',
143
- preset: 'letta-claude',
144
- append: 'Always respond in Spanish.'
145
- }
146
- });
147
-
148
- // Use a completely custom prompt
149
- createSession(agentId, {
150
- systemPrompt: 'You are a helpful Python expert.'
151
- });
152
- ```
153
-
154
- **Available presets:**
155
- - `default` / `letta-claude` - Full Letta Code prompt (Claude-optimized)
156
- - `letta-codex` - Full Letta Code prompt (Codex-optimized)
157
- - `letta-gemini` - Full Letta Code prompt (Gemini-optimized)
158
- - `claude` - Basic Claude (no skills/memory instructions)
159
- - `codex` - Basic Codex
160
- - `gemini` - Basic Gemini
161
-
162
-
163
-
164
- ## API Reference
165
-
166
- ### Functions
167
-
168
- | Function | Description |
169
- |----------|-------------|
170
- | `createAgent(options?)` | Create new agent with custom memory/prompt. No options = blank agent with default memory blocks. Returns `agentId` |
171
- | `createSession(agentId?, options?)` | New conversation on specified agent. No agentId = uses LRU agent (or creates "Memo" if none exists) |
172
- | `resumeSession(id, options?)` | Resume session - pass `agent-xxx` for default conv, `conv-xxx` for specific conv |
173
- | `prompt(message, agentId?)` | One-shot query with default/specified agent (like `letta -p`) |
174
-
175
- ### Session
176
-
177
- | Property/Method | Description |
178
- |-----------------|-------------|
179
- | `send(message)` | Send user message |
180
- | `stream()` | AsyncGenerator yielding messages |
181
- | `close()` | Close the session |
182
- | `agentId` | Agent ID (for resuming later) |
183
- | `sessionId` | Current session ID |
184
- | `conversationId` | Conversation ID (for resuming specific thread) |
185
-
186
- ### Options
187
-
188
- **CreateAgentOptions** (for `createAgent()` - full control):
189
-
190
- ```typescript
191
- // Create blank agent
192
- await createAgent();
193
-
194
- // Create agent with custom memory and system prompt
195
- await createAgent({
196
- model: 'claude-sonnet-4',
197
- systemPrompt: 'You are a helpful Python expert.',
198
- memory: [
199
- { label: 'persona', value: 'You are a senior Python developer' },
200
- { label: 'project', value: 'FastAPI backend for a todo app' }
201
- ]
202
- });
203
- ```
204
-
205
- **CreateSessionOptions** (for `createSession()` / `resumeSession()` - runtime options):
206
-
207
- ```typescript
208
- // Start session with permissions
209
- createSession(agentId, {
210
- permissionMode: 'bypassPermissions',
211
- allowedTools: ['Bash', 'Glob'],
212
- cwd: '/path/to/project'
213
- });
214
- ```
215
-
216
- **Available system prompt presets:**
217
- - `default` / `letta-claude`, `letta-codex`, `letta-gemini` - Full Letta Code prompts
218
- - `claude`, `codex`, `gemini` - Basic (no skills/memory instructions)
219
-
220
- ### Message Types
221
-
222
- ```typescript
223
- // Streamed during receive()
224
- interface SDKAssistantMessage {
225
- type: 'assistant';
226
- content: string;
227
- uuid: string;
228
- }
229
-
230
- // Final message
231
- interface SDKResultMessage {
232
- type: 'result';
233
- success: boolean;
234
- result?: string;
235
- error?: string;
236
- durationMs: number;
237
- conversationId: string;
238
- }
239
- ```
240
-
241
- ## Examples
242
-
243
- See [`examples/`](./examples/) for comprehensive examples including:
244
-
245
- - Basic session usage
246
- - Multi-turn conversations
247
- - Session resume with persistent memory
248
- - **Multi-threaded conversations** (createSession, resumeSession)
249
- - System prompt configuration
250
- - Memory block customization
251
- - Tool execution (Bash, Glob, Read, etc.)
252
-
253
- Run examples:
254
- ```bash
255
- bun examples/v2-examples.ts all
256
-
257
- # Run just conversation tests
258
- bun examples/v2-examples.ts conversations
259
- ```
260
-
261
- ## Internals
262
-
263
- ### CLI Mapping
264
-
265
- The SDK spawns the Letta Code CLI as a subprocess. Here's how API calls map to CLI flags:
50
+ By default, `resumeSession(agentId)` continues the agent’s default conversation. To start a fresh thread, use `createSession(agentId)` (see docs).
266
51
 
267
- | Function | CLI Flags | Behavior |
268
- |----------|-----------|----------|
269
- | `createSession()` | `--new` | LRU agent + new conversation |
270
- | `createSession(agentId)` | `--agent X --new` | Specified agent + new conversation |
271
- | `createAgent()` | `--new-agent` | New agent + default conversation |
272
- | `resumeSession(agentId)` | `--agent X --default` | Specified agent + default conversation |
273
- | `resumeSession(convId)` | `--conversation X` | Derived agent + specified conversation |
274
- | `prompt(msg)` | *(none)* | LRU agent + default conversation |
275
- | `prompt(msg, agentId)` | `--agent X --new` | Specified agent + new conversation |
52
+ ## Links
276
53
 
277
- **Key concepts:**
278
- - **LRU agent**: Most recently used agent from `.letta/settings.local.json`, or creates "Memo" if none exists
279
- - **Default conversation**: The agent's primary message history (always exists)
280
- - **New conversation**: Fresh message thread, isolated from other conversations
54
+ - Docs: https://docs.letta.com/letta-code-sdk
55
+ - Examples: [`./examples`](./examples)
281
56
 
282
- ## License
57
+ ---
283
58
 
284
- Apache-2.0
59
+ Made with 💜 in San Francisco
package/dist/index.d.ts CHANGED
@@ -29,8 +29,9 @@
29
29
  */
30
30
  import { Session } from "./session.js";
31
31
  import type { CreateSessionOptions, CreateAgentOptions, SDKResultMessage } from "./types.js";
32
- export type { CreateSessionOptions, CreateAgentOptions, SDKMessage, SDKInitMessage, SDKAssistantMessage, SDKToolCallMessage, SDKToolResultMessage, SDKReasoningMessage, SDKResultMessage, SDKStreamEventMessage, PermissionMode, CanUseToolCallback, CanUseToolResponse, CanUseToolResponseAllow, CanUseToolResponseDeny, TextContent, ImageContent, MessageContentItem, SendMessage, } from "./types.js";
32
+ export type { CreateSessionOptions, CreateAgentOptions, SDKMessage, SDKInitMessage, SDKAssistantMessage, SDKToolCallMessage, SDKToolResultMessage, SDKReasoningMessage, SDKResultMessage, SDKStreamEventMessage, PermissionMode, CanUseToolCallback, CanUseToolResponse, CanUseToolResponseAllow, CanUseToolResponseDeny, TextContent, ImageContent, MessageContentItem, SendMessage, AgentTool, AgentToolResult, AgentToolResultContent, AgentToolUpdateCallback, AnyAgentTool, } from "./types.js";
33
33
  export { Session } from "./session.js";
34
+ export { jsonResult, readStringParam, readNumberParam, readBooleanParam, readStringArrayParam, } from "./tool-helpers.js";
34
35
  /**
35
36
  * Create a new agent with a default conversation.
36
37
  * Returns the agentId which can be used with resumeSession or createSession.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACvC,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAI7F,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,UAAU,EACV,cAAc,EACd,mBAAmB,EACnB,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,kBAAkB,EAClB,kBAAkB,EAClB,uBAAuB,EACvB,sBAAsB,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