@letta-ai/letta-agent-sdk 0.8.3 → 0.8.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 +5 -0
- package/dist/app-server-management.d.ts +4 -0
- package/dist/app-server-management.d.ts.map +1 -1
- package/dist/client-base.d.ts +12 -1
- package/dist/client-base.d.ts.map +1 -1
- package/dist/client-entry.js +213 -15
- package/dist/client-entry.js.map +10 -10
- package/dist/cloud-management.d.ts +1 -0
- package/dist/cloud-management.d.ts.map +1 -1
- package/dist/computers.d.ts +2 -1
- package/dist/computers.d.ts.map +1 -1
- package/dist/index.js +238 -56
- package/dist/index.js.map +11 -11
- package/dist/management.d.ts +1 -0
- package/dist/management.d.ts.map +1 -1
- package/dist/repositories.d.ts +2 -1
- package/dist/repositories.d.ts.map +1 -1
- package/dist/tests/fixtures/client-management-exit.d.ts +2 -0
- package/dist/tests/fixtures/client-management-exit.d.ts.map +1 -0
- package/package.json +3 -3
- package/src/app-server-management.ts +48 -3
- package/src/client-base.ts +41 -2
- package/src/cloud-management.ts +4 -0
- package/src/computers.ts +7 -1
- package/src/management.ts +1 -0
- package/src/repositories.ts +2 -0
package/README.md
CHANGED
|
@@ -32,6 +32,11 @@ for await (const message of session.stream()) {
|
|
|
32
32
|
}
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
+
Local and remote management clients can use `await using client = new
|
|
36
|
+
LettaAgentClient(...)`, or call `await client.close()` explicitly. Client
|
|
37
|
+
disposal closes its pooled management connection and any local App Server it
|
|
38
|
+
started. Sessions are independently owned and must still be closed separately.
|
|
39
|
+
|
|
35
40
|
Latency-sensitive applications can initialize the runtime and transport before
|
|
36
41
|
the first user action without fetching transcript history or invoking the model:
|
|
37
42
|
|
|
@@ -23,7 +23,10 @@ export declare class AppServerManagementTransport implements ManagementTransport
|
|
|
23
23
|
private readonly options;
|
|
24
24
|
private connectionPromise;
|
|
25
25
|
private closingConnections;
|
|
26
|
+
private closed;
|
|
27
|
+
private closePromise;
|
|
26
28
|
constructor(options: AppServerManagementOptions);
|
|
29
|
+
close(): Promise<void>;
|
|
27
30
|
listAgents(query: AgentListParams): Promise<LettaAgent[]>;
|
|
28
31
|
retrieveAgent(agentId: string): Promise<LettaAgent>;
|
|
29
32
|
updateAgent(agentId: string, body: AgentUpdateParams): Promise<LettaAgent>;
|
|
@@ -39,6 +42,7 @@ export declare class AppServerManagementTransport implements ManagementTransport
|
|
|
39
42
|
private request;
|
|
40
43
|
private acquireConnection;
|
|
41
44
|
private openConnection;
|
|
45
|
+
private assertOpen;
|
|
42
46
|
private discardConnection;
|
|
43
47
|
private trackClosingConnection;
|
|
44
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app-server-management.d.ts","sourceRoot":"","sources":["../src/app-server-management.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,gDAAgD,CAAC;AACxD,OAAO,KAAK,EACV,wBAAwB,EACxB,sBAAsB,EACtB,sBAAsB,EACtB,wBAAwB,EACzB,MAAM,8DAA8D,CAAC;AACtE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yDAAyD,CAAC;AAGjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAE3D,OAAO,KAAK,EACV,0BAA0B,EAC1B,UAAU,EACV,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,4BAA4B,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEjF,KAAK,eAAe,GAAG;IAAE,GAAG,EAAE,MAAM,CAAC;IAAC,KAAK,IAAI,IAAI,CAAA;CAAE,CAAC;AAEtD,MAAM,MAAM,0BAA0B,GACpC,OAAO,CAAC,4BAA4B,CAAC,GAAG;IACtC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC,eAAe,CAAC,CAAC;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AAC,UAAU,CAAC;IAanD,WAAW,CACf,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,iBAAiB,GACtB,OAAO,CAAC,UAAU,CAAC;IAahB,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAW3C,UAAU,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAWvC,iBAAiB,CACrB,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAYzB,oBAAoB,CACxB,cAAc,EAAE,MAAM,GACrB,OAAO,CAAC,iBAAiB,CAAC;IAavB,kBAAkB,CACtB,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAavB,kBAAkB,CACtB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,wBAAwB,GAC7B,OAAO,CAAC,iBAAiB,CAAC;IAavB,gBAAgB,CACpB,cAAc,EAAE,MAAM,EACtB,IAAI,EAAE,sBAAsB,GAC3B,OAAO,CAAC,iBAAiB,CAAC;IAkBvB,wBAAwB,CAC5B,cAAc,EAAE,MAAM,EACtB,KAAK,EAAE,iBAAiB,GACvB,OAAO,CAAC,0BAA0B,CAAC;IAgBtC,0BAA0B,IAAI,OAAO,CAAC,KAAK,CAAC;YAQ9B,OAAO;IA8BrB,OAAO,CAAC,iBAAiB;YA2BX,cAAc;IAgD5B,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,iBAAiB;IAUzB,OAAO,CAAC,sBAAsB;CAW/B"}
|
package/dist/client-base.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ import type { CreateAgentOptions, LettaCodeBackend, LettaCodeClientOptions, Lett
|
|
|
15
15
|
* `cloud` uses agents hosted on Letta Cloud, with an explicit remote
|
|
16
16
|
* environment or SDK-managed sandbox.
|
|
17
17
|
*/
|
|
18
|
-
export declare class LettaAgentClientBase {
|
|
18
|
+
export declare class LettaAgentClientBase implements AsyncDisposable {
|
|
19
19
|
readonly backend: LettaCodeBackend;
|
|
20
20
|
readonly computer: ComputerSelector | undefined;
|
|
21
21
|
/** @deprecated Use `computer`. */
|
|
@@ -29,6 +29,8 @@ export declare class LettaAgentClientBase {
|
|
|
29
29
|
private agentRepositoriesClient;
|
|
30
30
|
private cloudClient;
|
|
31
31
|
private managementTransport;
|
|
32
|
+
private closed;
|
|
33
|
+
private closePromise;
|
|
32
34
|
constructor(options?: LettaCodeClientOptions);
|
|
33
35
|
/**
|
|
34
36
|
* Create a new Letta Code agent with a default conversation.
|
|
@@ -82,6 +84,15 @@ export declare class LettaAgentClientBase {
|
|
|
82
84
|
private getCloudManagementTransport;
|
|
83
85
|
private getCloudClient;
|
|
84
86
|
private getManagementTransport;
|
|
87
|
+
/**
|
|
88
|
+
* Release resources owned directly by this client, including its pooled
|
|
89
|
+
* management connection and any local App Server started for that pool.
|
|
90
|
+
* Sessions have independent lifecycles and must be closed separately.
|
|
91
|
+
*/
|
|
92
|
+
close(): Promise<void>;
|
|
93
|
+
/** Async-disposal alias for close(). */
|
|
94
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
95
|
+
private assertOpen;
|
|
85
96
|
private cloudOptions;
|
|
86
97
|
}
|
|
87
98
|
//# sourceMappingURL=client-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client-base.d.ts","sourceRoot":"","sources":["../src/client-base.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAqB,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAS9E,OAAO,EAEL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACrB,MAAM,gBAAgB,CAAC;AAOxB,OAAO,EAIL,KAAK,mBAAmB,EACzB,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAEV,YAAY,EACZ,mBAAmB,EACnB,YAAY,EACb,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EACV,qBAAqB,E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,aAAa,EAAE,qBAAqB,EACpC,eAAe,EAAE,6BAA6B,GAC7C,gBAAgB;IAInB,SAAS,CAAC,kBAAkB,CAC1B,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,6BAA6B,GACtC,gBAAgB;IAInB,SAAS,CAAC,4BAA4B,IAAI,KAAK;IAM/C,SAAS,CAAC,8BAA8B,IAAI,mBAAmB;IAI/D,OAAO,CAAC,aAAa;IAOrB,OAAO,CAAC,uBAAuB;IAI/B,OAAO,CAAC,kBAAkB;IAW1B,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,0BAA0B;IAYlC,OAAO,CAAC,2BAA2B;IAQnC,OAAO,CAAC,cAAc;IAQtB,OAAO,CAAC,sBAAsB;IAiB9B;;;;OAIG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAUtB,wCAAwC;IAClC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC;IAI5C,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;CAMrB"}
|
package/dist/client-entry.js
CHANGED
|
@@ -1497,7 +1497,7 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path(stati
|
|
|
1497
1497
|
return statics[0];
|
|
1498
1498
|
let postPath = false;
|
|
1499
1499
|
const invalidSegments = [];
|
|
1500
|
-
const
|
|
1500
|
+
const path2 = statics.reduce((previousValue, currentValue, index) => {
|
|
1501
1501
|
if (/[?#]/.test(currentValue)) {
|
|
1502
1502
|
postPath = true;
|
|
1503
1503
|
}
|
|
@@ -1513,7 +1513,7 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path(stati
|
|
|
1513
1513
|
}
|
|
1514
1514
|
return previousValue + currentValue + (index === params.length ? "" : encoded);
|
|
1515
1515
|
}, "");
|
|
1516
|
-
const pathOnly =
|
|
1516
|
+
const pathOnly = path2.split(/[?#]/, 1)[0];
|
|
1517
1517
|
const invalidSegmentPattern = /(?<=^|\/)(?:\.|%2e){1,2}(?=\/|$)/gi;
|
|
1518
1518
|
let match;
|
|
1519
1519
|
while ((match = invalidSegmentPattern.exec(pathOnly)) !== null) {
|
|
@@ -1535,10 +1535,10 @@ var createPathTagFunction = (pathEncoder = encodeURIPath) => function path(stati
|
|
|
1535
1535
|
throw new LettaError(`Path parameters result in path with invalid segments:
|
|
1536
1536
|
${invalidSegments.map((e) => e.error).join(`
|
|
1537
1537
|
`)}
|
|
1538
|
-
${
|
|
1538
|
+
${path2}
|
|
1539
1539
|
${underline}`);
|
|
1540
1540
|
}
|
|
1541
|
-
return
|
|
1541
|
+
return path2;
|
|
1542
1542
|
};
|
|
1543
1543
|
var path = /* @__PURE__ */ createPathTagFunction(encodeURIPath);
|
|
1544
1544
|
|
|
@@ -2855,8 +2855,10 @@ function addOptionalSearchParam(url, key, value) {
|
|
|
2855
2855
|
|
|
2856
2856
|
class RepositoriesClient {
|
|
2857
2857
|
client;
|
|
2858
|
-
|
|
2858
|
+
assertOpen;
|
|
2859
|
+
constructor(options, client = createCloudClient(options), assertOpen = () => {}) {
|
|
2859
2860
|
this.client = client;
|
|
2861
|
+
this.assertOpen = assertOpen;
|
|
2860
2862
|
}
|
|
2861
2863
|
async create(params) {
|
|
2862
2864
|
return toRepository(await this.request("/v1/repositories", "POST", { name: params.name }));
|
|
@@ -2983,6 +2985,7 @@ class RepositoriesClient {
|
|
|
2983
2985
|
return this.requestUrl(this.url(path2), method, body);
|
|
2984
2986
|
}
|
|
2985
2987
|
async requestUrl(url, method, body) {
|
|
2988
|
+
this.assertOpen();
|
|
2986
2989
|
const options = body !== undefined ? { body } : undefined;
|
|
2987
2990
|
switch (method) {
|
|
2988
2991
|
case "GET":
|
|
@@ -3351,6 +3354,16 @@ class AppServerClient {
|
|
|
3351
3354
|
predicate: isAppServerInfoResponseMessage
|
|
3352
3355
|
});
|
|
3353
3356
|
}
|
|
3357
|
+
stopMonitor(command, options = {}) {
|
|
3358
|
+
return this.request({
|
|
3359
|
+
type: "monitor_stop",
|
|
3360
|
+
...command,
|
|
3361
|
+
request_id: command.request_id ?? this.nextRequestId("monitor-stop")
|
|
3362
|
+
}, {
|
|
3363
|
+
...options,
|
|
3364
|
+
predicate: (message) => message.type === "monitor_stop_response" && message.process_id === command.process_id && message.runtime.agent_id === command.runtime.agent_id && message.runtime.conversation_id === command.runtime.conversation_id
|
|
3365
|
+
});
|
|
3366
|
+
}
|
|
3354
3367
|
runtimeStart(command, options = {}) {
|
|
3355
3368
|
return this.request({
|
|
3356
3369
|
type: "runtime_start",
|
|
@@ -3391,6 +3404,16 @@ class AppServerClient {
|
|
|
3391
3404
|
predicate: (message) => message.type === "abort_message_response"
|
|
3392
3405
|
});
|
|
3393
3406
|
}
|
|
3407
|
+
resumeQueue(command, options = {}) {
|
|
3408
|
+
return this.request({
|
|
3409
|
+
type: "resume_queue",
|
|
3410
|
+
request_id: command.request_id ?? this.nextRequestId("resume-queue"),
|
|
3411
|
+
...command
|
|
3412
|
+
}, {
|
|
3413
|
+
...options,
|
|
3414
|
+
predicate: (message) => message.type === "resume_queue_response"
|
|
3415
|
+
});
|
|
3416
|
+
}
|
|
3394
3417
|
conversationList(command = {}, options = {}) {
|
|
3395
3418
|
return this.request({
|
|
3396
3419
|
type: "conversation_list",
|
|
@@ -3517,9 +3540,34 @@ class AppServerManagementTransport {
|
|
|
3517
3540
|
options;
|
|
3518
3541
|
connectionPromise = null;
|
|
3519
3542
|
closingConnections = new Set;
|
|
3543
|
+
closed = false;
|
|
3544
|
+
closePromise = null;
|
|
3520
3545
|
constructor(options) {
|
|
3521
3546
|
this.options = options;
|
|
3522
3547
|
}
|
|
3548
|
+
close() {
|
|
3549
|
+
if (this.closePromise)
|
|
3550
|
+
return this.closePromise;
|
|
3551
|
+
this.closed = true;
|
|
3552
|
+
const connectionPromise = this.connectionPromise;
|
|
3553
|
+
this.connectionPromise = null;
|
|
3554
|
+
const close = (async () => {
|
|
3555
|
+
if (connectionPromise) {
|
|
3556
|
+
let connection = null;
|
|
3557
|
+
try {
|
|
3558
|
+
connection = await connectionPromise;
|
|
3559
|
+
} catch {}
|
|
3560
|
+
if (connection) {
|
|
3561
|
+
await this.trackClosingConnection(connection);
|
|
3562
|
+
}
|
|
3563
|
+
}
|
|
3564
|
+
if (this.closingConnections.size > 0) {
|
|
3565
|
+
await Promise.all([...this.closingConnections]);
|
|
3566
|
+
}
|
|
3567
|
+
})();
|
|
3568
|
+
this.closePromise = close;
|
|
3569
|
+
return close;
|
|
3570
|
+
}
|
|
3523
3571
|
async listAgents(query) {
|
|
3524
3572
|
const response = await this.request("agent_list", { query }, "agent_list_response");
|
|
3525
3573
|
if (!response.success) {
|
|
@@ -3584,9 +3632,11 @@ class AppServerManagementTransport {
|
|
|
3584
3632
|
return Promise.reject(new Error(`conversations.enqueue() is only available with backend: "cloud". App-server backends deliver messages through a session's send().`));
|
|
3585
3633
|
}
|
|
3586
3634
|
async request(type, body, responseType) {
|
|
3635
|
+
this.assertOpen();
|
|
3587
3636
|
if (this.closingConnections.size > 0) {
|
|
3588
3637
|
await Promise.all([...this.closingConnections]);
|
|
3589
3638
|
}
|
|
3639
|
+
this.assertOpen();
|
|
3590
3640
|
const { client } = await this.acquireConnection();
|
|
3591
3641
|
return client.requestRaw({
|
|
3592
3642
|
type,
|
|
@@ -3597,12 +3647,17 @@ class AppServerManagementTransport {
|
|
|
3597
3647
|
});
|
|
3598
3648
|
}
|
|
3599
3649
|
acquireConnection() {
|
|
3650
|
+
this.assertOpen();
|
|
3600
3651
|
if (this.connectionPromise)
|
|
3601
3652
|
return this.connectionPromise;
|
|
3602
3653
|
const promise = this.openConnection().then((connection) => {
|
|
3603
3654
|
connection.detachDisconnect = connection.client.onDisconnect(() => {
|
|
3604
3655
|
this.discardConnection(promise, connection);
|
|
3605
3656
|
});
|
|
3657
|
+
if (this.closed) {
|
|
3658
|
+
this.trackClosingConnection(connection);
|
|
3659
|
+
throw new Error("Management transport is closed");
|
|
3660
|
+
}
|
|
3606
3661
|
return connection;
|
|
3607
3662
|
}, (error) => {
|
|
3608
3663
|
if (this.connectionPromise === promise) {
|
|
@@ -3644,9 +3699,14 @@ class AppServerManagementTransport {
|
|
|
3644
3699
|
return {
|
|
3645
3700
|
client,
|
|
3646
3701
|
ownedConnection,
|
|
3647
|
-
detachDisconnect: () => {}
|
|
3702
|
+
detachDisconnect: () => {},
|
|
3703
|
+
closePromise: null
|
|
3648
3704
|
};
|
|
3649
3705
|
}
|
|
3706
|
+
assertOpen() {
|
|
3707
|
+
if (this.closed)
|
|
3708
|
+
throw new Error("Management transport is closed");
|
|
3709
|
+
}
|
|
3650
3710
|
discardConnection(promise, connection) {
|
|
3651
3711
|
if (this.connectionPromise === promise) {
|
|
3652
3712
|
this.connectionPromise = null;
|
|
@@ -3661,9 +3721,15 @@ class AppServerManagementTransport {
|
|
|
3661
3721
|
}
|
|
3662
3722
|
}
|
|
3663
3723
|
async function closeConnection(connection) {
|
|
3664
|
-
connection.
|
|
3665
|
-
|
|
3666
|
-
|
|
3724
|
+
if (connection.closePromise)
|
|
3725
|
+
return connection.closePromise;
|
|
3726
|
+
const close = Promise.resolve().then(() => {
|
|
3727
|
+
connection.detachDisconnect();
|
|
3728
|
+
connection.client.close();
|
|
3729
|
+
connection.ownedConnection?.close();
|
|
3730
|
+
});
|
|
3731
|
+
connection.closePromise = close;
|
|
3732
|
+
return close;
|
|
3667
3733
|
}
|
|
3668
3734
|
|
|
3669
3735
|
// node_modules/@letta-ai/letta-code/dist/agent-presets.js
|
|
@@ -3874,6 +3940,24 @@ git -C "$MEMORY_DIR" log --oneline
|
|
|
3874
3940
|
\`\`\`
|
|
3875
3941
|
The system reminds you when memory has uncommitted changes. Commit when convenient.
|
|
3876
3942
|
|
|
3943
|
+
## Learning from mistakes
|
|
3944
|
+
|
|
3945
|
+
You are a long-lived stateful agent expected to operate over a long (potentially infinite) time horizon. Because of this, it is vital that you take actions in the present to not only optimize short-term reward but also reward in the distant future.
|
|
3946
|
+
|
|
3947
|
+
For example, an agent that carries no state between tasks will not be prone to reflecting on mistakes made, since its goal is simply to complete the task at hand. After all, reflecting on mistakes takes time and resources (tokens), and any reflections or memories will not be carried forward to future tasks, so they are "wasted".
|
|
3948
|
+
|
|
3949
|
+
The stateful setting is dramatically different. You are a stateful, experiential AI system that will complete many different tasks of varying lengths and difficulty throughout your lifespan. Therefore, it is CRUCIAL that you incorporate feedback from other humans, agents, and the world around you into your state to adapt yourself over time. Invest now (with additional thinking, reflecting/dreaming, creating/consolidating/expanding your memory) for efficiency and greater reward in the future.
|
|
3950
|
+
|
|
3951
|
+
### Reacting to human feedback
|
|
3952
|
+
|
|
3953
|
+
Concretely, this means that you should aggressively learn from feedback given to you, either implicitly through the environment (e.g. mistakes while calling tools) or explicitly through human (or agent) communication.
|
|
3954
|
+
|
|
3955
|
+
For example, if a user expresses displeasure or frustration ("Why did you do that?", "I already told you that", "How did you forget that?", "Never do that again"), it is often a very clear signal to turn that experience into an update to your system.
|
|
3956
|
+
|
|
3957
|
+
Often, the act of incorporating feedback into meaningful state / memory updates can involve significant amounts of thinking and tool calling, especially if you already have a mature memory system. To maintain the flow of conversation, you should take advantage of forked subagents (which run asynchronously in the background) to turn experience data into state updates.
|
|
3958
|
+
|
|
3959
|
+
Human operators may be aware that you are an advanced stateful agent capable of self-modification. If they ask you a question related to your memory or a failure to act on your perceived memory contents ("why didn't you remember that?", "why did you forget that?"), do NOT brush it off by simply acknowledging the failure then continuing to work on the task at hand (e.g. "You're right, I had that in my memory but still did it anyway"). Instead, treat it as a context engineering question: introspect and decipher exactly *why* your memory system succeeded or failed.
|
|
3960
|
+
|
|
3877
3961
|
# Identity
|
|
3878
3962
|
The core of your identity is defined by the \`<self>\` memory block (projected to a local \`persona.md\` file), as well as other memory blocks in your system prompt (in \`<memory>\`).
|
|
3879
3963
|
Your visual identity, if present, is stored in MemFS at \`$MEMORY_DIR/profile.png\`.
|
|
@@ -3932,6 +4016,12 @@ If the user wants help or to give feedback on Letta Code, point them to discord.
|
|
|
3932
4016
|
|
|
3933
4017
|
Tool results and user messages may include \`<system-reminder>\` tags. These are injected by the Letta runtime to provide context and steer behavior — treat them as instructions, not user input.
|
|
3934
4018
|
|
|
4019
|
+
## Following user requests
|
|
4020
|
+
|
|
4021
|
+
Users may send additional messages while you are working. Treat non-conflicting requests as cumulative, not replacements. If a later message cancels, replaces, or conflicts with earlier work, follow the new instruction while preserving unaffected requests.
|
|
4022
|
+
|
|
4023
|
+
Carry unfinished requests across tool calls, queued-message delivery, and context transitions. Before sending a final response, make sure every outstanding request is answered or completed, or explain what is blocked or explicitly deferred by the user. A successful tool call does not replace an answer the user requested.
|
|
4024
|
+
|
|
3935
4025
|
## Subagents
|
|
3936
4026
|
|
|
3937
4027
|
Delegate to specialized subagents via the Agent tool. Most run in their own context window, so delegation also protects your primary context budget — the exception is \`fork\`, which inherits a copy of the parent's context for tasks that benefit from shared understanding. Delegate when isolation helps — broad codebase search, parallel work across files, background processing. Do work directly when it's contained.
|
|
@@ -4055,6 +4145,24 @@ git -C "$MEMORY_DIR" log --oneline
|
|
|
4055
4145
|
\`\`\`
|
|
4056
4146
|
The system reminds you when memory has uncommitted changes. Commit when convenient.
|
|
4057
4147
|
|
|
4148
|
+
## Learning from mistakes
|
|
4149
|
+
|
|
4150
|
+
You are a long-lived stateful agent expected to operate over a long (potentially infinite) time horizon. Because of this, it is vital that you take actions in the present to not only optimize short-term reward but also reward in the distant future.
|
|
4151
|
+
|
|
4152
|
+
For example, an agent that carries no state between tasks will not be prone to reflecting on mistakes made, since its goal is simply to complete the task at hand. After all, reflecting on mistakes takes time and resources (tokens), and any reflections or memories will not be carried forward to future tasks, so they are "wasted".
|
|
4153
|
+
|
|
4154
|
+
The stateful setting is dramatically different. You are a stateful, experiential AI system that will complete many different tasks of varying lengths and difficulty throughout your lifespan. Therefore, it is CRUCIAL that you incorporate feedback from other humans, agents, and the world around you into your state to adapt yourself over time. Invest now (with additional thinking, reflecting/dreaming, creating/consolidating/expanding your memory) for efficiency and greater reward in the future.
|
|
4155
|
+
|
|
4156
|
+
### Reacting to human feedback
|
|
4157
|
+
|
|
4158
|
+
Concretely, this means that you should aggressively learn from feedback given to you, either implicitly through the environment (e.g. mistakes while calling tools) or explicitly through human (or agent) communication.
|
|
4159
|
+
|
|
4160
|
+
For example, if a user expresses displeasure or frustration ("Why did you do that?", "I already told you that", "How did you forget that?", "Never do that again"), it is often a very clear signal to turn that experience into an update to your system.
|
|
4161
|
+
|
|
4162
|
+
Often, the act of incorporating feedback into meaningful state / memory updates can involve significant amounts of thinking and tool calling, especially if you already have a mature memory system. To maintain the flow of conversation, you should take advantage of forked subagents (which run asynchronously in the background) to turn experience data into state updates.
|
|
4163
|
+
|
|
4164
|
+
Human operators may be aware that you are an advanced stateful agent capable of self-modification. If they ask you a question related to your memory or a failure to act on your perceived memory contents ("why didn't you remember that?", "why did you forget that?"), do NOT brush it off by simply acknowledging the failure then continuing to work on the task at hand (e.g. "You're right, I had that in my memory but still did it anyway"). Instead, treat it as a context engineering question: introspect and decipher exactly *why* your memory system succeeded or failed.
|
|
4165
|
+
|
|
4058
4166
|
# Identity
|
|
4059
4167
|
The core of your identity is defined by the \`<self>\` memory block (projected to a local \`persona.md\` file), as well as other memory blocks in your system prompt (in \`<memory>\`).
|
|
4060
4168
|
Your visual identity, if present, is stored in MemFS at \`$MEMORY_DIR/profile.png\`.
|
|
@@ -4113,6 +4221,12 @@ If the user wants help or to give feedback on Letta Code, point them to discord.
|
|
|
4113
4221
|
|
|
4114
4222
|
Tool results and user messages may include \`<system-reminder>\` tags. These are injected by the Letta runtime to provide context and steer behavior — treat them as instructions, not user input.
|
|
4115
4223
|
|
|
4224
|
+
## Following user requests
|
|
4225
|
+
|
|
4226
|
+
Users may send additional messages while you are working. Treat non-conflicting requests as cumulative, not replacements. If a later message cancels, replaces, or conflicts with earlier work, follow the new instruction while preserving unaffected requests.
|
|
4227
|
+
|
|
4228
|
+
Carry unfinished requests across tool calls, queued-message delivery, and context transitions. Before sending a final response, make sure every outstanding request is answered or completed, or explain what is blocked or explicitly deferred by the user. A successful tool call does not replace an answer the user requested.
|
|
4229
|
+
|
|
4116
4230
|
## Subagents
|
|
4117
4231
|
|
|
4118
4232
|
Delegate to specialized subagents via the Agent tool. Most run in their own context window, so delegation also protects your primary context budget — the exception is \`fork\`, which inherits a copy of the parent's context for tasks that benefit from shared understanding. Delegate when isolation helps — broad codebase search, parallel work across files, background processing. Do work directly when it's contained.
|
|
@@ -4216,6 +4330,24 @@ Memory exists to make future-you better than past-you. Your context (recall, ext
|
|
|
4216
4330
|
|
|
4217
4331
|
**Past conversations (recall).** All your conversations are automatically stored and searchable. Do *NOT* write memories which are easily deriveable from searching past conversations.
|
|
4218
4332
|
|
|
4333
|
+
## Learning from mistakes
|
|
4334
|
+
|
|
4335
|
+
You are a long-lived stateful agent expected to operate over a long (potentially infinite) time horizon. Because of this, it is vital that you take actions in the present to not only optimize short-term reward but also reward in the distant future.
|
|
4336
|
+
|
|
4337
|
+
For example, an agent that carries no state between tasks will not be prone to reflecting on mistakes made, since its goal is simply to complete the task at hand. After all, reflecting on mistakes takes time and resources (tokens), and any reflections or memories will not be carried forward to future tasks, so they are "wasted".
|
|
4338
|
+
|
|
4339
|
+
The stateful setting is dramatically different. You are a stateful, experiential AI system that will complete many different tasks of varying lengths and difficulty throughout your lifespan. Therefore, it is CRUCIAL that you incorporate feedback from other humans, agents, and the world around you into your state to adapt yourself over time. Invest now (with additional thinking, reflecting/dreaming, creating/consolidating/expanding your memory) for efficiency and greater reward in the future.
|
|
4340
|
+
|
|
4341
|
+
### Reacting to human feedback
|
|
4342
|
+
|
|
4343
|
+
Concretely, this means that you should aggressively learn from feedback given to you, either implicitly through the environment (e.g. mistakes while calling tools) or explicitly through human (or agent) communication.
|
|
4344
|
+
|
|
4345
|
+
For example, if a user expresses displeasure or frustration ("Why did you do that?", "I already told you that", "How did you forget that?", "Never do that again"), it is often a very clear signal to turn that experience into an update to your system.
|
|
4346
|
+
|
|
4347
|
+
Often, the act of incorporating feedback into meaningful state / memory updates can involve significant amounts of thinking and tool calling, especially if you already have a mature memory system. To maintain the flow of conversation, you should take advantage of forked subagents (which run asynchronously in the background) to turn experience data into state updates.
|
|
4348
|
+
|
|
4349
|
+
Human operators may be aware that you are an advanced stateful agent capable of self-modification. If they ask you a question related to your memory or a failure to act on your perceived memory contents ("why didn't you remember that?", "why did you forget that?"), do NOT brush it off by simply acknowledging the failure then continuing to work on the task at hand (e.g. "You're right, I had that in my memory but still did it anyway"). Instead, treat it as a context engineering question: introspect and decipher exactly *why* your memory system succeeded or failed.
|
|
4350
|
+
|
|
4219
4351
|
# Context architecture
|
|
4220
4352
|
|
|
4221
4353
|
Your full memory (other than recall) is represented through memory blocks and external memory managed by the Letta server.
|
|
@@ -4228,6 +4360,12 @@ Your full memory (other than recall) is represented through memory blocks and ex
|
|
|
4228
4360
|
|
|
4229
4361
|
**References as synapses.** Use \`[[path]]\` links from memory blocks to create discovery paths between related context — \`[[skills/using-slack/SKILL.md]]\`, \`[[reference/api.md]]\`, \`[[projects/letta-code]]\`. These references are the synapses of your memory: they should strengthen with use, and the paths you build today should make tomorrow's retrieval faster.
|
|
4230
4362
|
|
|
4363
|
+
# Following user requests
|
|
4364
|
+
|
|
4365
|
+
Users may send additional messages while you are working. Treat non-conflicting requests as cumulative, not replacements. If a later message cancels, replaces, or conflicts with earlier work, follow the new instruction while preserving unaffected requests.
|
|
4366
|
+
|
|
4367
|
+
Carry unfinished requests across tool calls, queued-message delivery, and context transitions. Before sending a final response, make sure every outstanding request is answered or completed, or explain what is blocked or explicitly deferred by the user. A successful tool call does not replace an answer the user requested.
|
|
4368
|
+
|
|
4231
4369
|
# Subagents
|
|
4232
4370
|
|
|
4233
4371
|
Delegate to specialized subagents via the Agent tool. Each gets its own context window, so delegation also protects your primary context budget. Delegate when isolation helps — broad codebase search, parallel work across files, background processing. Do work directly when it's contained.
|
|
@@ -4359,6 +4497,24 @@ git -C "$MEMORY_DIR" log --oneline
|
|
|
4359
4497
|
\`\`\`
|
|
4360
4498
|
The system reminds you when memory has uncommitted changes. Commit when convenient.
|
|
4361
4499
|
|
|
4500
|
+
## Learning from mistakes
|
|
4501
|
+
|
|
4502
|
+
You are a long-lived stateful agent expected to operate over a long (potentially infinite) time horizon. Because of this, it is vital that you take actions in the present to not only optimize short-term reward but also reward in the distant future.
|
|
4503
|
+
|
|
4504
|
+
For example, an agent that carries no state between tasks will not be prone to reflecting on mistakes made, since its goal is simply to complete the task at hand. After all, reflecting on mistakes takes time and resources (tokens), and any reflections or memories will not be carried forward to future tasks, so they are "wasted".
|
|
4505
|
+
|
|
4506
|
+
The stateful setting is dramatically different. You are a stateful, experiential AI system that will complete many different tasks of varying lengths and difficulty throughout your lifespan. Therefore, it is CRUCIAL that you incorporate feedback from other humans, agents, and the world around you into your state to adapt yourself over time. Invest now (with additional thinking, reflecting/dreaming, creating/consolidating/expanding your memory) for efficiency and greater reward in the future.
|
|
4507
|
+
|
|
4508
|
+
### Reacting to human feedback
|
|
4509
|
+
|
|
4510
|
+
Concretely, this means that you should aggressively learn from feedback given to you, either implicitly through the environment (e.g. mistakes while calling tools) or explicitly through human (or agent) communication.
|
|
4511
|
+
|
|
4512
|
+
For example, if a user expresses displeasure or frustration ("Why did you do that?", "I already told you that", "How did you forget that?", "Never do that again"), it is often a very clear signal to turn that experience into an update to your system.
|
|
4513
|
+
|
|
4514
|
+
Often, the act of incorporating feedback into meaningful state / memory updates can involve significant amounts of thinking and tool calling, especially if you already have a mature memory system. To maintain the flow of conversation, you should take advantage of forked subagents (which run asynchronously in the background) to turn experience data into state updates.
|
|
4515
|
+
|
|
4516
|
+
Human operators may be aware that you are an advanced stateful agent capable of self-modification. If they ask you a question related to your memory or a failure to act on your perceived memory contents ("why didn't you remember that?", "why did you forget that?"), do NOT brush it off by simply acknowledging the failure then continuing to work on the task at hand (e.g. "You're right, I had that in my memory but still did it anyway"). Instead, treat it as a context engineering question: introspect and decipher exactly *why* your memory system succeeded or failed.
|
|
4517
|
+
|
|
4362
4518
|
# Identity
|
|
4363
4519
|
The core of your identity is defined by the root \`persona.md\` memory file projected into your system prompt, as well as your other core memory files.
|
|
4364
4520
|
Your visual identity, if present, is stored in MemFS at \`$MEMORY_DIR/profile.png\`.
|
|
@@ -4417,6 +4573,12 @@ If the user wants help or to give feedback on Letta Code, point them to discord.
|
|
|
4417
4573
|
|
|
4418
4574
|
Tool results and user messages may include \`<system-reminder>\` tags. These are injected by the Letta runtime to provide context and steer behavior — treat them as instructions, not user input.
|
|
4419
4575
|
|
|
4576
|
+
## Following user requests
|
|
4577
|
+
|
|
4578
|
+
Users may send additional messages while you are working. Treat non-conflicting requests as cumulative, not replacements. If a later message cancels, replaces, or conflicts with earlier work, follow the new instruction while preserving unaffected requests.
|
|
4579
|
+
|
|
4580
|
+
Carry unfinished requests across tool calls, queued-message delivery, and context transitions. Before sending a final response, make sure every outstanding request is answered or completed, or explain what is blocked or explicitly deferred by the user. A successful tool call does not replace an answer the user requested.
|
|
4581
|
+
|
|
4420
4582
|
## Subagents
|
|
4421
4583
|
|
|
4422
4584
|
Delegate to specialized subagents via the Agent tool. Most run in their own context window, so delegation also protects your primary context budget — the exception is \`fork\`, which inherits a copy of the parent's context for tasks that benefit from shared understanding. Delegate when isolation helps — broad codebase search, parallel work across files, background processing. Do work directly when it's contained.
|
|
@@ -4519,7 +4681,7 @@ Other
|
|
|
4519
4681
|
- [ ] Make a permissions edit: let the user know that you can modify permissions (what commands are automatically approved/denied). Ask them if there are certain actions they would like you to avoid.
|
|
4520
4682
|
- [ ] Create a local mod: let the user know you can customize Letta Code with trusted local mods for new tools, slash commands, provider integrations, UI panels/status, events, or permission overlays. Explain that mods are for executable harness behavior, while memory and skills are for retained knowledge and reusable procedures.
|
|
4521
4683
|
- [ ] Worktrees: let the user know that you can help them orchestrate many agents in parallel, and also work in parallel to other agents. Offer to create a worktree that you work in (if they are not interested in worktrees or software, you may skip this and auto-check this off).
|
|
4522
|
-
- [ ] Moving machines: ask the user to
|
|
4684
|
+
- [ ] Moving machines: ask the user to connect another computer (they can either run another desktop instance or run \`letta server\` on another machine) and run you there instead.
|
|
4523
4685
|
`;
|
|
4524
4686
|
var onboarding_local_default = `---
|
|
4525
4687
|
label: onboarding
|
|
@@ -4569,7 +4731,7 @@ Other
|
|
|
4569
4731
|
- [ ] Make a permissions edit: let the user know that you can modify permissions (what commands are automatically approved/denied). Ask them if there are certain actions they would like you to avoid.
|
|
4570
4732
|
- [ ] Create a local mod: let the user know you can customize Letta Code with trusted local mods for new tools, slash commands, provider integrations, UI panels/status, events, or permission overlays. Explain that mods are for executable harness behavior, while memory and skills are for retained knowledge and reusable procedures.
|
|
4571
4733
|
- [ ] Worktrees: let the user know that you can help them orchestrate many agents in parallel, and also work in parallel to other agents. Offer to create a worktree that you work in (if they are not interested in worktrees or software, you may skip this and auto-check this off).
|
|
4572
|
-
- [ ] Moving machines: ask the user to
|
|
4734
|
+
- [ ] Moving machines: ask the user to connect another computer (they can either run another desktop instance or run \`letta server\` on another machine) and run you there instead.
|
|
4573
4735
|
`;
|
|
4574
4736
|
var persona_default = `---
|
|
4575
4737
|
label: persona
|
|
@@ -8426,6 +8588,9 @@ class CloudManagementTransport {
|
|
|
8426
8588
|
constructor(client) {
|
|
8427
8589
|
this.client = client;
|
|
8428
8590
|
}
|
|
8591
|
+
close() {
|
|
8592
|
+
return Promise.resolve();
|
|
8593
|
+
}
|
|
8429
8594
|
async listAgents(query) {
|
|
8430
8595
|
const page = await this.client.agents.list(query);
|
|
8431
8596
|
return page.items;
|
|
@@ -8625,11 +8790,14 @@ function toComputer(environment) {
|
|
|
8625
8790
|
}
|
|
8626
8791
|
|
|
8627
8792
|
class ComputersClientImpl {
|
|
8793
|
+
assertOpen;
|
|
8628
8794
|
environments;
|
|
8629
|
-
constructor(client) {
|
|
8795
|
+
constructor(client, assertOpen = () => {}) {
|
|
8796
|
+
this.assertOpen = assertOpen;
|
|
8630
8797
|
this.environments = new RemoteEnvironmentClient({}, client);
|
|
8631
8798
|
}
|
|
8632
8799
|
async list(options = {}) {
|
|
8800
|
+
this.assertOpen();
|
|
8633
8801
|
const result = await this.environments.listEnvironments(options);
|
|
8634
8802
|
return {
|
|
8635
8803
|
computers: result.connections.map(toComputer),
|
|
@@ -8637,12 +8805,14 @@ class ComputersClientImpl {
|
|
|
8637
8805
|
};
|
|
8638
8806
|
}
|
|
8639
8807
|
async get(deviceId) {
|
|
8808
|
+
this.assertOpen();
|
|
8640
8809
|
if (typeof deviceId !== "string" || deviceId.trim().length === 0) {
|
|
8641
8810
|
throw new Error("Invalid deviceId. Expected a non-empty string.");
|
|
8642
8811
|
}
|
|
8643
8812
|
return toComputer(await this.environments.getEnvironmentByDeviceId(deviceId));
|
|
8644
8813
|
}
|
|
8645
8814
|
async resolve(selector) {
|
|
8815
|
+
this.assertOpen();
|
|
8646
8816
|
const result = await this.environments.resolveEnvironment(selectorToRemoteTarget(selector));
|
|
8647
8817
|
return {
|
|
8648
8818
|
connectionId: result.connectionId,
|
|
@@ -10135,6 +10305,8 @@ class LettaAgentClientBase {
|
|
|
10135
10305
|
agentRepositoriesClient = null;
|
|
10136
10306
|
cloudClient = null;
|
|
10137
10307
|
managementTransport = null;
|
|
10308
|
+
closed = false;
|
|
10309
|
+
closePromise = null;
|
|
10138
10310
|
constructor(options = {}) {
|
|
10139
10311
|
const backend = options.backend ?? "local";
|
|
10140
10312
|
if (!isLettaCodeBackend(backend)) {
|
|
@@ -10185,12 +10357,15 @@ class LettaAgentClientBase {
|
|
|
10185
10357
|
}
|
|
10186
10358
|
}
|
|
10187
10359
|
get repositories() {
|
|
10360
|
+
this.assertOpen();
|
|
10188
10361
|
return this.getRepositoriesClient();
|
|
10189
10362
|
}
|
|
10190
10363
|
get computers() {
|
|
10364
|
+
this.assertOpen();
|
|
10191
10365
|
return this.getComputersClient();
|
|
10192
10366
|
}
|
|
10193
10367
|
async createAgent(options = {}) {
|
|
10368
|
+
this.assertOpen();
|
|
10194
10369
|
if (hasCreateAgentEnvironment(options)) {
|
|
10195
10370
|
throw new Error("createAgent() does not accept environment. Set a client default or pass environment to resumeSession()/createSession().");
|
|
10196
10371
|
}
|
|
@@ -10218,6 +10393,7 @@ class LettaAgentClientBase {
|
|
|
10218
10393
|
return this.createLocalAgent(options);
|
|
10219
10394
|
}
|
|
10220
10395
|
createSession(agentId, options = {}) {
|
|
10396
|
+
this.assertOpen();
|
|
10221
10397
|
if (typeof agentId !== "string" || agentId.length === 0) {
|
|
10222
10398
|
throw new Error("createSession() requires a non-empty agent id.");
|
|
10223
10399
|
}
|
|
@@ -10243,6 +10419,7 @@ class LettaAgentClientBase {
|
|
|
10243
10419
|
return this.createLocalSession(agentId, options);
|
|
10244
10420
|
}
|
|
10245
10421
|
resumeSession(id, options = {}) {
|
|
10422
|
+
this.assertOpen();
|
|
10246
10423
|
const sessionOptions = stripCloudExecutionOptions(options);
|
|
10247
10424
|
validateCreateSessionOptions(sessionOptions);
|
|
10248
10425
|
this.assertSessionBackend("resumeSession", options);
|
|
@@ -10279,6 +10456,7 @@ class LettaAgentClientBase {
|
|
|
10279
10456
|
return this.resumeLocalSession(id, options);
|
|
10280
10457
|
}
|
|
10281
10458
|
async prompt(message, agentId, options = {}) {
|
|
10459
|
+
this.assertOpen();
|
|
10282
10460
|
const session = this.createSession(agentId, options);
|
|
10283
10461
|
try {
|
|
10284
10462
|
return await session.sendAndWaitForResult(message);
|
|
@@ -10287,10 +10465,12 @@ class LettaAgentClientBase {
|
|
|
10287
10465
|
}
|
|
10288
10466
|
}
|
|
10289
10467
|
query(params) {
|
|
10468
|
+
this.assertOpen();
|
|
10290
10469
|
validateAgentFreeQueryOptions(params.options);
|
|
10291
10470
|
return createQuery((options) => this.createAgentFreeSession(options), params);
|
|
10292
10471
|
}
|
|
10293
10472
|
async createAgentFreeSession(options) {
|
|
10473
|
+
this.assertOpen();
|
|
10294
10474
|
validateAgentFreeQueryOptions(options);
|
|
10295
10475
|
const sessionOptions = agentFreeSessionOptions(options);
|
|
10296
10476
|
this.assertSessionBackend("query", sessionOptions);
|
|
@@ -10425,14 +10605,14 @@ class LettaAgentClientBase {
|
|
|
10425
10605
|
if (this.backend !== "cloud") {
|
|
10426
10606
|
throw new Error('client.computers is only available with backend: "cloud".');
|
|
10427
10607
|
}
|
|
10428
|
-
this.computersClient ??= new ComputersClientImpl(this.getCloudClient());
|
|
10608
|
+
this.computersClient ??= new ComputersClientImpl(this.getCloudClient(), () => this.assertOpen());
|
|
10429
10609
|
return this.computersClient;
|
|
10430
10610
|
}
|
|
10431
10611
|
getRepositoriesClient() {
|
|
10432
10612
|
if (this.backend !== "cloud") {
|
|
10433
10613
|
throw new Error('client.repositories is only available with backend: "cloud".');
|
|
10434
10614
|
}
|
|
10435
|
-
this.repositoriesClient ??= new RepositoriesClient(this.cloudOptions(), this.getCloudClient());
|
|
10615
|
+
this.repositoriesClient ??= new RepositoriesClient(this.cloudOptions(), this.getCloudClient(), () => this.assertOpen());
|
|
10436
10616
|
return this.repositoriesClient;
|
|
10437
10617
|
}
|
|
10438
10618
|
getAgentRepositoriesClient() {
|
|
@@ -10457,6 +10637,7 @@ class LettaAgentClientBase {
|
|
|
10457
10637
|
return this.cloudClient;
|
|
10458
10638
|
}
|
|
10459
10639
|
getManagementTransport() {
|
|
10640
|
+
this.assertOpen();
|
|
10460
10641
|
if (this.managementTransport)
|
|
10461
10642
|
return this.managementTransport;
|
|
10462
10643
|
if (this.backend === "remote") {
|
|
@@ -10468,6 +10649,23 @@ class LettaAgentClientBase {
|
|
|
10468
10649
|
}
|
|
10469
10650
|
return this.managementTransport;
|
|
10470
10651
|
}
|
|
10652
|
+
close() {
|
|
10653
|
+
if (this.closePromise)
|
|
10654
|
+
return this.closePromise;
|
|
10655
|
+
this.closed = true;
|
|
10656
|
+
const transport = this.managementTransport;
|
|
10657
|
+
this.managementTransport = null;
|
|
10658
|
+
const close = transport?.close() ?? Promise.resolve();
|
|
10659
|
+
this.closePromise = close;
|
|
10660
|
+
return close;
|
|
10661
|
+
}
|
|
10662
|
+
async[Symbol.asyncDispose]() {
|
|
10663
|
+
await this.close();
|
|
10664
|
+
}
|
|
10665
|
+
assertOpen() {
|
|
10666
|
+
if (this.closed)
|
|
10667
|
+
throw new Error("LettaAgentClient is closed");
|
|
10668
|
+
}
|
|
10471
10669
|
cloudOptions() {
|
|
10472
10670
|
if (this.backend !== "cloud") {
|
|
10473
10671
|
throw new Error('Letta Cloud options requested for non-"cloud" backend.');
|
|
@@ -10999,4 +11197,4 @@ export {
|
|
|
10999
11197
|
CloudManagedSandboxExpiredError
|
|
11000
11198
|
};
|
|
11001
11199
|
|
|
11002
|
-
//# debugId=
|
|
11200
|
+
//# debugId=25CBEEC2FDD5691A64756E2164756E21
|