@letta-ai/letta-code 0.5.2 → 0.6.1

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.
Files changed (3) hide show
  1. package/README.md +30 -425
  2. package/letta.js +3308 -1546
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -1,451 +1,56 @@
1
- # Letta Code (Research Preview)
1
+ # Letta Code
2
2
 
3
- A self-improving, stateful coding agent that can learn from experience and improve with use.
3
+ [![npm](https://img.shields.io/npm/v/@letta-ai/letta-code.svg?style=flat-square)](https://www.npmjs.com/package/@letta-ai/letta-code) [![Discord](https://img.shields.io/badge/discord-join-blue?style=flat-square&logo=discord)](https://discord.gg/letta)
4
4
 
5
- <img width="1713" height="951" alt="letta-code" src="https://github.com/user-attachments/assets/ae546e96-368a-4a7b-9397-3963a35c8d6b" />
5
+ Letta Code is a memory-first coding harness, built on top of the Letta API. Instead of working in independent sessions, you work with a persisted agent that learns over time and is portable across models (Claude Sonnet/Opus, GPT-5, Gemini 3 Pro, GLM-4.6, and more).
6
6
 
7
- ---
8
-
9
- ## What is Letta Code?
10
-
11
- Letta Code is a command-line harness around the stateful [Letta API](https://docs.letta.com/api-reference/overview). You can use Letta Code to create and connect with any Letta agent (even non-coding agents!) - Letta Code simply gives your agents the ability to interact with your local dev environment, directly in your terminal.
7
+ **Read more about how to use Letta Code on the [official docs page](https://docs.letta.com/letta-code).**
12
8
 
13
- Letta Code is model agnostic, and supports Sonnet 4.5, GPT-5, Gemini 2.5, GLM-4.6, and more.
9
+ ![](https://github.com/letta-ai/letta-code/blob/main/assets/letta-code-demo.gif)
14
10
 
15
- > [!IMPORTANT]
16
- > Letta Code is a **research preview** in active development, and may have bugs or unexpected issues. To learn more about the roadmap and chat with the dev team, visit our [Discord](https://discord.gg/letta). Contributions welcome, join the fun.
11
+ ## Get started
17
12
 
18
- ## Quickstart
19
-
20
- > Get a Letta API key at: [https://app.letta.com](https://app.letta.com/)
13
+ Requirements:
14
+ * [Node.js](https://nodejs.org/en/download) (version 18+)
15
+ * A [Letta Developer Platform](https://app.letta.com/) account (or a [self-hosted Letta server](https://docs.letta.com/letta-code/configuration#self-hosted-server))
21
16
 
22
17
  Install the package via [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm):
23
18
  ```bash
24
19
  npm install -g @letta-ai/letta-code
25
20
  ```
21
+ Navigate to your project directory and run `letta` (see various command-line options [on the docs](https://docs.letta.com/letta-code/commands)):
26
22
 
27
- Set your Letta API key via environment variable:
28
- ```bash
29
- export LETTA_API_KEY=...
30
- ```
31
-
32
- Then run `letta` to start Letta Code (see various command-line options below):
33
- ```
34
- letta
35
- ```
36
-
37
- Any of the agents you create in Letta Code will be viewable (and fully interactable!) inside the [Agent Development Environment](https://app.letta.com).
38
-
39
- ## Persistence
40
-
41
- All agents in Letta are **stateful**: they maintain context forever and can self-edit their own [memory blocks](https://www.letta.com/blog/memory-blocks).
42
-
43
- ### Project-Level Agent Persistence
44
-
45
- **Letta Code automatically remembers the last agent used in each directory.**
46
- When you run `letta` in a project, it resumes where you left off with the same agent.
47
-
48
- **How it works:**
49
- - First time running `letta` in a directory → creates new agent (with shared memory blocks across all Letta Code agents)
50
- - Subsequent runs → automatically resumes that agent
51
- - Agent ID stored in `.letta/settings.local.json` (gitignored, personal to you)
52
-
53
- ```bash
54
- letta # Auto-resumes project agent (or creates new if first time)
55
- letta --new # Create new agent with new memory blocks
56
- letta --agent <id> # Use specific agent ID
57
- ```
58
-
59
- ### Memory Configuration
60
-
61
- Letta Code uses a hierarchical memory system:
62
-
63
- **Global** (`~/.letta/settings.json`)
64
- - API keys and credentials
65
- - `persona` block - defines agent behavior
66
- - `human` block - stores user coding preferences
67
-
68
- **Project** (`./.letta/settings.local.json`)
69
- - Last agent ID for this directory (auto-resumes)
70
- - Gitignored - personal to you, not shared with your team
71
-
72
- **Project Shared** (`./.letta/settings.json`)
73
- - `project` block - stores project-specific context
74
- - Can be committed - shared with team
75
-
76
- Memory blocks are highly configurable — see our [docs](https://docs.letta.com/guides/agents/memory-blocks) for advanced configuration options.
77
- Join our [Discord](https://discord.gg/letta) to share feedback on persistence patterns for coding agents.
78
-
79
- ## Skills
80
-
81
- **Skills are automatically discovered from a `.skills` directory in your project.**
82
-
83
- Skills allow you to define custom capabilities that the agent can reference and use. When you start a new session, Letta Code recursively scans for `SKILL.MD` files and loads any skill definitions found.
84
-
85
- ### Creating Skills
86
-
87
- Create a `.skills` directory in your project root and organize skills in subdirectories:
88
-
89
- ```bash
90
- mkdir -p .skills/data-analysis
91
- ```
92
-
93
- Each skill is defined in a file named `SKILL.MD`. The directory structure determines the skill ID:
94
-
95
- ```
96
- .skills/
97
- ├── data-analysis/
98
- │ └── SKILL.MD # skill id: "data-analysis"
99
- └── web/
100
- └── scraper/
101
- └── SKILL.MD # skill id: "web/scraper"
102
- ```
103
-
104
- Create a skill file (`.skills/data-analysis/SKILL.MD`):
105
-
106
- ```markdown
107
- ---
108
- name: Data Analysis Skill
109
- description: Analyzes CSV files and generates statistical reports
110
- category: Data Processing
111
- tags:
112
- - analytics
113
- - statistics
114
- - csv
115
- ---
116
-
117
- # Data Analysis Skill
118
-
119
- This skill analyzes data files and generates comprehensive reports.
120
-
121
- ## Usage
122
-
123
- Use this skill to analyze CSV files and generate statistical summaries...
124
- ```
125
-
126
- **Skill File Format:**
127
-
128
- - **File name:** Must be named `SKILL.MD` (case-insensitive)
129
- - **Required frontmatter:**
130
- - `name` - Display name for the skill
131
- - `description` - Brief description of what the skill does
132
- - **Optional frontmatter:**
133
- - `category` - Category for organizing skills (skills are grouped by category in the agent's memory)
134
- - `tags` - Array of tags for filtering/searching
135
- - **Body:** Additional details and documentation about the skill
136
-
137
- Skills are automatically loaded into the agent's memory on startup, making them available for reference throughout your session.
138
-
139
- ### Custom Skills Directory
140
-
141
- You can specify a custom skills directory using the `--skills` flag:
142
-
143
- ```bash
144
- letta --skills /path/to/custom/skills
145
- letta -p "Use the custom skills" --skills ~/my-skills
146
- ```
147
-
148
- ## Usage
149
-
150
- ### Interactive Mode
151
- ```bash
152
- letta # Auto-resume project agent (or create new if first time)
153
- letta --new # Create new agent with new memory blocks
154
- letta --agent <id> # Use specific agent ID
155
- letta --model <model> # Specify model (e.g., claude-opus-4.5, claude-sonnet-4.5, gpt-4o)
156
- letta -m <model> # Short form of --model
157
- letta --continue # Resume global last agent (deprecated, use project-based)
158
-
159
- # Managing tools (requires --agent flag)
160
- letta --agent <id> --link # Attach Letta Code tools to agent, then start session
161
- letta --agent <id> --unlink # Remove Letta Code tools from agent, then start session
162
- ```
163
-
164
- > **Note:** The `--model` flag is inconsistent when resuming sessions. We recommend using the `/model` command instead to change models in interactive mode.
165
-
166
- #### Interactive Commands
167
-
168
- While in a session, you can use these commands:
169
-
170
- **Agent Management:**
171
- - `/agent` - Show current agent link
172
- - `/swap` - Switch to a different agent (prompts with agent selector)
173
- - `/rename` - Rename the current agent
174
- - `/download` - Download agent file locally (exports agent configuration as JSON)
175
-
176
- **Configuration:**
177
- - `/model` - Switch models (prompts with model selector)
178
- - `/toolset` - Switch toolsets (codex/default/gemini)
179
- - `/system` - Switch system prompt (change agent behavior preset)
180
- - `/stream` - Toggle token streaming on/off
181
-
182
- **Tools & Memory:**
183
- - `/link` - Attach Letta Code tools to current agent (enables Read, Write, Edit, Bash, etc.)
184
- - `/unlink` - Remove Letta Code tools from current agent
185
- - `/init` - Initialize agent memory for this project (guides agent to organize memory blocks based on current context)
186
-
187
- **Skills:**
188
- - `/skill` - Enter skill creation mode (optionally: `/skill <description>`)
189
-
190
- **Background Processes:**
191
- - `/bashes` - Show background shell processes (displays shells started with `run_in_background=true`)
192
-
193
- **Session Management:**
194
- - `/clear` - Clear conversation history
195
- - `/exit` - Exit and show session stats
196
- - `/logout` - Clear credentials and exit
197
-
198
- #### Background Shell Processes
199
-
200
- When running long-running commands (like dev servers, test watchers, or builds), the agent can use `run_in_background=true` with the Bash tool. Use `/bashes` to view all background processes:
201
-
202
- ```bash
203
- /bashes # Shows running background shells with their IDs and commands
204
- ```
205
-
206
- The agent can monitor background process output using the `BashOutput` tool and terminate them with `KillBash`.
23
+ ## Philosophy
24
+ Letta Code is built around long-lived agents that persist across sessions and improve with use. Rather than working in independent sessions, each session is tied to a persisted agent that learns.
207
25
 
208
- #### Memory Initialization
26
+ **Claude Code / Codex / Gemini CLI** (Session-Based)
27
+ - Sessions are independent
28
+ - No learning between sessions
29
+ - Context = messages in the current session + `AGENTS.md`
30
+ - Relationship: Every conversation is like meeting a new contractor
209
31
 
210
- The `/init` command helps the agent organize its memory blocks based on your project context:
32
+ **Letta Code** (Agent-Based)
33
+ - Same agent across sessions
34
+ - Persistent memory and learning over time
35
+ - `/clear` resets the session (clears current in-context messages), but memory persists
36
+ - Relationship: Like having a coworker or mentee that learns and remembers
211
37
 
38
+ ## Agent Memory & Learning
39
+ If you’re using Letta Code for the first time, you will likely want to run the `/init` command to initialize the agent’s memory system:
212
40
  ```bash
213
- /init # Guides agent to analyze project and structure its memory
41
+ > /init
214
42
  ```
215
43
 
216
- This is useful when:
217
- - Starting fresh in a new project
218
- - Reorganizing an existing agent's memory structure
219
- - After sharing project documentation (like AGENTS.md or README)
220
-
221
- The agent will analyze available context and create/update memory blocks like:
222
- - **`project`** - Build commands, architecture, conventions
223
- - **`human`** - Your coding preferences and communication style
224
- - **`ticket`/`context`** - Current task or debugging context
225
-
226
- See [Memory Configuration](#memory-configuration) for more details on memory blocks.
227
-
228
- #### Skill Creation
229
-
230
- The `/skill` command enters an interactive mode for creating new skills:
231
-
44
+ Over time, the agent will update its memory as it learns. To actively guide your agents memory, you can use the `/remember` command:
232
45
  ```bash
233
- /skill # Enter skill creation mode
234
- /skill "Python testing helper" # Start with a description
46
+ > /remember [optional instructions on what to remember]
235
47
  ```
236
-
237
- Skills are modular packages that extend Letta Code with specialized knowledge or workflows. The agent will guide you through:
238
- 1. Defining the skill's purpose and scope
239
- 2. Creating the skill structure (SKILL.md + optional resources)
240
- 3. Writing effective instructions and bundled scripts
241
- 4. Validating and packaging the skill
242
-
243
- Created skills are saved to your `.skills` directory and automatically discovered on next session.
244
-
245
- #### Managing Letta Code Tools
246
-
247
- Letta Code provides tools like `Bash`, `Read`, `Write`, `Edit`, `Grep`, `Glob`, and more. You can attach or remove these tools from any agent:
248
-
249
- **Via CLI flags** (before starting session):
48
+ Letta Code works with skills (reusable modules that teach your agent new capabilities in a `.skills` directory), but additionally supports [skill learning](https://www.letta.com/blog/skill-learning). You can ask your agent to learn a skill from it's current trajectory with the command:
250
49
  ```bash
251
- letta --agent <id> --link # Attach Letta Code tools
252
- letta --agent <id> --unlink # Remove Letta Code tools
253
- ```
254
-
255
- **Via interactive commands** (during session):
256
- ```bash
257
- /link # Attach Letta Code tools to current agent
258
- /unlink # Remove Letta Code tools from current agent
259
- ```
260
-
261
- When you attach tools with `/link` or `--link`, they are added to the agent with approval rules enabled (human-in-the-loop). This means the agent can use these tools, but you'll be prompted to approve each tool call. Use permission modes to control approval behavior (see Permissions section below).
262
-
263
- ### Toolsets
264
-
265
- Letta Code includes different toolsets optimized for different model providers:
266
-
267
- 1. **Default Toolset** (Anthropic-optimized, best for Claude models)
268
- 2. **Codex Toolset** (OpenAI-optimized, best for GPT models)
269
- 3. **Gemini Toolset** (Google-optimized, best for Gemini models)
270
-
271
- **Automatic Selection:**
272
- When you specify a model, Letta Code automatically selects the appropriate toolset:
273
- ```bash
274
- letta --model haiku # Loads default toolset
275
- letta --model gpt-5-codex # Loads codex toolset
276
- letta --model gemini-3-pro # Loads gemini toolset
277
- ```
278
-
279
- **Manual Override:**
280
- You can force a specific toolset regardless of model:
281
- ```bash
282
- # CLI flag (at startup)
283
- letta --model haiku --toolset codex # Use Codex-style tools with Claude Haiku
284
- letta --model gpt-5-codex --toolset gemini # Use Gemini-style tools with GPT-5-Codex
285
- letta --toolset gemini # Use Gemini tools with default model
286
-
287
- # Interactive command (during session)
288
- /toolset # Opens toolset selector
289
- ```
290
-
291
- The `/model` command automatically switches toolsets when you change models. Use `/toolset` if you want to manually override the automatic selection.
292
-
293
- ### Headless Mode
294
- ```bash
295
- letta -p "Run bun lint and correct errors" # Auto-resumes project agent
296
- letta -p "Pick up where you left off" # Same - auto-resumes by default
297
- letta -p "Start fresh" --new # Create new agent with new memory blocks
298
- letta -p "Run all the test" --allowedTools "Bash" # Control tool permissions
299
- letta -p "Just read the code" --disallowedTools "Bash" # Control tool permissions
300
- letta -p "Explain this code" -m gpt-4o # Use specific model
301
-
302
- # Pipe input from stdin
303
- echo "Explain this code" | letta -p
304
- cat file.txt | letta -p
305
- gh pr diff 123 | letta -p --yolo
306
-
307
- # Output formats
308
- letta -p "Analyze this codebase" --output-format json # Structured JSON at end
309
- letta -p "Analyze this codebase" --output-format stream-json # JSONL stream (one event per line)
310
- ```
311
-
312
- You can also use the `--tools` flag to control the underlying *attachment* of tools (not just the permissions).
313
- Compared to disallowing the tool, this will additionally remove the tool schema from the agent's context window.
314
- ```bash
315
- letta -p "Run all tests" --tools "Bash,Read" # Only load specific tools
316
- letta -p "Just analyze the code" --tools "" # No tools (analysis only)
317
- ```
318
-
319
- Use `--output-format json` to get structured output with metadata:
320
- ```bash
321
- # regular text output
322
- $ letta -p "hi there"
323
- Hi! How can I help you today?
324
-
325
- # structured output (single JSON object at end)
326
- $ letta -p "hi there" --output-format json
327
- {
328
- "type": "result",
329
- "subtype": "success",
330
- "is_error": false,
331
- "duration_ms": 5454,
332
- "duration_api_ms": 2098,
333
- "num_turns": 1,
334
- "result": "Hi! How can I help you today?",
335
- "agent_id": "agent-8ab431ca-63e0-4ca1-ba83-b64d66d95a0f",
336
- "usage": {
337
- "prompt_tokens": 294,
338
- "completion_tokens": 97,
339
- "total_tokens": 391
340
- }
341
- }
50
+ > /skill [optional instructions on what skill to learn]
342
51
  ```
343
52
 
344
- Use `--output-format stream-json` to get streaming outputs, in addition to a final JSON response.
345
- This is useful if you need to have data flowing to prevent automatic timeouts:
346
- ```bash
347
- # streaming JSON output (JSONL - one event per line, token-level streaming)
348
- # Note: Messages are streamed at the token level - each chunk has the same otid and incrementing seqId.
349
- $ letta -p "hi there" --output-format stream-json
350
- {"type":"init","agent_id":"agent-...","model":"claude-sonnet-4-5-20250929","tools":[...]}
351
- {"type":"message","messageType":"reasoning_message","reasoning":"The user is asking","otid":"...","seqId":1}
352
- {"type":"message","messageType":"reasoning_message","reasoning":" me to say hello","otid":"...","seqId":2}
353
- {"type":"message","messageType":"reasoning_message","reasoning":". This is a simple","otid":"...","seqId":3}
354
- {"type":"message","messageType":"reasoning_message","reasoning":" greeting.","otid":"...","seqId":4}
355
- {"type":"message","messageType":"assistant_message","content":"Hi! How can I help you today?","otid":"...","seqId":5}
356
- {"type":"message","messageType":"stop_reason","stopReason":"end_turn"}
357
- {"type":"message","messageType":"usage_statistics","promptTokens":294,"completionTokens":97,"totalTokens":391}
358
- {"type":"result","subtype":"success","result":"Hi! How can I help you today?","agent_id":"agent-...","usage":{...}}
359
- ```
360
-
361
- ### Permissions
362
-
363
- **Tool selection** (controls which tools are loaded):
364
- ```bash
365
- --tools "Bash,Read,Write" # Only load these tools
366
- --tools "" # No tools (conversation only)
367
- ```
368
-
369
- **Permission overrides** (controls tool access, applies to loaded tools):
370
- ```bash
371
- --allowedTools "Bash,Read,Write" # Allow specific tools
372
- --allowedTools "Bash(npm run test:*)" # Allow specific commands
373
- --disallowedTools "Bash(curl:*)" # Block specific patterns
374
- --permission-mode acceptEdits # Auto-allow Write/Edit tools
375
- --permission-mode plan # Read-only mode
376
- --permission-mode bypassPermissions # Allow all tools (use carefully!)
377
- --yolo # Alias for --permission-mode bypassPermissions
378
- ```
379
-
380
- Permission modes:
381
- - `default` - Standard behavior, prompts for approval
382
- - `acceptEdits` - Auto-allows Write/Edit/NotebookEdit
383
- - `plan` - Read-only, allows analysis but blocks modifications
384
- - `bypassPermissions` - Auto-allows all tools (for trusted environments)
385
-
386
- Permissions are also configured in `.letta/settings.json`:
387
- ```json
388
- {
389
- "permissions": {
390
- "allow": ["Bash(npm run lint)", "Read(src/**)"],
391
- "deny": ["Bash(rm -rf:*)", "Read(.env)"]
392
- }
393
- }
394
- ```
395
-
396
- ## Updates
397
-
398
- Letta Code automatically checks for updates on startup and installs them in the background.
399
-
400
- ### Auto updates
401
-
402
- * **Update checks**: Performed on startup
403
- * **Update process**: Downloads and installs automatically in the background
404
- * **Applying updates**: Updates take effect the next time you start Letta Code
405
-
406
- **Disable auto-updates:**
407
- Set the `DISABLE_AUTOUPDATER` environment variable in your shell:
408
- ```bash
409
- export DISABLE_AUTOUPDATER=1
410
- ```
411
-
412
- ### Update manually
413
-
414
- ```bash
415
- letta update
416
- ```
417
-
418
- ## Self-hosting
419
-
420
- To use Letta Code with a self-hosted server, set `LETTA_BASE_URL` to your server IP, e.g. `export LETTA_BASE_URL="http://localhost:8283"`.
421
- See our [self-hosting guide](https://docs.letta.com/guides/selfhosting) for more information.
422
-
423
- ## Installing from source
424
-
425
- First, install Bun if you don't have it yet: [https://bun.com/docs/installation](https://bun.com/docs/installation)
426
-
427
- ### Run directly from source (dev workflow)
428
- ```bash
429
- # install deps
430
- bun install
431
-
432
- # run the CLI from TypeScript sources (pick up changes immediately)
433
- bun run dev
434
- bun run dev -- -p "Hello world" # example with args
435
- ```
436
-
437
- ### Build + link the standalone binary
438
- ```bash
439
- # build bin/letta (includes prompts + schemas)
440
- bun run build
441
-
442
- # expose the binary globally (adjust to your preference)
443
- bun link
444
-
445
- # now you can run the compiled CLI
446
- letta
447
- ```
448
- > Whenever you change source files, rerun `bun run build` before using the linked `letta` binary so it picks up your edits.
53
+ Read the docs to learn more about [skills and skill learning](https://docs.letta.com/letta-code/skills).
449
54
 
450
55
  ---
451
56