fix: memory blocks config on createAgent (#21)

This commit is contained in:
Christina Tong
2026-02-03 16:44:05 -08:00
committed by GitHub
parent 4cb8af7be8
commit 5f37e513c8
5 changed files with 41 additions and 100 deletions

View File

@@ -258,14 +258,20 @@ export class SubprocessTransport {
}
}
// Add preset names via --init-blocks
if (presetNames.length > 0) {
args.push("--init-blocks", presetNames.join(","));
}
// Add custom blocks and block references via --memory-blocks
// NOTE: When custom blocks are provided via --memory-blocks, they define the complete
// memory configuration. Preset blocks (--init-blocks) cannot be mixed with custom blocks.
if (memoryBlocksJson.length > 0) {
// Use custom blocks only
args.push("--memory-blocks", JSON.stringify(memoryBlocksJson));
if (presetNames.length > 0) {
console.warn(
"[letta-code-sdk] Using custom memory blocks. " +
`Preset blocks are ignored when custom blocks are provided: ${presetNames.join(", ")}`
);
}
} else if (presetNames.length > 0) {
// Use presets only
args.push("--init-blocks", presetNames.join(","));
}
}
}
@@ -278,9 +284,6 @@ export class SubprocessTransport {
if (this.options.human !== undefined) {
args.push("--block-value", `human=${this.options.human}`);
}
if (this.options.project !== undefined) {
args.push("--block-value", `project=${this.options.project}`);
}
}
// Permission mode

View File

@@ -113,7 +113,7 @@ export type MemoryItem =
/**
* Default memory block preset names.
*/
export type MemoryPreset = "persona" | "human" | "project";
export type MemoryPreset = "persona" | "human" | "skills" | "loaded_skills";
// ═══════════════════════════════════════════════════════════════
// SESSION OPTIONS
@@ -147,9 +147,8 @@ export interface InternalSessionOptions {
// Memory blocks (only for new agents)
memory?: MemoryItem[];
persona?: string;
human?: string;
project?: string;
persona?: string; // Convenience for persona block
human?: string; // Convenience for human block
// Permissions
allowedTools?: string[];
@@ -203,8 +202,8 @@ export interface CreateAgentOptions {
/**
* Memory block configuration. Each item can be:
* - string: Preset block name ("project", "persona", "human")
* - CreateBlock: Custom block definition
* - string: Preset block name ("persona", "human", "skills", "loaded_skills")
* - CreateBlock: Custom block definition (e.g., { label: "project", value: "..." })
* - { blockId: string }: Reference to existing shared block
*/
memory?: MemoryItem[];
@@ -215,9 +214,6 @@ export interface CreateAgentOptions {
/** Convenience: Set human block value directly */
human?: string;
/** Convenience: Set project block value directly */
project?: string;
/** List of allowed tool names */
allowedTools?: string[];

View File

@@ -77,13 +77,6 @@ export function validateCreateAgentOptions(options: CreateAgentOptions): void {
"Either add 'human' to memory array or remove the human option."
);
}
if (options.project !== undefined && !blockLabels.includes("project")) {
throw new Error(
"Cannot set 'project' value - block not included in 'memory'. " +
"Either add 'project' to memory array or remove the project option."
);
}
}
// Validate systemPrompt preset if provided as preset object