@letta-ai/letta-code-sdk 0.0.5 → 0.0.7
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 +22 -246
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +421 -26
- package/dist/index.js.map +8 -6
- package/dist/interactiveToolPolicy.d.ts +4 -0
- package/dist/interactiveToolPolicy.d.ts.map +1 -0
- package/dist/session.d.ts +24 -0
- package/dist/session.d.ts.map +1 -1
- package/dist/tool-helpers.d.ts +47 -0
- package/dist/tool-helpers.d.ts.map +1 -0
- package/dist/transport.d.ts +2 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/types.d.ts +78 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@letta-ai/letta-code-sdk) [](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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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,47 @@ for await (const msg of session.stream()) {
|
|
|
23
14
|
npm install @letta-ai/letta-code-sdk
|
|
24
15
|
```
|
|
25
16
|
|
|
26
|
-
## Quick
|
|
17
|
+
## Quick start
|
|
27
18
|
|
|
28
19
|
### One-shot prompt
|
|
29
20
|
|
|
30
|
-
```
|
|
31
|
-
import { prompt } from
|
|
21
|
+
```ts
|
|
22
|
+
import { prompt } from "@letta-ai/letta-code-sdk";
|
|
32
23
|
|
|
33
|
-
|
|
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
|
-
###
|
|
28
|
+
### Persistent agent with multi-turn conversations
|
|
42
29
|
|
|
43
|
-
```
|
|
44
|
-
import { createAgent, resumeSession } from
|
|
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
|
-
|
|
49
|
-
|
|
34
|
+
persona: "You are a helpful coding assistant for TypeScript projects.",
|
|
35
|
+
memfs: true, // Enable git-backed memory filesystem for this new agent
|
|
50
36
|
});
|
|
51
37
|
|
|
52
|
-
// Resume the default conversation
|
|
53
38
|
await using session = resumeSession(agentId);
|
|
54
39
|
|
|
55
|
-
await session.send(
|
|
40
|
+
await session.send("Find and fix the bug in auth.ts");
|
|
56
41
|
for await (const msg of session.stream()) {
|
|
57
|
-
if (msg.type ===
|
|
42
|
+
if (msg.type === "assistant") console.log(msg.content);
|
|
58
43
|
}
|
|
59
44
|
|
|
60
|
-
await session.send(
|
|
45
|
+
await session.send("Add a unit test for the fix");
|
|
61
46
|
for await (const msg of session.stream()) {
|
|
62
|
-
if (msg.type ===
|
|
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"
|
|
47
|
+
if (msg.type === "assistant") console.log(msg.content);
|
|
85
48
|
}
|
|
86
49
|
```
|
|
87
50
|
|
|
88
|
-
|
|
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:
|
|
51
|
+
By default, `resumeSession(agentId)` continues the agent’s default conversation. To start a fresh thread, use `createSession(agentId)` (see docs).
|
|
266
52
|
|
|
267
|
-
|
|
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 |
|
|
53
|
+
## Links
|
|
276
54
|
|
|
277
|
-
|
|
278
|
-
-
|
|
279
|
-
- **Default conversation**: The agent's primary message history (always exists)
|
|
280
|
-
- **New conversation**: Fresh message thread, isolated from other conversations
|
|
55
|
+
- Docs: https://docs.letta.com/letta-code-sdk
|
|
56
|
+
- Examples: [`./examples`](./examples)
|
|
281
57
|
|
|
282
|
-
|
|
58
|
+
---
|
|
283
59
|
|
|
284
|
-
|
|
60
|
+
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.
|
package/dist/index.d.ts.map
CHANGED
|
@@ -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,EAEtB,WAAW,EACX,YAAY,EACZ,kBAAkB,EACl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