@letta-ai/letta-code 0.11.1 → 0.11.2-next.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@letta-ai/letta-code",
3
- "version": "0.11.1",
3
+ "version": "0.11.2-next.1",
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": {
@@ -30,7 +30,7 @@
30
30
  "access": "public"
31
31
  },
32
32
  "dependencies": {
33
- "@letta-ai/letta-client": "1.6.1",
33
+ "@letta-ai/letta-client": "1.6.4",
34
34
  "glob": "^13.0.0",
35
35
  "ink-link": "^5.0.0",
36
36
  "open": "^10.2.0"
@@ -0,0 +1,115 @@
1
+ ---
2
+ name: finding-agents
3
+ description: Find other agents on the same server. Use when the user asks about other agents, wants to migrate memory from another agent, or needs to find an agent by name or tags.
4
+ ---
5
+
6
+ # Finding Agents
7
+
8
+ This skill helps you find other agents on the same Letta server.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - User asks about other agents they have
13
+ - User wants to find a specific agent by name
14
+ - User wants to list agents with certain tags
15
+ - You need to find an agent ID for memory migration
16
+ - You found an agent_id via message search and need details about that agent
17
+
18
+ ## Script Usage
19
+
20
+ ```bash
21
+ npx ts-node scripts/find-agents.ts [options]
22
+ ```
23
+
24
+ ### Options
25
+
26
+ | Option | Description |
27
+ |--------|-------------|
28
+ | `--name <name>` | Exact name match |
29
+ | `--query <text>` | Fuzzy search by name |
30
+ | `--tags <tag1,tag2>` | Filter by tags (comma-separated) |
31
+ | `--match-all-tags` | Require ALL tags (default: ANY) |
32
+ | `--include-blocks` | Include agent.blocks in response |
33
+ | `--limit <n>` | Max results (default: 20) |
34
+
35
+ ## Common Patterns
36
+
37
+ ### Finding Letta Code Agents
38
+
39
+ Agents created by Letta Code are tagged with `origin:letta-code`. To find only Letta Code agents:
40
+
41
+ ```bash
42
+ npx ts-node scripts/find-agents.ts --tags "origin:letta-code"
43
+ ```
44
+
45
+ This is useful when the user is looking for agents they've worked with in Letta Code CLI sessions.
46
+
47
+ ### Finding All Agents
48
+
49
+ If the user has agents created outside Letta Code (via ADE, SDK, etc.), search without the tag filter:
50
+
51
+ ```bash
52
+ npx ts-node scripts/find-agents.ts
53
+ ```
54
+
55
+ ## Examples
56
+
57
+ **List all agents (up to 20):**
58
+ ```bash
59
+ npx ts-node scripts/find-agents.ts
60
+ ```
61
+
62
+ **Find agent by exact name:**
63
+ ```bash
64
+ npx ts-node scripts/find-agents.ts --name "ProjectX-v1"
65
+ ```
66
+
67
+ **Search agents by name (fuzzy):**
68
+ ```bash
69
+ npx ts-node scripts/find-agents.ts --query "project"
70
+ ```
71
+
72
+ **Find only Letta Code agents:**
73
+ ```bash
74
+ npx ts-node scripts/find-agents.ts --tags "origin:letta-code"
75
+ ```
76
+
77
+ **Find agents with multiple tags:**
78
+ ```bash
79
+ npx ts-node scripts/find-agents.ts --tags "frontend,production" --match-all-tags
80
+ ```
81
+
82
+ **Include memory blocks in results:**
83
+ ```bash
84
+ npx ts-node scripts/find-agents.ts --query "project" --include-blocks
85
+ ```
86
+
87
+ ## Output
88
+
89
+ Returns the raw API response with full agent details. Key fields:
90
+ - `id` - Agent ID (e.g., `agent-abc123`)
91
+ - `name` - Agent name
92
+ - `description` - Agent description
93
+ - `tags` - Agent tags
94
+ - `blocks` - Memory blocks (if `--include-blocks` used)
95
+
96
+ ## Related Skills
97
+
98
+ - **migrating-memory** - Once you find an agent, use this skill to copy/share memory blocks
99
+ - **searching-messages** - Search messages across all agents to find which agent discussed a topic. Use `--all-agents` to get `agent_id` values, then use this skill to get full agent details.
100
+
101
+ ### Finding Agents by Topic
102
+
103
+ If you need to find which agent worked on a specific topic:
104
+
105
+ 1. Load both skills: `searching-messages` and `finding-agents`
106
+ 2. Search messages across all agents:
107
+ ```bash
108
+ search-messages.ts --query "topic" --all-agents --limit 10
109
+ ```
110
+ 3. Note the `agent_id` values from matching messages
111
+ 4. Get agent details:
112
+ ```bash
113
+ find-agents.ts --query "partial-name"
114
+ ```
115
+ Or use the agent_id directly in the Letta API
@@ -0,0 +1,134 @@
1
+ #!/usr/bin/env npx ts-node
2
+ /**
3
+ * Find Agents - Search for agents with various filters
4
+ *
5
+ * Usage:
6
+ * npx ts-node find-agents.ts [options]
7
+ *
8
+ * Options:
9
+ * --name <name> Exact name match
10
+ * --query <text> Fuzzy search by name
11
+ * --tags <tag1,tag2> Filter by tags (comma-separated)
12
+ * --match-all-tags Require ALL tags (default: ANY)
13
+ * --include-blocks Include agent.blocks in response
14
+ * --limit <n> Max results (default: 20)
15
+ *
16
+ * Output:
17
+ * Raw API response from GET /v1/agents
18
+ */
19
+
20
+ import type Letta from "@letta-ai/letta-client";
21
+ import { getClient } from "../../../../agent/client";
22
+ import { settingsManager } from "../../../../settings-manager";
23
+
24
+ interface FindAgentsOptions {
25
+ name?: string;
26
+ query?: string;
27
+ tags?: string[];
28
+ matchAllTags?: boolean;
29
+ includeBlocks?: boolean;
30
+ limit?: number;
31
+ }
32
+
33
+ /**
34
+ * Find agents matching the given criteria
35
+ * @param client - Letta client instance
36
+ * @param options - Search options
37
+ * @returns Array of agent objects from the API
38
+ */
39
+ export async function findAgents(
40
+ client: Letta,
41
+ options: FindAgentsOptions = {},
42
+ ): Promise<Awaited<ReturnType<typeof client.agents.list>>> {
43
+ const params: Parameters<typeof client.agents.list>[0] = {
44
+ limit: options.limit ?? 20,
45
+ };
46
+
47
+ if (options.name) {
48
+ params.name = options.name;
49
+ }
50
+
51
+ if (options.query) {
52
+ params.query_text = options.query;
53
+ }
54
+
55
+ if (options.tags && options.tags.length > 0) {
56
+ params.tags = options.tags;
57
+ if (options.matchAllTags) {
58
+ params.match_all_tags = true;
59
+ }
60
+ }
61
+
62
+ if (options.includeBlocks) {
63
+ params.include = ["agent.blocks"];
64
+ }
65
+
66
+ return await client.agents.list(params);
67
+ }
68
+
69
+ function parseArgs(args: string[]): FindAgentsOptions {
70
+ const options: FindAgentsOptions = {};
71
+
72
+ const nameIndex = args.indexOf("--name");
73
+ if (nameIndex !== -1 && nameIndex + 1 < args.length) {
74
+ options.name = args[nameIndex + 1];
75
+ }
76
+
77
+ const queryIndex = args.indexOf("--query");
78
+ if (queryIndex !== -1 && queryIndex + 1 < args.length) {
79
+ options.query = args[queryIndex + 1];
80
+ }
81
+
82
+ const tagsIndex = args.indexOf("--tags");
83
+ if (tagsIndex !== -1 && tagsIndex + 1 < args.length) {
84
+ options.tags = args[tagsIndex + 1]?.split(",").map((t) => t.trim());
85
+ }
86
+
87
+ if (args.includes("--match-all-tags")) {
88
+ options.matchAllTags = true;
89
+ }
90
+
91
+ if (args.includes("--include-blocks")) {
92
+ options.includeBlocks = true;
93
+ }
94
+
95
+ const limitIndex = args.indexOf("--limit");
96
+ if (limitIndex !== -1 && limitIndex + 1 < args.length) {
97
+ const limit = Number.parseInt(args[limitIndex + 1] as string, 10);
98
+ if (!Number.isNaN(limit)) {
99
+ options.limit = limit;
100
+ }
101
+ }
102
+
103
+ return options;
104
+ }
105
+
106
+ // CLI entry point
107
+ if (require.main === module) {
108
+ (async () => {
109
+ try {
110
+ const options = parseArgs(process.argv.slice(2));
111
+ await settingsManager.initialize();
112
+ const client = await getClient();
113
+ const result = await findAgents(client, options);
114
+ console.log(JSON.stringify(result, null, 2));
115
+ } catch (error) {
116
+ console.error(
117
+ "Error:",
118
+ error instanceof Error ? error.message : String(error),
119
+ );
120
+ console.error(`
121
+ Usage: npx ts-node find-agents.ts [options]
122
+
123
+ Options:
124
+ --name <name> Exact name match
125
+ --query <text> Fuzzy search by name
126
+ --tags <tag1,tag2> Filter by tags (comma-separated)
127
+ --match-all-tags Require ALL tags (default: ANY)
128
+ --include-blocks Include agent.blocks in response
129
+ --limit <n> Max results (default: 20)
130
+ `);
131
+ process.exit(1);
132
+ }
133
+ })();
134
+ }
@@ -18,6 +18,18 @@ This command may be run in different scenarios:
18
18
 
19
19
  Before making changes, use the `memory` tool to inspect your current memory blocks and understand what already exists.
20
20
 
21
+ ## Memory Migration Option
22
+
23
+ If you're setting up a new agent that should inherit memory from an existing agent, consider using the `migrating-memory` skill:
24
+
25
+ 1. Load the skill: `Skill({ command: "load", skills: ["migrating-memory"] })`
26
+ 2. Follow its workflow to copy or share blocks from another agent
27
+
28
+ **When to suggest migration**:
29
+ - User mentions they have an existing agent with useful memory
30
+ - User is replacing an old agent with a new one
31
+ - User wants to share memory blocks across multiple agents
32
+
21
33
  ## What Coding Agents Should Remember
22
34
 
23
35
  ### 1. Procedures (Rules & Workflows)
@@ -0,0 +1,132 @@
1
+ ---
2
+ name: migrating-memory
3
+ description: Migrate memory blocks from an existing agent to the current agent. Use when the user wants to copy or share memory from another agent, or during /init when setting up a new agent that should inherit memory from an existing one.
4
+ ---
5
+
6
+ # Migrating Memory
7
+
8
+ This skill helps migrate memory blocks from an existing agent to a new agent, similar to macOS Migration Assistant for AI agents.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - User is setting up a new agent that should inherit memory from an existing one
13
+ - User wants to share memory blocks across multiple agents
14
+ - User is replacing an old agent with a new one
15
+ - User mentions they have an existing agent with useful memory
16
+
17
+ ## Migration Methods
18
+
19
+ ### 1. Manual Copy (Recommended for partial content)
20
+
21
+ If you only need **part** of a source block, or the source is messy and needs cleanup:
22
+ 1. Use `get-agent-blocks.ts` to view the source block's content
23
+ 2. Use the `memory` tool to create a new block with just the content you want
24
+ 3. No scripts needed - you have full control over what gets copied
25
+
26
+ Best for: Extracting sections, cleaning up messy content, selective migration.
27
+
28
+ ### 2. Script Copy (Full block duplication)
29
+
30
+ Creates new blocks with the same content using `copy-block.ts`. After copying:
31
+ - You own the copy - changes don't sync
32
+ - Use `--label` flag if you already have a block with that label
33
+ - Best for: One-time migration, forking an agent
34
+
35
+ ### 3. Share (Linked Blocks)
36
+
37
+ Attaches the same block to multiple agents using `attach-block.ts`. After sharing:
38
+ - All agents see the same block content
39
+ - Changes by any agent are visible to all others
40
+ - Can be read-only (target can read but not modify)
41
+ - Best for: Shared knowledge bases, synchronized state
42
+
43
+ **Note:** You cannot have two blocks with the same label. When copying, use `--label` to rename if needed.
44
+
45
+ ## Workflow
46
+
47
+ ### Step 1: Identify Source Agent
48
+
49
+ Ask the user for the source agent's ID (e.g., `agent-abc123`).
50
+
51
+ If they don't know the ID, load the **finding-agents** skill to search:
52
+ ```
53
+ Skill({ command: "load", skills: ["finding-agents"] })
54
+ ```
55
+
56
+ Example: "What's the ID of the agent you want to migrate memory from?"
57
+
58
+ ### Step 2: View Source Agent's Blocks
59
+
60
+ Inspect what memory blocks the source agent has:
61
+
62
+ ```bash
63
+ npx ts-node scripts/get-agent-blocks.ts --agent-id <source-agent-id>
64
+ ```
65
+
66
+ This shows each block's ID, label, description, and value.
67
+
68
+ ### Step 3: Migrate Blocks
69
+
70
+ For each block you want to migrate, choose copy or share:
71
+
72
+ **To Copy (create independent block):**
73
+ ```bash
74
+ npx ts-node scripts/copy-block.ts --block-id <block-id> [--label <new-label>]
75
+ ```
76
+
77
+ Use `--label` if you already have a block with that label (e.g., `--label project-imported`).
78
+
79
+ **To Share (attach existing block):**
80
+ ```bash
81
+ npx ts-node scripts/attach-block.ts --block-id <block-id>
82
+ ```
83
+
84
+ Add `--read-only` flag to share to make this agent unable to modify the block.
85
+
86
+ Note: These scripts automatically target the current agent (you) for safety.
87
+
88
+ ## Script Reference
89
+
90
+ All scripts are located in the `scripts/` directory and output raw API responses (JSON).
91
+
92
+ | Script | Purpose | Args |
93
+ |--------|---------|------|
94
+ | `get-agent-blocks.ts` | Get blocks from an agent | `--agent-id` |
95
+ | `copy-block.ts` | Copy block to current agent | `--block-id`, optional `--label` |
96
+ | `attach-block.ts` | Attach existing block to current agent | `--block-id`, optional `--read-only` |
97
+
98
+ ## Authentication
99
+
100
+ The bundled scripts automatically use the same authentication as Letta Code:
101
+ - Keychain/secrets storage
102
+ - `~/.config/letta/settings.json` fallback
103
+ - `LETTA_API_KEY` environment variable
104
+
105
+ You can also make direct API calls using the Letta SDK if you have the API key available.
106
+
107
+ ## Example: Migrating Project Memory
108
+
109
+ Scenario: You're a new agent and want to inherit memory from an existing agent "ProjectX-v1".
110
+
111
+ 1. **Get source agent ID from user:**
112
+ User provides: `agent-abc123`
113
+
114
+ 2. **List its blocks:**
115
+ ```bash
116
+ npx ts-node scripts/get-agent-blocks.ts --agent-id agent-abc123
117
+ # Shows: project (block-def456), human (block-ghi789), persona (block-jkl012)
118
+ ```
119
+
120
+ 3. **Copy project knowledge to yourself:**
121
+ ```bash
122
+ # If you don't have a 'project' block yet:
123
+ npx ts-node scripts/copy-block.ts --block-id block-def456
124
+
125
+ # If you already have 'project', use --label to rename:
126
+ npx ts-node scripts/copy-block.ts --block-id block-def456 --label project-v1
127
+ ```
128
+
129
+ 4. **Optionally share human preferences (read-only):**
130
+ ```bash
131
+ npx ts-node scripts/attach-block.ts --block-id block-ghi789 --read-only
132
+ ```
@@ -0,0 +1,100 @@
1
+ #!/usr/bin/env npx ts-node
2
+ /**
3
+ * Attach Block - Attaches an existing memory block to an agent (sharing)
4
+ *
5
+ * Usage:
6
+ * npx ts-node attach-block.ts --block-id <block-id> --target-agent-id <agent-id> [--read-only]
7
+ *
8
+ * This attaches an existing block to another agent, making it shared.
9
+ * Changes to the block will be visible to all agents that have it attached.
10
+ *
11
+ * Options:
12
+ * --read-only Target agent can read but not modify the block
13
+ *
14
+ * Output:
15
+ * Raw API response from the attach operation
16
+ */
17
+
18
+ import type Letta from "@letta-ai/letta-client";
19
+ import { getClient } from "../../../../agent/client";
20
+ import { getCurrentAgentId } from "../../../../agent/context";
21
+ import { settingsManager } from "../../../../settings-manager";
22
+
23
+ /**
24
+ * Attach an existing block to the current agent (sharing it)
25
+ * @param client - Letta client instance
26
+ * @param blockId - The block ID to attach
27
+ * @param readOnly - Whether this agent should have read-only access
28
+ * @param targetAgentId - Optional target agent ID (defaults to current agent)
29
+ * @returns API response from the attach operation
30
+ */
31
+ export async function attachBlock(
32
+ client: Letta,
33
+ blockId: string,
34
+ readOnly = false,
35
+ targetAgentId?: string,
36
+ ): Promise<Awaited<ReturnType<typeof client.agents.blocks.attach>>> {
37
+ // Get current agent ID (the agent calling this script) or use provided ID
38
+ const currentAgentId = targetAgentId ?? getCurrentAgentId();
39
+
40
+ const result = await client.agents.blocks.attach(blockId, {
41
+ agent_id: currentAgentId,
42
+ });
43
+
44
+ // If read-only is requested, update the block's read_only flag for this agent
45
+ // Note: This may require a separate API call depending on how read_only works
46
+ if (readOnly) {
47
+ // The read_only flag is per-block, not per-agent attachment
48
+ // For now, we'll note this in the output
49
+ console.warn(
50
+ "Note: read_only flag is set on the block itself, not per-agent. " +
51
+ "Use the block update API to set read_only if needed.",
52
+ );
53
+ }
54
+
55
+ return result;
56
+ }
57
+
58
+ function parseArgs(args: string[]): {
59
+ blockId: string;
60
+ readOnly: boolean;
61
+ } {
62
+ const blockIdIndex = args.indexOf("--block-id");
63
+ const readOnly = args.includes("--read-only");
64
+
65
+ if (blockIdIndex === -1 || blockIdIndex + 1 >= args.length) {
66
+ throw new Error("Missing required argument: --block-id <block-id>");
67
+ }
68
+
69
+ return {
70
+ blockId: args[blockIdIndex + 1] as string,
71
+ readOnly,
72
+ };
73
+ }
74
+
75
+ // CLI entry point
76
+ if (require.main === module) {
77
+ (async () => {
78
+ try {
79
+ const { blockId, readOnly } = parseArgs(process.argv.slice(2));
80
+ await settingsManager.initialize();
81
+ const client = await getClient();
82
+ const result = await attachBlock(client, blockId, readOnly);
83
+ console.log(JSON.stringify(result, null, 2));
84
+ } catch (error) {
85
+ console.error(
86
+ "Error:",
87
+ error instanceof Error ? error.message : String(error),
88
+ );
89
+ if (
90
+ error instanceof Error &&
91
+ error.message.includes("Missing required argument")
92
+ ) {
93
+ console.error(
94
+ "\nUsage: npx ts-node attach-block.ts --block-id <block-id> [--read-only]",
95
+ );
96
+ }
97
+ process.exit(1);
98
+ }
99
+ })();
100
+ }
@@ -0,0 +1,108 @@
1
+ #!/usr/bin/env npx ts-node
2
+ /**
3
+ * Copy Block - Copies a memory block to create a new independent block for the current agent
4
+ *
5
+ * Usage:
6
+ * npx ts-node copy-block.ts --block-id <block-id> [--label <new-label>]
7
+ *
8
+ * Options:
9
+ * --label Override the block label (required if you already have a block with that label)
10
+ *
11
+ * This creates a new block with the same content as the source block,
12
+ * then attaches it to the current agent. Changes to the new block
13
+ * won't affect the original.
14
+ *
15
+ * Output:
16
+ * Raw API response from each step (retrieve, create, attach)
17
+ */
18
+
19
+ import type Letta from "@letta-ai/letta-client";
20
+ import { getClient } from "../../../../agent/client";
21
+ import { getCurrentAgentId } from "../../../../agent/context";
22
+ import { settingsManager } from "../../../../settings-manager";
23
+
24
+ interface CopyBlockResult {
25
+ sourceBlock: Awaited<ReturnType<typeof Letta.prototype.blocks.retrieve>>;
26
+ newBlock: Awaited<ReturnType<typeof Letta.prototype.blocks.create>>;
27
+ attachResult: Awaited<
28
+ ReturnType<typeof Letta.prototype.agents.blocks.attach>
29
+ >;
30
+ }
31
+
32
+ /**
33
+ * Copy a block's content to a new block and attach to the current agent
34
+ * @param client - Letta client instance
35
+ * @param blockId - The source block ID to copy from
36
+ * @param options - Optional settings: labelOverride, targetAgentId
37
+ * @returns Object containing source block, new block, and attach result
38
+ */
39
+ export async function copyBlock(
40
+ client: Letta,
41
+ blockId: string,
42
+ options?: { labelOverride?: string; targetAgentId?: string },
43
+ ): Promise<CopyBlockResult> {
44
+ // Get current agent ID (the agent calling this script) or use provided ID
45
+ const currentAgentId = options?.targetAgentId ?? getCurrentAgentId();
46
+
47
+ // 1. Get source block details
48
+ const sourceBlock = await client.blocks.retrieve(blockId);
49
+
50
+ // 2. Create new block with same content (optionally override label)
51
+ const newBlock = await client.blocks.create({
52
+ label: options?.labelOverride || sourceBlock.label || "migrated-block",
53
+ value: sourceBlock.value,
54
+ description: sourceBlock.description || undefined,
55
+ limit: sourceBlock.limit,
56
+ });
57
+
58
+ // 3. Attach new block to current agent
59
+ const attachResult = await client.agents.blocks.attach(newBlock.id, {
60
+ agent_id: currentAgentId,
61
+ });
62
+
63
+ return { sourceBlock, newBlock, attachResult };
64
+ }
65
+
66
+ function parseArgs(args: string[]): { blockId: string; label?: string } {
67
+ const blockIdIndex = args.indexOf("--block-id");
68
+ const labelIndex = args.indexOf("--label");
69
+
70
+ if (blockIdIndex === -1 || blockIdIndex + 1 >= args.length) {
71
+ throw new Error("Missing required argument: --block-id <block-id>");
72
+ }
73
+
74
+ return {
75
+ blockId: args[blockIdIndex + 1] as string,
76
+ label:
77
+ labelIndex !== -1 && labelIndex + 1 < args.length
78
+ ? (args[labelIndex + 1] as string)
79
+ : undefined,
80
+ };
81
+ }
82
+
83
+ // CLI entry point
84
+ if (require.main === module) {
85
+ (async () => {
86
+ try {
87
+ const { blockId, label } = parseArgs(process.argv.slice(2));
88
+ await settingsManager.initialize();
89
+ const client = await getClient();
90
+ const result = await copyBlock(client, blockId, { labelOverride: label });
91
+ console.log(JSON.stringify(result, null, 2));
92
+ } catch (error) {
93
+ console.error(
94
+ "Error:",
95
+ error instanceof Error ? error.message : String(error),
96
+ );
97
+ if (
98
+ error instanceof Error &&
99
+ error.message.includes("Missing required argument")
100
+ ) {
101
+ console.error(
102
+ "\nUsage: npx ts-node copy-block.ts --block-id <block-id> [--label <new-label>]",
103
+ );
104
+ }
105
+ process.exit(1);
106
+ }
107
+ })();
108
+ }
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env npx ts-node
2
+ /**
3
+ * Get Agent Blocks - Retrieves memory blocks from a specific agent
4
+ *
5
+ * Usage:
6
+ * npx ts-node get-agent-blocks.ts --agent-id <agent-id>
7
+ *
8
+ * Output:
9
+ * Raw API response from GET /v1/agents/{id}/core-memory/blocks
10
+ */
11
+
12
+ import type Letta from "@letta-ai/letta-client";
13
+ import { getClient } from "../../../../agent/client";
14
+ import { settingsManager } from "../../../../settings-manager";
15
+
16
+ /**
17
+ * Get memory blocks for a specific agent
18
+ * @param client - Letta client instance
19
+ * @param agentId - The agent ID to get blocks from
20
+ * @returns Array of block objects from the API
21
+ */
22
+ export async function getAgentBlocks(
23
+ client: Letta,
24
+ agentId: string,
25
+ ): Promise<Awaited<ReturnType<typeof client.agents.blocks.list>>> {
26
+ return await client.agents.blocks.list(agentId);
27
+ }
28
+
29
+ function parseArgs(args: string[]): { agentId: string } {
30
+ const agentIdIndex = args.indexOf("--agent-id");
31
+ if (agentIdIndex === -1 || agentIdIndex + 1 >= args.length) {
32
+ throw new Error("Missing required argument: --agent-id <agent-id>");
33
+ }
34
+ return { agentId: args[agentIdIndex + 1] as string };
35
+ }
36
+
37
+ // CLI entry point
38
+ if (require.main === module) {
39
+ (async () => {
40
+ try {
41
+ const { agentId } = parseArgs(process.argv.slice(2));
42
+ await settingsManager.initialize();
43
+ const client = await getClient();
44
+ const result = await getAgentBlocks(client, agentId);
45
+ console.log(JSON.stringify(result, null, 2));
46
+ } catch (error) {
47
+ console.error(
48
+ "Error:",
49
+ error instanceof Error ? error.message : String(error),
50
+ );
51
+ if (
52
+ error instanceof Error &&
53
+ error.message.includes("Missing required argument")
54
+ ) {
55
+ console.error(
56
+ "\nUsage: npx ts-node get-agent-blocks.ts --agent-id <agent-id>",
57
+ );
58
+ }
59
+ process.exit(1);
60
+ }
61
+ })();
62
+ }