@letta-ai/letta-agent-sdk 0.5.3 → 0.5.5

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/README.md CHANGED
@@ -30,8 +30,16 @@ const client = new LettaAgentClient({
30
30
 
31
31
  const agentId = await client.createAgent({
32
32
  model: "anthropic/claude-opus-4-8",
33
- persona: "You are a proactive research assistant.",
34
- human: "The user prefers concise summaries with sources and next steps.",
33
+ memory: [
34
+ {
35
+ label: "persona",
36
+ value: "You are a proactive research assistant.",
37
+ },
38
+ {
39
+ label: "human",
40
+ value: "The user prefers concise summaries with sources and next steps.",
41
+ },
42
+ ],
35
43
  });
36
44
 
37
45
  await using session = client.createSession(agentId);
@@ -44,6 +52,10 @@ for await (const message of session.stream()) {
44
52
  }
45
53
  ```
46
54
 
55
+ `createAgent()` uses the supplied memory as the agent's identity. Letta Code
56
+ personality presets are opt-in: pass `personality: "memo"` (or another preset)
57
+ only when you want that preset's name, description, and memory blocks.
58
+
47
59
  An agent is the persistent entity with memory. A conversation is a thread on that agent. A session is the active connection used to send messages, stream events, execute tools, and handle approvals.
48
60
 
49
61
  - `createSession(agentId)` starts a new conversation.
@@ -0,0 +1,9 @@
1
+ import type { CreateAgentOptions } from "./types.js";
2
+ /**
3
+ * Build the standard harness portion of a create-agent request.
4
+ *
5
+ * Personality presets are explicit opt-ins. Without one, the SDK builds a
6
+ * generic agent and lets the caller's memory blocks define its identity.
7
+ */
8
+ export declare function buildInitialAgentBody(options: CreateAgentOptions): Promise<Record<string, unknown>>;
9
+ //# sourceMappingURL=agent-creation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent-creation.d.ts","sourceRoot":"","sources":["../src/agent-creation.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAmBrD;;;;;GAKG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAA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e,EACzD,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,OAAO,GAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,OAAO,CAAA;KAAO,GACtF,OAAO,CAAC,SAAS,CAAC;IAqBf,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IASvC,WAAW,CACf,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC;IAYvB,uBAAuB,CAC3B,OAAO,EAAE,YAAY,EACrB,OAAO,GAAE,8BAAmC,GAC3C,OAAO,CAAC,6BAA6B,CAAC;IAqBnC,YAAY,CAChB,cAAc,EAAE,MAAM,EACtB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,kBAAkB,CAAC;IAwC9B,KAAK,IAAI,IAAI;CAGd;AAED,qBAAa,gBAAiB,SAAQ,uBAAuB;IAOzD,OAAO,CAAC,QAAQ,CAAC,aAAa;IANhC,OAAO,CAAC,eAAe,CAAkC;IACzD,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,yBAAyB,CAA6B;IAC9D,OAAO,CAAC,2BAA2B,CAA6B;gBAG7C,aAAa,EAAE,uBAAuB,EACvD,IAAI,EAAE,oBAAoB;cAYT,iBAAiB,CAAC,OAAO,EAAE,6BAA6B,GAAG,kBAAkB,GAAG,OAAO;cAKjF,2BAA2B,IAAI,OAAO,CAAC,kBAAkB,CAAC;cA0DhE,WAAW,IAAI,IAAI;YASxB,mBAAmB;YAenB,YAAY;YAOZ,wBAAwB;YAiExB,0BAA0B;CAqBzC"}
@@ -8271,6 +8271,7 @@ var models_default = {
8271
8271
  ]
8272
8272
  };
8273
8273
  var models = models_default.models;
8274
+ var MODEL_PRESETS = models;
8274
8275
  function resolveModel(modelIdentifier) {
8275
8276
  const byId = models.find((m) => m.id === modelIdentifier);
8276
8277
  if (byId)
@@ -8530,6 +8531,45 @@ async function buildCreateAgentRequestForPersonality(params) {
8530
8531
  };
8531
8532
  }
8532
8533
 
8534
+ // src/agent-creation.ts
8535
+ var DEFAULT_MODEL_ID = "auto";
8536
+ var DEFAULT_SUMMARIZATION_MODEL2 = "letta/auto";
8537
+ function resolveModel2(modelIdentifier) {
8538
+ const preset = MODEL_PRESETS.find((model) => model.id === modelIdentifier || model.handle === modelIdentifier);
8539
+ if (preset)
8540
+ return preset.handle;
8541
+ if (modelIdentifier.includes("/"))
8542
+ return modelIdentifier;
8543
+ throw new Error(`Unknown model: ${modelIdentifier}`);
8544
+ }
8545
+ async function buildInitialAgentBody(options) {
8546
+ if (options.personality !== undefined) {
8547
+ return {
8548
+ ...await buildCreateAgentRequestForPersonality({
8549
+ personalityId: options.personality,
8550
+ ...options.name !== undefined ? { name: options.name } : {},
8551
+ ...options.description !== undefined ? { description: options.description } : {},
8552
+ ...options.model !== undefined ? { model: options.model } : {},
8553
+ ...options.tags !== undefined ? { extraTags: options.tags } : {}
8554
+ })
8555
+ };
8556
+ }
8557
+ return {
8558
+ agent_type: LETTA_CODE_AGENT_TYPE,
8559
+ ...options.name !== undefined ? { name: options.name } : {},
8560
+ ...options.description !== undefined ? { description: options.description } : {},
8561
+ model: resolveModel2(options.model ?? DEFAULT_MODEL_ID),
8562
+ system: buildSystemPrompt("default", "memfs"),
8563
+ tags: buildCreatedAgentTags({
8564
+ enableMemfs: true,
8565
+ tags: options.tags ?? []
8566
+ }),
8567
+ initial_message_sequence: [],
8568
+ parallel_tool_calls: true,
8569
+ compaction_settings: { model: DEFAULT_SUMMARIZATION_MODEL2 }
8570
+ };
8571
+ }
8572
+
8533
8573
  // src/interactiveToolPolicy.ts
8534
8574
  var INTERACTIVE_APPROVAL_TOOLS = new Set([
8535
8575
  "AskUserQuestion",
@@ -8981,6 +9021,7 @@ function normalizeSendMessage(message) {
8981
9021
  class RemoteTurnCoordinator {
8982
9022
  label;
8983
9023
  requestTimeoutMs;
9024
+ autoHandlesToolApprovals;
8984
9025
  onDeviceStatus;
8985
9026
  streamQueue = [];
8986
9027
  streamResolvers = [];
@@ -8994,6 +9035,7 @@ class RemoteTurnCoordinator {
8994
9035
  constructor(config) {
8995
9036
  this.label = config.label;
8996
9037
  this.requestTimeoutMs = config.requestTimeoutMs;
9038
+ this.autoHandlesToolApprovals = config.autoHandlesToolApprovals === true;
8997
9039
  this.onDeviceStatus = config.onDeviceStatus;
8998
9040
  }
8999
9041
  get activeTurnStartedAt() {
@@ -9170,6 +9212,8 @@ class RemoteTurnCoordinator {
9170
9212
  if (!hadTurnEvidence)
9171
9213
  return;
9172
9214
  if (status === "WAITING_ON_APPROVAL") {
9215
+ if (this.autoHandlesToolApprovals)
9216
+ return;
9173
9217
  this.completeActiveTurn({
9174
9218
  runtime: active.runtime,
9175
9219
  stopReason: "requires_approval",
@@ -9407,6 +9451,7 @@ class RemoteClientSessionCore {
9407
9451
  this.turns = new RemoteTurnCoordinator({
9408
9452
  label: config.label,
9409
9453
  requestTimeoutMs: config.requestTimeoutMs,
9454
+ autoHandlesToolApprovals: mode.kind === "session" && typeof mode.options.canUseTool === "function",
9410
9455
  onDeviceStatus: (status) => this.emitDeviceStatus(status)
9411
9456
  });
9412
9457
  }
@@ -9981,15 +10026,7 @@ function upsertMemoryBlock(blocks, block) {
9981
10026
  async function createAgentBody(options, settings = {}) {
9982
10027
  assertRemoteCreateAgentOptionsSupported(options);
9983
10028
  const includeOriginTag = settings.includeSdkOriginTag ?? true;
9984
- const body = {
9985
- ...await buildCreateAgentRequestForPersonality({
9986
- personalityId: options.personality ?? "memo",
9987
- ...options.name !== undefined ? { name: options.name } : {},
9988
- ...options.description !== undefined ? { description: options.description } : {},
9989
- ...options.model !== undefined ? { model: options.model } : {},
9990
- ...options.tags !== undefined ? { extraTags: options.tags } : {}
9991
- })
9992
- };
10029
+ const body = await buildInitialAgentBody(options);
9993
10030
  if (Array.isArray(body.tags)) {
9994
10031
  body.tags = body.tags.filter((tag) => (includeOriginTag || tag !== LETTA_CODE_ORIGIN_TAG) && (options.memfs !== false || tag !== GIT_MEMORY_ENABLED_TAG));
9995
10032
  }
@@ -10020,6 +10057,7 @@ async function createAgentBody(options, settings = {}) {
10020
10057
  throw new Error("createAgent() does not yet support system prompt preset objects for this backend.");
10021
10058
  }
10022
10059
  }
10060
+ const hasMemoryConfiguration = Array.isArray(body.memory_blocks) || options.memory !== undefined || options.persona !== undefined || options.human !== undefined;
10023
10061
  const memoryBlocks = Array.isArray(body.memory_blocks) ? body.memory_blocks.filter((block) => block !== null && typeof block === "object").map((block) => ({ ...block })) : [];
10024
10062
  const blockIds = [];
10025
10063
  for (const item of options.memory ?? []) {
@@ -10041,7 +10079,8 @@ async function createAgentBody(options, settings = {}) {
10041
10079
  if (options.human !== undefined) {
10042
10080
  upsertMemoryBlock(memoryBlocks, { label: "human", value: options.human });
10043
10081
  }
10044
- body.memory_blocks = memoryBlocks;
10082
+ if (hasMemoryConfiguration)
10083
+ body.memory_blocks = memoryBlocks;
10045
10084
  if (blockIds.length > 0)
10046
10085
  body.block_ids = blockIds;
10047
10086
  return body;
@@ -10178,37 +10217,72 @@ function runtimeScopeFromMessage(message) {
10178
10217
  }
10179
10218
  return null;
10180
10219
  }
10181
- function registerAppServerControlRequestHandler(config) {
10182
- return config.client.onMessage((rawMessage, channel) => {
10183
- const message = rawMessage;
10184
- if (channel !== "control" || message.type !== "control_request")
10185
- return;
10186
- respondToAppServerControlRequest(config, message).catch(() => {});
10187
- });
10188
- }
10189
- async function respondToAppServerControlRequest(config, message) {
10190
- const runtime = runtimeScopeFromMessage(message) ?? config.getRuntime();
10191
- if (!runtime)
10192
- return;
10193
- const requestId = typeof message.request_id === "string" ? message.request_id : undefined;
10220
+ var MAX_CACHED_TOOL_APPROVALS = 256;
10221
+ function parseToolApprovalRequest(message, fallbackRuntime) {
10222
+ const runtime = runtimeScopeFromMessage(message) ?? fallbackRuntime;
10223
+ const requestId = typeof message.request_id === "string" ? message.request_id : null;
10194
10224
  const request = message.request;
10195
- if (!requestId || !request || typeof request !== "object")
10196
- return;
10225
+ if (!runtime || !requestId || !request || typeof request !== "object")
10226
+ return null;
10197
10227
  const requestRecord = request;
10198
10228
  if (requestRecord.subtype !== "can_use_tool")
10199
- return;
10229
+ return null;
10200
10230
  const toolName = typeof requestRecord.tool_name === "string" ? requestRecord.tool_name : "unknown";
10201
10231
  const toolInput = requestRecord.input && typeof requestRecord.input === "object" && !Array.isArray(requestRecord.input) ? requestRecord.input : {};
10202
- const decision = await resolveAppServerToolApproval(config.getOptions(), toolName, toolInput, buildCanUseToolContext(requestRecord, requestId));
10203
- config.client.input({
10232
+ return {
10233
+ key: JSON.stringify([runtime.agent_id, runtime.conversation_id, requestId]),
10204
10234
  runtime,
10235
+ requestId,
10236
+ toolName,
10237
+ toolInput,
10238
+ context: buildCanUseToolContext(requestRecord, requestId)
10239
+ };
10240
+ }
10241
+ function sendToolApprovalResponse(client, request, decision) {
10242
+ client.input({
10243
+ runtime: request.runtime,
10205
10244
  payload: {
10206
10245
  kind: "approval_response",
10207
- request_id: requestId,
10246
+ request_id: request.requestId,
10208
10247
  decision: toAppServerApprovalDecision(decision)
10209
10248
  }
10210
10249
  });
10211
10250
  }
10251
+ function registerAppServerControlRequestHandler(config) {
10252
+ const approvals = new Map;
10253
+ return config.client.onMessage((rawMessage, channel) => {
10254
+ const message = rawMessage;
10255
+ if (channel !== "control" || message.type !== "control_request")
10256
+ return;
10257
+ const request = parseToolApprovalRequest(message, config.getRuntime());
10258
+ if (!request)
10259
+ return;
10260
+ const cached = approvals.get(request.key);
10261
+ if (cached) {
10262
+ if (cached.sent) {
10263
+ cached.decision.then((decision) => sendToolApprovalResponse(config.client, cached.request, decision)).catch(() => {
10264
+ return;
10265
+ });
10266
+ }
10267
+ return;
10268
+ }
10269
+ if (approvals.size >= MAX_CACHED_TOOL_APPROVALS) {
10270
+ const oldest = approvals.keys().next().value;
10271
+ if (oldest !== undefined)
10272
+ approvals.delete(oldest);
10273
+ }
10274
+ const entry = {
10275
+ decision: resolveAppServerToolApproval(config.getOptions(), request.toolName, request.toolInput, request.context),
10276
+ sent: false,
10277
+ request
10278
+ };
10279
+ approvals.set(request.key, entry);
10280
+ entry.decision.then((decision) => {
10281
+ entry.sent = true;
10282
+ sendToolApprovalResponse(config.client, request, decision);
10283
+ }).catch(() => approvals.delete(request.key));
10284
+ });
10285
+ }
10212
10286
 
10213
10287
  class AppServerRuntimeController {
10214
10288
  client;
@@ -12135,4 +12209,4 @@ export {
12135
12209
  CloudManagedSandboxExpiredError
12136
12210
  };
12137
12211
 
12138
- //# debugId=BAE3E396031D003F64756E2164756E21
12212
+ //# debugId=8B8DDE1B1EDE2B4764756E2164756E21