@letta-ai/letta-code 0.1.9 → 0.1.11

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 +74 -32
  2. package/letta.js +4169 -113381
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -13,7 +13,7 @@ Letta Code is a command-line harness around the stateful Letta [Agents API](http
13
13
  Letta Code is model agnostic, and supports Sonnet 4.5, GPT-5, Gemini 2.5, GLM-4.6, and more.
14
14
 
15
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.
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.
17
17
 
18
18
  ## Quickstart
19
19
 
@@ -24,7 +24,7 @@ Install the package via [npm](https://docs.npmjs.com/downloading-and-installing-
24
24
  npm install -g @letta-ai/letta-code
25
25
  ```
26
26
 
27
- Make sure you have your Letta API key set in your environment:
27
+ Set your Letta API key via environment variable:
28
28
  ```bash
29
29
  export LETTA_API_KEY=...
30
30
  ```
@@ -38,67 +38,86 @@ Any of the agents you create in Letta Code will be viewable (and fully interacta
38
38
 
39
39
  ## Persistence
40
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). Agents can share memory blocks across projects—for example, multiple agents can share user coding preferences while maintaining project-specific memories independently.
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 # Force create new agent
56
+ letta --agent <id> # Use specific agent ID
57
+ ```
42
58
 
43
59
  ### Memory Configuration
44
60
 
45
- Letta Code uses a hierarchical memory system with both global and local blocks:
61
+ Letta Code uses a hierarchical memory system:
46
62
 
47
63
  **Global** (`~/.letta/settings.json`)
64
+ - API keys and credentials
48
65
  - `persona` block - defines agent behavior
49
66
  - `human` block - stores user coding preferences
50
67
 
51
- **Local** (`./.letta/settings.json`)
52
- - `project` block - stores project-specific context
53
-
54
- ### Starting Letta
55
-
56
- ```bash
57
- letta # New agent (attaches to existing memory blocks or creates new)
58
- letta --continue # Resume last agent session
59
- letta --agent <id> # Resume specific agent session
60
- ```
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
61
71
 
62
- When you start a new agent, it automatically connects to existing memory block IDs from your settings files. If none exist, it creates them.
72
+ **Project Shared** (`./.letta/settings.json`)
73
+ - `project` block - stores project-specific context
74
+ - Can be committed - shared with team
63
75
 
64
- Memory blocks are highly configurable — see our [docs](https://docs.letta.com/guides/agents/memory-blocks) for advanced configuration options. Join our [Discord](https://discord.gg/letta) to share feedback on persistence patterns for coding agents.
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.
65
78
 
66
79
  ## Usage
67
80
 
68
81
  ### Interactive Mode
69
82
  ```bash
70
- letta # Start new session (new agent with shared memory blocks)
71
- letta --continue # Resume last session (last recently used agent)
72
- letta --agent <id> # Open specific agent
83
+ letta # Auto-resume project agent (or create new if first time)
84
+ letta --new # Force create new agent
85
+ letta --agent <id> # Use specific agent ID
86
+ letta --continue # Resume global last agent (deprecated, use project-based)
73
87
  ```
74
88
 
75
89
  ### Headless Mode
76
90
  ```bash
77
- letta -p "your prompt" # Run non-interactive
78
- letta -p "commit changes" --continue # Continue previous session
79
- letta -p "run tests" --allowedTools "Bash" # Control tool permissions
80
- letta -p "run tests" --disallowedTools "Bash" # Control tool permissions
91
+ letta -p "Run bun lint and correct errors" # Auto-resumes project agent
92
+ letta -p "Pick up where you left off" # Same - auto-resumes by default
93
+ letta -p "Start fresh" --new # Force new agent
94
+ letta -p "Run all the test" --allowedTools "Bash" # Control tool permissions
95
+ letta -p "Just read the code" --disallowedTools "Bash" # Control tool permissions
81
96
 
82
97
  # Pipe input from stdin
83
98
  echo "Explain this code" | letta -p
84
99
  cat file.txt | letta -p
85
- gh pr diff 123 | letta -p --yolo # Review PR changes
100
+ gh pr diff 123 | letta -p --yolo
101
+
102
+ # Output formats
103
+ letta -p "Analyze this codebase" --output-format json # Structured JSON at end
104
+ letta -p "Analyze this codebase" --output-format stream-json # JSONL stream (one event per line)
86
105
  ```
87
106
 
88
107
  You can also use the `--tools` flag to control the underlying *attachment* of tools (not just the permissions).
89
108
  Compared to disallowing the tool, this will additionally remove the tool schema from the agent's context window.
90
109
  ```bash
91
- letta -p "run tests" --tools "Bash,Read" # Only load specific tools
92
- letta -p "analyze code" --tools "" # No tools (analysis only)
110
+ letta -p "Run all tests" --tools "Bash,Read" # Only load specific tools
111
+ letta -p "Just analyze the code" --tools "" # No tools (analysis only)
93
112
  ```
94
113
 
95
- Use `--output-format json` to get additional information, including the agent ID ("session_id"):
114
+ Use `--output-format json` to get structured output with metadata:
96
115
  ```bash
97
116
  # regular text output
98
117
  $ letta -p "hi there"
99
118
  Hi! How can I help you today?
100
119
 
101
- # structured output
120
+ # structured output (single JSON object at end)
102
121
  $ letta -p "hi there" --output-format json
103
122
  {
104
123
  "type": "result",
@@ -108,14 +127,32 @@ $ letta -p "hi there" --output-format json
108
127
  "duration_api_ms": 2098,
109
128
  "num_turns": 1,
110
129
  "result": "Hi! How can I help you today?",
111
- "session_id": "agent-8ab431ca-63e0-4ca1-ba83-b64d66d95a0f",
130
+ "agent_id": "agent-8ab431ca-63e0-4ca1-ba83-b64d66d95a0f",
112
131
  "usage": {
113
- "input_tokens": 294,
114
- "output_tokens": 97
132
+ "prompt_tokens": 294,
133
+ "completion_tokens": 97,
134
+ "total_tokens": 391
115
135
  }
116
136
  }
117
137
  ```
118
138
 
139
+ Use `--output-format stream-json` to get streaming outputs, in addition to a final JSON response.
140
+ This is useful if you need to have data flowing to prevent automatic timeouts:
141
+ ```bash
142
+ # streaming JSON output (JSONL - one event per line, token-level streaming)
143
+ # Note: Messages are streamed at the token level - each chunk has the same otid and incrementing seqId.
144
+ $ letta -p "hi there" --output-format stream-json
145
+ {"type":"init","agent_id":"agent-...","model":"claude-sonnet-4-5-20250929","tools":[...]}
146
+ {"type":"message","messageType":"reasoning_message","reasoning":"The user is asking","otid":"...","seqId":1}
147
+ {"type":"message","messageType":"reasoning_message","reasoning":" me to say hello","otid":"...","seqId":2}
148
+ {"type":"message","messageType":"reasoning_message","reasoning":". This is a simple","otid":"...","seqId":3}
149
+ {"type":"message","messageType":"reasoning_message","reasoning":" greeting.","otid":"...","seqId":4}
150
+ {"type":"message","messageType":"assistant_message","content":"Hi! How can I help you today?","otid":"...","seqId":5}
151
+ {"type":"message","messageType":"stop_reason","stopReason":"end_turn"}
152
+ {"type":"message","messageType":"usage_statistics","promptTokens":294,"completionTokens":97,"totalTokens":391}
153
+ {"type":"result","subtype":"success","result":"Hi! How can I help you today?","agent_id":"agent-...","usage":{...}}
154
+ ```
155
+
119
156
  ### Permissions
120
157
 
121
158
  **Tool selection** (controls which tools are loaded):
@@ -151,6 +188,11 @@ Permissions are also configured in `.letta/settings.json`:
151
188
  }
152
189
  ```
153
190
 
191
+ ## Self-hosting
192
+
193
+ 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"`.
194
+ See our [self-hosting guide](https://docs.letta.com/guides/selfhosting) for more information.
195
+
154
196
  ## Installing from source
155
197
 
156
198
  First, install Bun if you don't have it yet: [https://bun.com/docs/installation](https://bun.com/docs/installation)
@@ -171,7 +213,7 @@ bun run dev -- -p "Hello world" # example with args
171
213
  bun run build
172
214
 
173
215
  # expose the binary globally (adjust to your preference)
174
- bun link --global # or: bun add --global .
216
+ bun link
175
217
 
176
218
  # now you can run the compiled CLI
177
219
  letta