feat: add basic utility examples with agent persistence

Three practical examples showing core SDK capabilities:

- **bug-fixer**: Find and fix bugs, remembers codebase patterns
- **release-notes**: Generate release notes from git commits
- **file-organizer**: Organize directories, learns preferences

Each example uses agent persistence (getOrCreateAgent pattern) so the
agent remembers context across sessions - the key Letta differentiator.

🤖 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>
This commit is contained in:
Cameron Pfiffer
2026-01-27 15:51:27 -08:00
parent d5bbce6dec
commit 3b4811f035
9 changed files with 1137 additions and 0 deletions

107
examples/bug-fixer/cli.ts Executable file
View File

@@ -0,0 +1,107 @@
#!/usr/bin/env bun
/**
* Bug Fixer CLI
*
* A persistent agent that finds and fixes bugs in code.
*
* Usage:
* bun cli.ts "description of the bug" # Fix a specific bug
* bun cli.ts # Interactive mode
* bun cli.ts --status # Show agent status
* bun cli.ts --reset # Reset agent
*/
import { parseArgs } from 'node:util';
import {
loadState,
saveState,
getOrCreateAgent,
fixBug,
interactiveMode,
showStatus,
reset,
} from './fixer.js';
async function main() {
const { values, positionals } = parseArgs({
args: process.argv.slice(2),
options: {
status: { type: 'boolean', default: false },
reset: { type: 'boolean', default: false },
help: { type: 'boolean', short: 'h', default: false },
},
allowPositionals: true,
});
if (values.help) {
printHelp();
return;
}
if (values.reset) {
await reset();
return;
}
const state = await loadState();
if (values.status) {
await showStatus(state);
return;
}
// Get or create the agent
const agent = await getOrCreateAgent(state);
// Save agent ID if new
if (!state.agentId && agent.agentId) {
state.agentId = agent.agentId;
await saveState(state);
console.log(`\x1b[90m[Agent: ${agent.agentId}]\x1b[0m`);
console.log(`\x1b[90m[→ https://app.letta.com/agents/${agent.agentId}]\x1b[0m\n`);
}
if (positionals.length > 0) {
// Fix the specified bug
const bugDescription = positionals.join(' ');
await fixBug(agent, state, bugDescription);
} else {
// Interactive mode
await interactiveMode(agent, state);
}
agent.close();
}
function printHelp() {
console.log(`
🐛 Bug Fixer
A persistent agent that finds and fixes bugs. Remembers your codebase.
USAGE:
bun cli.ts [bug description] Fix a specific bug
bun cli.ts Interactive mode
bun cli.ts --status Show agent status
bun cli.ts --reset Reset agent (forget everything)
bun cli.ts -h, --help Show this help
EXAMPLES:
bun cli.ts "the tests in auth.test.ts are failing"
bun cli.ts "TypeError on line 42 of utils.ts"
bun cli.ts "npm run build shows an error about missing module"
HOW IT WORKS:
1. Describe the bug (error message, failing test, unexpected behavior)
2. The agent explores your codebase to understand the context
3. It identifies the root cause and makes a fix
4. It runs tests or commands to verify
PERSISTENCE:
The agent remembers your codebase across sessions. The more you use it,
the better it knows where things are and what patterns to look for.
`);
}
main().catch(console.error);