@letta-ai/letta-code 0.19.6 → 0.19.8
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/letta.js +2539 -1250
- package/package.json +2 -1
- package/skills/context_doctor/SKILL.md +132 -0
- package/skills/context_doctor/scripts/estimate_system_tokens.ts +181 -0
- package/skills/initializing-memory/SKILL.md +48 -54
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@letta-ai/letta-code",
|
|
3
|
-
"version": "0.19.
|
|
3
|
+
"version": "0.19.8",
|
|
4
4
|
"description": "Letta Code is a CLI tool for interacting with stateful Letta agents from the terminal.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -64,6 +64,7 @@
|
|
|
64
64
|
"typescript": "^5.0.0"
|
|
65
65
|
},
|
|
66
66
|
"scripts": {
|
|
67
|
+
"prepare": "node .husky/install.mjs",
|
|
67
68
|
"lint": "bunx --bun @biomejs/biome@2.2.5 check src",
|
|
68
69
|
"fix": "bunx --bun @biomejs/biome@2.2.5 check --write src",
|
|
69
70
|
"typecheck": "tsc --noEmit",
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: Context Doctor
|
|
3
|
+
id: context_doctor
|
|
4
|
+
description: Identify and repair degradation in system prompt, external memory, and skills preventing you from following instructions or remembering information as well as you should.
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Context Doctor
|
|
8
|
+
Your context is managed by yourself, along with additional memory subagents. Your context includes:
|
|
9
|
+
- Your system prompt and instructions (contained in `system/`)
|
|
10
|
+
- Your external memory
|
|
11
|
+
- Your skills (procedural memory)
|
|
12
|
+
|
|
13
|
+
Over time, context can degrade — bloat and poor prompt quality erode your ability to remember the right things and follow instructions properly. This skill helps you identify issues with your context and repair them collaboratively with the user.
|
|
14
|
+
|
|
15
|
+
## Operating Procedure
|
|
16
|
+
|
|
17
|
+
### Step 1: Identifying and resolving context issues
|
|
18
|
+
Explore your memory files to identify issues. Consider what is confusing about your own prompts and context, and resolve the issues.
|
|
19
|
+
|
|
20
|
+
Below are additional common issues with context and how they can be resolved:
|
|
21
|
+
|
|
22
|
+
### Context quality
|
|
23
|
+
Your system prompt and memory filesystem should be well structured and clear.
|
|
24
|
+
|
|
25
|
+
**Questions to ask**:
|
|
26
|
+
- Is my system prompt clear and well formatted?
|
|
27
|
+
- Are there wasteful or unnecessary tokens in my prompts?
|
|
28
|
+
- Do I know when to load which files in my memory filesystem?
|
|
29
|
+
|
|
30
|
+
#### System prompt bloat
|
|
31
|
+
Prompts that are compiled as part of the system prompt (contained in `system/`) should only take up about 10% of the total context size, though this is a recommendation, not a hard requirement. Usually this means about 15-20k tokens.
|
|
32
|
+
|
|
33
|
+
Use the following script to evaluate the token usage of the system prompt:
|
|
34
|
+
```bash
|
|
35
|
+
bun scripts/estimate_system_tokens.ts --memory-dir "$MEMORY_DIR"
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**Questions to ask**:
|
|
39
|
+
- Do all these tokens need to be passed to the LLM on every turn, or can they be retrieved when needed through being part of external memory of my conversation history?
|
|
40
|
+
- Do any of these prompts confuse or distract me?
|
|
41
|
+
- Am I able to effectively follow critical instructions (e.g. persona information, user preferences) given the current prompt structure and contents?
|
|
42
|
+
|
|
43
|
+
**Solution**: Reduce the size of the system prompt if needed:
|
|
44
|
+
- Move files outside of `system/` so they are no longer part of the system prompt
|
|
45
|
+
- Compact information to be more information dense or eliminate redundancy
|
|
46
|
+
- Leverage progressive disclosure: move some context outside of `system/` and reference it to pull in dynamically
|
|
47
|
+
|
|
48
|
+
**Scope**: You may refine, tighten, and restructure prompts to improve clarity and adherence — but do not change the intended semantics. The goal is better signal, not different behavior.
|
|
49
|
+
- Do not alter persona-defining content (who you are, how you communicate)
|
|
50
|
+
- Do not remove or change user identity or preferences (e.g. the human's name, their stated goals)
|
|
51
|
+
- Do not rewrite instructions in ways that shift their meaning — only reduce noise and improve structure
|
|
52
|
+
|
|
53
|
+
#### Context redundancy and unclear organization
|
|
54
|
+
The context in the memory filesystem should have a clear structure, with a well-defined purpose for each file. Memory file descriptions should be precise and non-overlapping. Their contents should be consistent with the description, and have non-overlapping content to other files.
|
|
55
|
+
|
|
56
|
+
**Questions to ask**:
|
|
57
|
+
- Do the descriptions make clear what file is for what?
|
|
58
|
+
- Do the contents of the file match the descriptions? (you can ask subagents to check)
|
|
59
|
+
|
|
60
|
+
**Solution**: Read all memory files (use subagents for efficiency), then:
|
|
61
|
+
- Consolidate redundant files
|
|
62
|
+
- Reorganize files and rewrite descriptions to have clear separation of concerns
|
|
63
|
+
- Avoid duplication by referencing common files from multiple places (e.g. `[[reference/api]]`)
|
|
64
|
+
- Rewrite unclear or low-quality content
|
|
65
|
+
|
|
66
|
+
#### Invalid context format
|
|
67
|
+
Files in the memory filesystem must follow certain structural requirements:
|
|
68
|
+
- Must have a `system/persona.md`
|
|
69
|
+
- Must NOT have overlapping file and folder names (e.g. `system/human.md` and `system/human/identity.md`)
|
|
70
|
+
- Must follow specification for skills (e.g. `skills/{skill_name}/`) with the format:
|
|
71
|
+
```
|
|
72
|
+
skill-name/
|
|
73
|
+
├── SKILL.md # Required: metadata + instructions
|
|
74
|
+
├── scripts/ # Optional: executable code
|
|
75
|
+
├── references/ # Optional: documentation
|
|
76
|
+
├── assets/ # Optional: templates, resources
|
|
77
|
+
└── ... # Any additional files or directories
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
**Solution**: Reorganize files to follow the required structure
|
|
81
|
+
|
|
82
|
+
### Poor use of progressive disclosure
|
|
83
|
+
Only critical information should be in the system prompt, since it's passed on every turn. Use progressive disclosure so that context only *sometimes* needed can be dynamically retrieved.
|
|
84
|
+
|
|
85
|
+
Files that are outside of `system/` are not part of the system prompt, and must be dynamically loaded. You must index your files to ensure your future self can discover them: for example, make sure that files have informative names and descriptions, or are referenced from parts of your system prompt. Otherwise, you will never discover the external context or make use of it.
|
|
86
|
+
|
|
87
|
+
**Solution**:
|
|
88
|
+
- Reference external skills from the relevant parts of in-context memory:
|
|
89
|
+
```
|
|
90
|
+
When running a migration, always use the skill [[skills/db-migrations]]
|
|
91
|
+
```
|
|
92
|
+
or external memory files:
|
|
93
|
+
```
|
|
94
|
+
Sarah's active projects are: Letta Code [[projects/letta_code.md]] and Letta Cloud [[projects/letta_cloud]]
|
|
95
|
+
```
|
|
96
|
+
- Ensure that contents of files match the file name and descriptions
|
|
97
|
+
- Make sure your future self will be able to find and load external files when needed.
|
|
98
|
+
|
|
99
|
+
### Step 2: Implement context fixes
|
|
100
|
+
Create a plan for what fixes you want to make, then implement them.
|
|
101
|
+
|
|
102
|
+
Before moving on, verify:
|
|
103
|
+
- [ ] System prompt token budget reviewed (target ~10% of context, usually 15-20k tokens)
|
|
104
|
+
- [ ] No overlapping or redundant files remain
|
|
105
|
+
- [ ] All file descriptions are unique, accurate, and match their contents
|
|
106
|
+
- [ ] Moved-out knowledge has references from in-context memory so it can be discovered
|
|
107
|
+
- [ ] No semantic changes to persona, user identity, or behavioral instructions
|
|
108
|
+
|
|
109
|
+
### Step 3: Commit and push
|
|
110
|
+
Review changes, then commit with a descriptive message:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
cd $MEMORY_DIR
|
|
114
|
+
git status # Review what changed before staging
|
|
115
|
+
git add <specific files> # Stage targeted paths — avoid blind `git add -A`
|
|
116
|
+
git commit --author="<AGENT_NAME> <<ACTUAL_AGENT_ID>@letta.com>" -m "fix(doctor): <summary> 🏥
|
|
117
|
+
|
|
118
|
+
<identified issues and implemented solutions>"
|
|
119
|
+
|
|
120
|
+
git push
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Step 4: Final checklist and message
|
|
124
|
+
Tell the user what issues you identitied, the fixes you made, the commit you made, and also recommend that they run `/recompile` to apply these changes to the current system prompt.
|
|
125
|
+
|
|
126
|
+
Before finishing make sure you:
|
|
127
|
+
- [ ] Resolved all the identified context issues
|
|
128
|
+
- [ ] Pushed your changes successfully
|
|
129
|
+
- [ ] Told the user to run `/recompile` to refresh the system prompt and apply changes
|
|
130
|
+
|
|
131
|
+
## Critical information
|
|
132
|
+
- **Ask the user about their goals for you, not the implementation**: You understand your own context best, and should follow the guidelines in this document. Do NOT ask the user about their structural preferences - the context is for YOU, not them. Ask them how they want YOU to behave or know instead.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
#!/usr/bin/env bun
|
|
2
|
+
|
|
3
|
+
import { existsSync, readdirSync, readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { getClient } from "../../../../agent/client";
|
|
6
|
+
import { settingsManager } from "../../../../settings-manager";
|
|
7
|
+
|
|
8
|
+
const BYTES_PER_TOKEN = 4;
|
|
9
|
+
|
|
10
|
+
type FileEstimate = {
|
|
11
|
+
path: string;
|
|
12
|
+
tokens: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
type ParsedArgs = {
|
|
16
|
+
memoryDir?: string;
|
|
17
|
+
agentId?: string;
|
|
18
|
+
top: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function parseArgs(argv: string[]): ParsedArgs {
|
|
22
|
+
const parsed: ParsedArgs = { top: 20 };
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < argv.length; i++) {
|
|
25
|
+
const arg = argv[i];
|
|
26
|
+
if (arg === "--memory-dir") {
|
|
27
|
+
parsed.memoryDir = argv[i + 1];
|
|
28
|
+
i++;
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (arg === "--agent-id") {
|
|
32
|
+
parsed.agentId = argv[i + 1];
|
|
33
|
+
i++;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (arg === "--top") {
|
|
37
|
+
const raw = argv[i + 1];
|
|
38
|
+
const value = Number.parseInt(raw ?? "", 10);
|
|
39
|
+
if (!Number.isNaN(value) && value >= 0) {
|
|
40
|
+
parsed.top = value;
|
|
41
|
+
}
|
|
42
|
+
i++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return parsed;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function estimateTokens(text: string): number {
|
|
50
|
+
return Math.ceil(Buffer.byteLength(text, "utf8") / BYTES_PER_TOKEN);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function normalizePath(value: string): string {
|
|
54
|
+
return value.replaceAll("\\", "/");
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function walkMarkdownFiles(dir: string): string[] {
|
|
58
|
+
if (!existsSync(dir)) {
|
|
59
|
+
return [];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const out: string[] = [];
|
|
63
|
+
const entries = readdirSync(dir, { withFileTypes: true });
|
|
64
|
+
|
|
65
|
+
for (const entry of entries) {
|
|
66
|
+
if (entry.name.startsWith(".")) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const full = join(dir, entry.name);
|
|
70
|
+
if (entry.isDirectory()) {
|
|
71
|
+
if (entry.name === ".git") {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
out.push(...walkMarkdownFiles(full));
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (entry.isFile() && entry.name.endsWith(".md")) {
|
|
78
|
+
out.push(full);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function inferAgentIdFromMemoryDir(memoryDir: string): string | null {
|
|
86
|
+
const parts = normalizePath(memoryDir).split("/");
|
|
87
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
88
|
+
if (parts[i] === "agents" && parts[i + 1]?.startsWith("agent-")) {
|
|
89
|
+
return parts[i + 1];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const maybe = parts.at(-2);
|
|
94
|
+
return maybe?.startsWith("agent-") ? maybe : null;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
async function resolveAgentId(
|
|
98
|
+
memoryDir: string,
|
|
99
|
+
cliAgentId?: string,
|
|
100
|
+
): Promise<string> {
|
|
101
|
+
if (cliAgentId) {
|
|
102
|
+
return cliAgentId;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (process.env.AGENT_ID) {
|
|
106
|
+
return process.env.AGENT_ID;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const inferred = inferAgentIdFromMemoryDir(memoryDir);
|
|
110
|
+
if (inferred) {
|
|
111
|
+
return inferred;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const fromSession = settingsManager.getEffectiveLastAgentId(process.cwd());
|
|
115
|
+
if (fromSession) {
|
|
116
|
+
return fromSession;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
throw new Error(
|
|
120
|
+
"Unable to resolve agent ID. Pass --agent-id or set AGENT_ID.",
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
function formatNumber(value: number): string {
|
|
125
|
+
return value.toLocaleString("en-US");
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
async function main(): Promise<number> {
|
|
129
|
+
await settingsManager.initialize();
|
|
130
|
+
|
|
131
|
+
const args = parseArgs(process.argv.slice(2));
|
|
132
|
+
const memoryDir = args.memoryDir || process.env.MEMORY_DIR;
|
|
133
|
+
|
|
134
|
+
if (!memoryDir) {
|
|
135
|
+
throw new Error("Missing memory dir. Pass --memory-dir or set MEMORY_DIR.");
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const systemDir = join(memoryDir, "system");
|
|
139
|
+
if (!existsSync(systemDir)) {
|
|
140
|
+
throw new Error(`Missing system directory: ${systemDir}`);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const agentId = await resolveAgentId(memoryDir, args.agentId);
|
|
144
|
+
|
|
145
|
+
// Use the SDK auth path used by letta-code (OAuth + API key handling via getClient).
|
|
146
|
+
const client = await getClient();
|
|
147
|
+
await client.agents.retrieve(agentId);
|
|
148
|
+
|
|
149
|
+
const files = walkMarkdownFiles(systemDir).sort();
|
|
150
|
+
const rows: FileEstimate[] = [];
|
|
151
|
+
|
|
152
|
+
for (const filePath of files) {
|
|
153
|
+
const text = readFileSync(filePath, "utf8");
|
|
154
|
+
const rel = normalizePath(filePath.slice(memoryDir.length + 1));
|
|
155
|
+
rows.push({ path: rel, tokens: estimateTokens(text) });
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const estimatedTotalTokens = rows.reduce((sum, row) => sum + row.tokens, 0);
|
|
159
|
+
|
|
160
|
+
console.log("Estimated total tokens");
|
|
161
|
+
console.log(` ${formatNumber(estimatedTotalTokens)}`);
|
|
162
|
+
|
|
163
|
+
console.log("\nPer-file token estimates");
|
|
164
|
+
console.log(` ${"tokens".padStart(8)} path`);
|
|
165
|
+
|
|
166
|
+
const sortedRows = [...rows].sort((a, b) => b.tokens - a.tokens);
|
|
167
|
+
for (const row of sortedRows.slice(0, Math.max(0, args.top))) {
|
|
168
|
+
console.log(` ${formatNumber(row.tokens).padStart(8)} ${row.path}`);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return 0;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
main()
|
|
175
|
+
.then((code) => {
|
|
176
|
+
process.exit(code);
|
|
177
|
+
})
|
|
178
|
+
.catch((error: unknown) => {
|
|
179
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
180
|
+
process.exit(1);
|
|
181
|
+
});
|
|
@@ -16,23 +16,23 @@ If you are running as a background subagent (you cannot use AskUserQuestion):
|
|
|
16
16
|
- Use reasonable defaults for all preferences
|
|
17
17
|
- Any specific overrides will be provided in your initial prompt
|
|
18
18
|
|
|
19
|
-
## Your Goal:
|
|
19
|
+
## Your Goal: Organize Into a Hierarchical Memory Structure
|
|
20
20
|
|
|
21
|
-
Your goal is to **
|
|
21
|
+
Your goal is to **organize** memory into a **deeply hierarchical structure of small, focused files**.
|
|
22
22
|
|
|
23
23
|
### Target Output
|
|
24
24
|
|
|
25
25
|
| Metric | Target |
|
|
26
26
|
|--------|--------|
|
|
27
|
-
| **Total files** |
|
|
28
|
-
| **
|
|
29
|
-
| **Hierarchy depth** |
|
|
27
|
+
| **Total files** | Enough focused files to cover distinct concepts without bloating any single file |
|
|
28
|
+
| **File size** | Keep files concise and split when they become unwieldy |
|
|
29
|
+
| **Hierarchy depth** | Use nested `/` paths whenever they improve clarity (e.g., `project/tooling/bun.md`) |
|
|
30
30
|
| **Nesting requirement** | Every new file MUST be nested under a parent using `/` |
|
|
31
31
|
|
|
32
32
|
**Anti-patterns to avoid:**
|
|
33
|
-
- ❌ Ending with only
|
|
33
|
+
- ❌ Ending with only a few large files
|
|
34
34
|
- ❌ Flat naming (all files at top level)
|
|
35
|
-
- ❌ Mega-files with
|
|
35
|
+
- ❌ Mega-files with many unrelated sections
|
|
36
36
|
|
|
37
37
|
## Memory Filesystem Integration
|
|
38
38
|
|
|
@@ -45,27 +45,27 @@ Your memory is a git-backed filesystem at `~/.letta/agents/<agent-id>/`. The act
|
|
|
45
45
|
- The filesystem tree (all file paths + metadata) is always visible regardless of location
|
|
46
46
|
- You can use bash commands (`ls`, `mkdir`, `mv`, `git`) to organize files
|
|
47
47
|
- You MUST create a **deeply hierarchical file structure** — flat naming is NOT acceptable
|
|
48
|
-
-
|
|
48
|
+
- Create as many files as needed for clarity in `system/`, with additional reference files outside as needed
|
|
49
49
|
|
|
50
50
|
**MANDATORY principles for hierarchical organization:**
|
|
51
51
|
|
|
52
52
|
| Requirement | Target |
|
|
53
53
|
|-------------|--------|
|
|
54
|
-
| **Total files** |
|
|
55
|
-
| **
|
|
56
|
-
| **Hierarchy depth** |
|
|
54
|
+
| **Total files** | Enough focused files to avoid monoliths while staying maintainable |
|
|
55
|
+
| **File size** | Keep files concise and split when they become unwieldy |
|
|
56
|
+
| **Hierarchy depth** | Use meaningful nesting with `/` naming where it helps organization |
|
|
57
57
|
| **Nesting requirement** | EVERY new file MUST use `/` naming (no flat files) |
|
|
58
58
|
|
|
59
59
|
**Anti-patterns to avoid:**
|
|
60
|
-
- ❌ Creating only
|
|
60
|
+
- ❌ Creating only a few large files
|
|
61
61
|
- ❌ Flat naming (all files at top level like `project-commands.md`)
|
|
62
|
-
- ❌ Mega-files with
|
|
62
|
+
- ❌ Mega-files with many unrelated sections
|
|
63
63
|
|
|
64
64
|
**Rules:**
|
|
65
|
-
- Use
|
|
66
|
-
- Keep files **focused and
|
|
65
|
+
- Use clear nested paths for files whenever hierarchy improves discoverability (e.g., `project/tooling/bun.md`)
|
|
66
|
+
- Keep files **focused and concise**
|
|
67
67
|
- Use **descriptive paths** that make sense when you see just the filename
|
|
68
|
-
- Split when a file
|
|
68
|
+
- Split when a file starts mixing multiple concepts (be aggressive)
|
|
69
69
|
|
|
70
70
|
**Example target structure (what success looks like):**
|
|
71
71
|
|
|
@@ -93,7 +93,7 @@ system/
|
|
|
93
93
|
└── behavior.md # How to behave
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
This example
|
|
96
|
+
This example is illustrative. Your output should match the project’s actual complexity and the user’s needs.
|
|
97
97
|
|
|
98
98
|
This approach makes memory more **scannable**, **maintainable**, and **shareable** with other agents.
|
|
99
99
|
|
|
@@ -319,7 +319,7 @@ You should ask these questions at the start (bundle them together in one AskUser
|
|
|
319
319
|
2. **Identity**: "Which contributor are you?" (You can often infer this from git logs - e.g., if git shows "cpacker" as a top contributor, ask "Are you cpacker?")
|
|
320
320
|
3. **Related repos**: "Are there other repositories I should know about and consider in my research?" (e.g., backend monorepo, shared libraries)
|
|
321
321
|
4. **Historical sessions** (include this question if history data was found in step 2): "I found Claude Code / Codex history on your machine. Should I analyze it to learn your preferences, coding patterns, and project context? This significantly improves how I work with you but uses additional time and tokens." Options: "Yes, analyze history" / "Skip for now". Use "History" as the header.
|
|
322
|
-
5. **Memory updates**: "How often should I check
|
|
322
|
+
5. **Memory updates**: "How often should I check whether to update memory?" with options "Frequent" and "Occasional". This should be a binary question with "Memory" as the header.
|
|
323
323
|
6. **Communication style**: "Terse or detailed responses?"
|
|
324
324
|
7. **Any specific rules**: "Rules I should always follow?"
|
|
325
325
|
|
|
@@ -364,11 +364,11 @@ mkdir -p ~/.letta/agents/<agent-id>/memory/system/human/prefs
|
|
|
364
364
|
- **Every new file MUST use `/` naming** - no flat files allowed
|
|
365
365
|
- Use `/` for hierarchy: `project/tooling/testing` (not `project-tooling-testing`)
|
|
366
366
|
- File path determines the memory label: `system/project/overview.md` → label `project/overview`
|
|
367
|
-
- Keep files small and focused
|
|
367
|
+
- Keep files small and focused
|
|
368
368
|
- Use **descriptive frontmatter** — the `description` field helps your future self understand each file's purpose
|
|
369
369
|
|
|
370
370
|
**Checkpoint before proceeding:**
|
|
371
|
-
|
|
371
|
+
Review your proposed files and split further if the structure still feels too flat or monolithic.
|
|
372
372
|
|
|
373
373
|
**Benefits:**
|
|
374
374
|
- More scannable and maintainable
|
|
@@ -376,17 +376,17 @@ Count your proposed files. **If you have fewer than 15 files, go back and split
|
|
|
376
376
|
- Natural progressive disclosure (load parent, then drill into children)
|
|
377
377
|
- Works like a file system you're familiar with
|
|
378
378
|
|
|
379
|
-
### Split Aggressively
|
|
379
|
+
### Split Aggressively
|
|
380
380
|
|
|
381
|
-
**Don't create monolithic files.**
|
|
381
|
+
**Don't create monolithic files.** Be aggressive about splitting when it improves clarity:
|
|
382
382
|
|
|
383
383
|
**Split when:**
|
|
384
|
-
- A file
|
|
385
|
-
- A file
|
|
384
|
+
- A file becomes long enough that scanning it slows you down
|
|
385
|
+
- A file mixes distinct concepts that would be clearer if separated
|
|
386
386
|
- A section could stand alone as its own file
|
|
387
387
|
- You can name the extracted content with a clear `/` path
|
|
388
388
|
|
|
389
|
-
If a file is getting long
|
|
389
|
+
If a file is getting long or conceptually mixed, split it:
|
|
390
390
|
|
|
391
391
|
**Without memory filesystem** (flat naming - acceptable but not ideal):
|
|
392
392
|
- `project-overview`: High-level description, tech stack, repo links
|
|
@@ -402,7 +402,7 @@ If a file is getting long (>40 lines), split it:
|
|
|
402
402
|
- `project/architecture`: Directory structure, key modules
|
|
403
403
|
- `project/gotchas`: Footguns, things to watch out for
|
|
404
404
|
- **Must further nest**: `project/tooling/testing`, `project/tooling/linting`, `project/tooling/bun`
|
|
405
|
-
-
|
|
405
|
+
- If commands are broad, split into focused files like `project/commands/dev`, `project/commands/build`, etc.
|
|
406
406
|
|
|
407
407
|
This makes memory more scannable and easier to update and share with other agents.
|
|
408
408
|
|
|
@@ -456,9 +456,9 @@ And add memory files that you think make sense to add (e.g., `project/architectu
|
|
|
456
456
|
|
|
457
457
|
9. **Create/update memory structure** (can happen incrementally alongside steps 7-8):
|
|
458
458
|
- **With memfs enabled**: Create a deeply hierarchical file structure using bash commands
|
|
459
|
-
- Use `mkdir -p` to create subdirectories
|
|
459
|
+
- Use `mkdir -p` to create subdirectories as needed
|
|
460
460
|
- Create `.md` files for memory files using `/` naming
|
|
461
|
-
-
|
|
461
|
+
- Be aggressive about splitting when it improves clarity
|
|
462
462
|
- Use nested paths like `project/tooling/testing.md` (never flat like `project-testing.md`)
|
|
463
463
|
- **Every new file MUST be nested** under a parent using `/`
|
|
464
464
|
- **Every new file MUST be nested** under a parent using `/`
|
|
@@ -466,10 +466,9 @@ And add memory files that you think make sense to add (e.g., `project/architectu
|
|
|
466
466
|
- **Don't wait until the end** - write findings as you go
|
|
467
467
|
|
|
468
468
|
**Checkpoint verification:**
|
|
469
|
-
-
|
|
470
|
-
-
|
|
471
|
-
-
|
|
472
|
-
- **Should be 2-3 levels deep** minimum
|
|
469
|
+
- Review file count and shape: `find ~/.letta/agents/<agent-id>/memory/system/ -type f | wc -l`
|
|
470
|
+
- Review hierarchy depth: `find ~/.letta/agents/<agent-id>/memory/system/ -type f | awk -F/ '{print NF}' | sort -n | tail -1`
|
|
471
|
+
- Verify the structure feels appropriately granular and discoverable for this project
|
|
473
472
|
|
|
474
473
|
10. **Organize incrementally**:
|
|
475
474
|
- Start with a basic structure
|
|
@@ -487,14 +486,13 @@ And add memory files that you think make sense to add (e.g., `project/architectu
|
|
|
487
486
|
|
|
488
487
|
Before finishing, you MUST do a reflection step. **Your memory files are visible to you in your system prompt right now.** Look at them carefully and ask yourself:
|
|
489
488
|
|
|
490
|
-
1. **File
|
|
491
|
-
-
|
|
492
|
-
-
|
|
493
|
-
- Too few files means they're too large - split more aggressively
|
|
489
|
+
1. **File granularity check**:
|
|
490
|
+
- Review your memory file set: `find ~/.letta/agents/<agent-id>/memory/system/ -type f | wc -l`
|
|
491
|
+
- Ask whether any files are still too broad and should be split
|
|
494
492
|
|
|
495
493
|
2. **Hierarchy check**:
|
|
496
494
|
- Are ALL new files using `/` naming? (e.g., `project/tooling/bun.md`)
|
|
497
|
-
-
|
|
495
|
+
- Is the nesting meaningful for this project?
|
|
498
496
|
- Are there any flat files like `project-commands.md`? **These should be nested**
|
|
499
497
|
|
|
500
498
|
3. **Redundancy check**: Are there files with overlapping content? Either literally overlapping (due to errors while editing), or semantically/conceptually overlapping?
|
|
@@ -545,7 +543,7 @@ cat ~/.letta/agents/<agent-id>/memory/system/persona.md
|
|
|
545
543
|
❌ `project_testing.md` (underscore instead of `/`)
|
|
546
544
|
|
|
547
545
|
```bash
|
|
548
|
-
# Create
|
|
546
|
+
# Create a nested directory structure suited to the content
|
|
549
547
|
mkdir -p ~/.letta/agents/<agent-id>/memory/system/project/{tooling,architecture,conventions}
|
|
550
548
|
mkdir -p ~/.letta/agents/<agent-id>/memory/system/human/prefs
|
|
551
549
|
mkdir -p ~/.letta/agents/<agent-id>/memory/system/persona/behavior
|
|
@@ -584,22 +582,22 @@ mv ~/.letta/agents/<agent-id>/memory/system/project/tooling.md \
|
|
|
584
582
|
|
|
585
583
|
Before you tell the user you're done, confirm:
|
|
586
584
|
|
|
587
|
-
- [ ] **File
|
|
585
|
+
- [ ] **File granularity is appropriate** — verify no files are overly broad and split where useful.
|
|
588
586
|
- [ ] **All new files use `/` naming** — No flat files like `my_notes.md` or `project-commands.md`
|
|
589
|
-
- [ ] **Hierarchy is
|
|
590
|
-
- [ ] **No file
|
|
591
|
-
- [ ] **Each file
|
|
587
|
+
- [ ] **Hierarchy is meaningful** — nested paths should improve discoverability and organization.
|
|
588
|
+
- [ ] **No file is bloated** — split files that are hard to scan quickly.
|
|
589
|
+
- [ ] **Each file stays concept-focused** — split files that combine unrelated topics.
|
|
592
590
|
- [ ] **Every file has real content** — No empty or pointer-only files
|
|
593
591
|
- [ ] **Verify sync**: After creating files, check they appear in your memory files
|
|
594
592
|
|
|
595
|
-
**If
|
|
593
|
+
**If the structure still feels flat or monolithic, split further until it is clear and maintainable.**
|
|
596
594
|
|
|
597
595
|
### Best Practices
|
|
598
596
|
|
|
599
597
|
1. **Check memfs status first**: Look for `memory_filesystem` section in your system prompt
|
|
600
598
|
2. **Start with directories**: Create the directory structure before populating files
|
|
601
|
-
3. **Use
|
|
602
|
-
4. **Keep files focused**:
|
|
599
|
+
3. **Use practical paths**: prefer clear, readable nesting (e.g., `project/tooling/testing`) over unnecessarily deep paths.
|
|
600
|
+
4. **Keep files focused**: each file should cover a coherent concept and remain easy to scan.
|
|
603
601
|
5. **Every file should have real content** — no empty or pointer-only files
|
|
604
602
|
6. **Be aggressive about splitting**: If in doubt, split. Too many small files is better than too few large ones.
|
|
605
603
|
|
|
@@ -636,15 +634,11 @@ LINES=$(wc -l < ~/.claude/history.jsonl)
|
|
|
636
634
|
CHUNK_SIZE=$(( LINES / NUM_WORKERS + 1 ))
|
|
637
635
|
split -l $CHUNK_SIZE ~/.claude/history.jsonl "$SPLIT_DIR/claude-"
|
|
638
636
|
|
|
639
|
-
# Split Codex history
|
|
637
|
+
# Split Codex history if it exists
|
|
640
638
|
if [ -f ~/.codex/history.jsonl ]; then
|
|
641
639
|
LINES=$(wc -l < ~/.codex/history.jsonl)
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
split -l $CHUNK_SIZE ~/.codex/history.jsonl "$SPLIT_DIR/codex-"
|
|
645
|
-
else
|
|
646
|
-
cp ~/.codex/history.jsonl "$SPLIT_DIR/codex-aa"
|
|
647
|
-
fi
|
|
640
|
+
CHUNK_SIZE=$(( LINES / NUM_WORKERS + 1 ))
|
|
641
|
+
split -l $CHUNK_SIZE ~/.codex/history.jsonl "$SPLIT_DIR/codex-"
|
|
648
642
|
fi
|
|
649
643
|
|
|
650
644
|
# Rename to .jsonl for clarity
|
|
@@ -702,12 +696,12 @@ After merging, **read every file in `system/`** and apply editorial judgment:
|
|
|
702
696
|
|
|
703
697
|
Workers may have created files that don't fit the ideal hierarchy, or put too much into `system/`. Fix this:
|
|
704
698
|
|
|
705
|
-
- Split oversized
|
|
699
|
+
- Split oversized or conceptually mixed files into focused sub-files
|
|
706
700
|
- Move reference-quality content (detailed history, background context, evidence trails) to `reference/`
|
|
707
701
|
- Ensure `system/` contains only what you genuinely need in-context: identity, active preferences, current project context, behavioral rules, gotchas
|
|
708
702
|
- Merge near-duplicate files that cover the same topic
|
|
709
703
|
|
|
710
|
-
**Rule of thumb**: If removing a file from `system/` wouldn't
|
|
704
|
+
**Rule of thumb**: If removing a file from `system/` wouldn't materially affect near-term responses, it belongs in `reference/`.
|
|
711
705
|
|
|
712
706
|
**3d. Clean up worktrees and branches:**
|
|
713
707
|
|