-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathmessages.ts
More file actions
848 lines (740 loc) · 23 KB
/
messages.ts
File metadata and controls
848 lines (740 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
import { APIResource } from '../../core/resource';
import * as AgentsAPI from '../agents/agents';
import * as MessagesAPI from '../agents/messages';
import { MessagesArrayPage } from '../agents/messages';
import { APIPromise } from '../../core/api-promise';
import { ArrayPage, type ArrayPageParams, PagePromise } from '../../core/pagination';
import { Stream } from '../../core/streaming';
import { RequestOptions } from '../../internal/request-options';
import { path } from '../../internal/utils/path';
export class Messages extends APIResource {
/**
* Send a message to a conversation and get a response.
*
* This endpoint sends a message to an existing conversation. By default
* (streaming=true), returns a streaming response (Server-Sent Events). Set
* streaming=false to get a complete JSON response.
*
* **Agent-direct mode**: Pass conversation_id="default" with agent_id in request
* body to send messages to the agent's default conversation with locking.
*
* **Deprecated**: Passing an agent ID as conversation_id still works but will be
* removed.
*/
create(
conversationID: string,
body: MessageCreateParams,
options?: RequestOptions,
): APIPromise<Stream<MessagesAPI.LettaStreamingResponse>> {
return this._client.post(path`/v1/conversations/${conversationID}/messages`, {
body,
...options,
stream: true,
}) as APIPromise<Stream<MessagesAPI.LettaStreamingResponse>>;
}
/**
* List all messages in a conversation.
*
* Returns LettaMessage objects (UserMessage, AssistantMessage, etc.) for all
* messages in the conversation, with support for cursor-based pagination.
*
* **Agent-direct mode**: Pass conversation_id="default" with agent_id parameter to
* list messages from the agent's default conversation.
*
* **Deprecated**: Passing an agent ID as conversation_id still works but will be
* removed.
*/
list(
conversationID: string,
query: MessageListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<MessagesArrayPage, MessagesAPI.Message> {
return this._client.getAPIList(
path`/v1/conversations/${conversationID}/messages`,
ArrayPage<MessagesAPI.Message>,
{ query, ...options },
);
}
/**
* Compact (summarize) a conversation's message history.
*
* This endpoint summarizes the in-context messages for a specific conversation,
* reducing the message count while preserving important context.
*
* **Agent-direct mode**: Pass conversation_id="default" with agent_id in request
* body to compact the agent's default conversation messages.
*
* **Deprecated**: Passing an agent ID as conversation_id still works but will be
* removed.
*/
compact(
conversationID: string,
body: MessageCompactParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<CompactionResponse> {
return this._client.post(path`/v1/conversations/${conversationID}/compact`, { body, ...options });
}
/**
* Resume the stream for the most recent active run in a conversation.
*
* This endpoint allows you to reconnect to an active background stream for a
* conversation, enabling recovery from network interruptions.
*
* **Agent-direct mode**: Pass conversation_id="default" with agent_id in request
* body to retrieve the stream for the agent's most recent active run.
*
* **Deprecated**: Passing an agent ID as conversation_id still works but will be
* removed.
*/
stream(
conversationID: string,
body: MessageStreamParams | undefined = {},
options?: RequestOptions,
): APIPromise<Stream<MessagesAPI.LettaStreamingResponse>> {
return this._client.post(path`/v1/conversations/${conversationID}/stream`, {
body,
...options,
stream: true,
}) as APIPromise<Stream<MessagesAPI.LettaStreamingResponse>>;
}
}
export interface CompactionRequest {
/**
* Configuration for conversation compaction / summarization.
*
* Per-model settings (temperature, max tokens, etc.) are derived from the default
* configuration for that handle.
*/
compaction_settings?: CompactionRequest.CompactionSettings | null;
}
export namespace CompactionRequest {
/**
* Configuration for conversation compaction / summarization.
*
* Per-model settings (temperature, max tokens, etc.) are derived from the default
* configuration for that handle.
*/
export interface CompactionSettings {
/**
* The maximum length of the summary in characters. If none, no clipping is
* performed.
*/
clip_chars?: number | null;
/**
* The type of summarization technique use.
*/
mode?: 'all' | 'sliding_window' | 'self_compact_all' | 'self_compact_sliding_window';
/**
* Model handle to use for sliding_window/all summarization (format:
* provider/model-name). If None, uses lightweight provider-specific defaults.
*/
model?: string | null;
/**
* Optional model settings used to override defaults for the summarizer model.
*/
model_settings?:
| AgentsAPI.OpenAIModelSettings
| AgentsAPI.AnthropicModelSettings
| AgentsAPI.GoogleAIModelSettings
| AgentsAPI.GoogleVertexModelSettings
| AgentsAPI.AzureModelSettings
| AgentsAPI.XaiModelSettings
| CompactionSettings.ZaiModelSettings
| AgentsAPI.GroqModelSettings
| AgentsAPI.DeepseekModelSettings
| AgentsAPI.TogetherModelSettings
| AgentsAPI.BedrockModelSettings
| CompactionSettings.OpenRouterModelSettings
| CompactionSettings.ChatGptoAuthModelSettings
| null;
/**
* The prompt to use for summarization. If None, uses mode-specific default.
*/
prompt?: string | null;
/**
* Whether to include an acknowledgement post-prompt (helps prevent non-summary
* outputs).
*/
prompt_acknowledgement?: boolean;
/**
* The percentage of the context window to keep post-summarization (only used in
* sliding window modes).
*/
sliding_window_percentage?: number;
}
export namespace CompactionSettings {
/**
* Z.ai (ZhipuAI) model configuration (OpenAI-compatible).
*/
export interface ZaiModelSettings {
/**
* The maximum number of tokens the model can generate.
*/
max_output_tokens?: number;
/**
* Whether to enable parallel tool calling.
*/
parallel_tool_calls?: boolean;
/**
* The type of the provider.
*/
provider_type?: 'zai';
/**
* The response format for the model.
*/
response_format?:
| AgentsAPI.TextResponseFormat
| AgentsAPI.JsonSchemaResponseFormat
| AgentsAPI.JsonObjectResponseFormat
| null;
/**
* The temperature of the model.
*/
temperature?: number;
/**
* The thinking configuration for GLM-4.5+ models.
*/
thinking?: ZaiModelSettings.Thinking;
}
export namespace ZaiModelSettings {
/**
* The thinking configuration for GLM-4.5+ models.
*/
export interface Thinking {
/**
* If False, preserved thinking is used (recommended for agents).
*/
clear_thinking?: boolean;
/**
* Whether thinking is enabled or disabled.
*/
type?: 'enabled' | 'disabled';
}
}
/**
* OpenRouter model configuration (OpenAI-compatible).
*/
export interface OpenRouterModelSettings {
/**
* The maximum number of tokens the model can generate.
*/
max_output_tokens?: number;
/**
* Whether to enable parallel tool calling.
*/
parallel_tool_calls?: boolean;
/**
* The type of the provider.
*/
provider_type?: 'openrouter';
/**
* The response format for the model.
*/
response_format?:
| AgentsAPI.TextResponseFormat
| AgentsAPI.JsonSchemaResponseFormat
| AgentsAPI.JsonObjectResponseFormat
| null;
/**
* The temperature of the model.
*/
temperature?: number;
}
/**
* ChatGPT OAuth model configuration (uses ChatGPT backend API).
*/
export interface ChatGptoAuthModelSettings {
/**
* The maximum number of tokens the model can generate.
*/
max_output_tokens?: number;
/**
* Whether to enable parallel tool calling.
*/
parallel_tool_calls?: boolean;
/**
* The type of the provider.
*/
provider_type?: 'chatgpt_oauth';
/**
* The reasoning configuration for the model.
*/
reasoning?: ChatGptoAuthModelSettings.Reasoning;
/**
* The temperature of the model.
*/
temperature?: number;
}
export namespace ChatGptoAuthModelSettings {
/**
* The reasoning configuration for the model.
*/
export interface Reasoning {
/**
* The reasoning effort level for GPT-5.x and o-series models.
*/
reasoning_effort?: 'none' | 'low' | 'medium' | 'high' | 'xhigh';
}
}
}
}
export interface CompactionResponse {
num_messages_after: number;
num_messages_before: number;
summary: string;
}
export type MessageStreamResponse = unknown;
export interface MessageCreateParams {
/**
* Agent ID for agent-direct mode with 'default' conversation. Use with
* conversation_id='default' in the URL path.
*/
agent_id?: string | null;
/**
* @deprecated The name of the message argument in the designated message tool.
* Still supported for legacy agent types, but deprecated for letta_v1_agent
* onward.
*/
assistant_message_tool_kwarg?: string;
/**
* @deprecated The name of the designated message tool. Still supported for legacy
* agent types, but deprecated for letta_v1_agent onward.
*/
assistant_message_tool_name?: string;
/**
* Whether to process the request in the background (only used when
* streaming=true).
*/
background?: boolean;
/**
* Client-side skills available in the environment. These are rendered in the
* system prompt's available skills section alongside agent-scoped skills from
* MemFS.
*/
client_skills?: Array<MessageCreateParams.ClientSkill> | null;
/**
* Client-side tools that the agent can call. When the agent calls a client-side
* tool, execution pauses and returns control to the client to execute the tool and
* provide the result via a ToolReturn.
*/
client_tools?: Array<MessageCreateParams.ClientTool> | null;
/**
* @deprecated If set to True, enables reasoning before responses or tool calls
* from the agent.
*/
enable_thinking?: string;
/**
* If True, compaction events emit structured `SummaryMessage` and `EventMessage`
* types. If False (default), compaction messages are not included in the response.
*/
include_compaction_messages?: boolean;
/**
* Whether to include periodic keepalive ping messages in the stream to prevent
* connection timeouts (only used when streaming=true).
*/
include_pings?: boolean;
/**
* Only return specified message types in the response. If `None` (default) returns
* all messages.
*/
include_return_message_types?: Array<MessagesAPI.MessageType> | null;
/**
* Syntactic sugar for a single user message. Equivalent to messages=[{'role':
* 'user', 'content': input}].
*/
input?:
| string
| Array<
| MessagesAPI.TextContent
| MessagesAPI.ImageContent
| MessagesAPI.ToolCallContent
| MessagesAPI.ToolReturnContent
| MessagesAPI.ReasoningContent
| MessagesAPI.RedactedReasoningContent
| MessagesAPI.OmittedReasoningContent
| MessageCreateParams.SummarizedReasoningContent
>
| null;
/**
* Maximum number of steps the agent should take to process the request.
*/
max_steps?: number;
/**
* The messages to be sent to the agent.
*/
messages?: Array<
AgentsAPI.MessageCreate | MessagesAPI.ApprovalCreate | MessageCreateParams.ToolReturnCreate
> | null;
/**
* Model handle to use for this request instead of the agent's default model. This
* allows sending a message to a different model without changing the agent's
* configuration.
*/
override_model?: string | null;
/**
* If True, returns log probabilities of the output tokens in the response. Useful
* for RL training. Only supported for OpenAI-compatible providers (including
* SGLang).
*/
return_logprobs?: boolean;
/**
* If True, returns token IDs and logprobs for ALL LLM generations in the agent
* step, not just the last one. Uses SGLang native /generate endpoint. Returns
* 'turns' field with TurnTokenData for each assistant/tool turn. Required for
* proper multi-turn RL training with loss masking.
*/
return_token_ids?: boolean;
/**
* Flag to determine if individual tokens should be streamed, rather than streaming
* per step (only used when streaming=true).
*/
stream_tokens?: boolean;
/**
* If True (default), returns a streaming response (Server-Sent Events). If False,
* returns a complete JSON response.
*/
streaming?: boolean;
/**
* Number of most likely tokens to return at each position (0-20). Requires
* return_logprobs=True.
*/
top_logprobs?: number | null;
/**
* @deprecated Whether the server should parse specific tool call arguments
* (default `send_message`) as `AssistantMessage` objects. Still supported for
* legacy agent types, but deprecated for letta_v1_agent onward.
*/
use_assistant_message?: boolean;
}
export namespace MessageCreateParams {
/**
* Schema for a client-side skill passed in the request.
*
* Client-side skills represent environment-provided capabilities (e.g.
* project-scoped skills) that are not stored in the agent's MemFS but should
* appear in the system prompt's available skills section.
*/
export interface ClientSkill {
/**
* Description of what the skill does
*/
description: string;
/**
* Path or location hint for the skill (e.g. skills/my-skill/SKILL.md)
*/
location: string;
/**
* The name of the skill
*/
name: string;
}
/**
* Schema for a client-side tool passed in the request.
*
* Client-side tools are executed by the client, not the server. When the agent
* calls a client-side tool, execution pauses and returns control to the client to
* execute the tool and provide the result.
*/
export interface ClientTool {
/**
* The name of the tool function
*/
name: string;
/**
* Description of what the tool does
*/
description?: string | null;
/**
* JSON Schema for the function parameters
*/
parameters?: { [key: string]: unknown } | null;
}
/**
* The style of reasoning content returned by the OpenAI Responses API
*/
export interface SummarizedReasoningContent {
/**
* The unique identifier for this reasoning step.
*/
id: string;
/**
* Summaries of the reasoning content.
*/
summary: Array<SummarizedReasoningContent.Summary>;
/**
* The encrypted reasoning content.
*/
encrypted_content?: string;
/**
* Indicates this is a summarized reasoning step.
*/
type?: 'summarized_reasoning';
}
export namespace SummarizedReasoningContent {
export interface Summary {
/**
* The index of the summary part.
*/
index: number;
/**
* The text of the summary part.
*/
text: string;
}
}
/**
* Submit tool return(s) from client-side tool execution.
*
* This is the preferred way to send tool results back to the agent after
* client-side tool execution. It is equivalent to sending an ApprovalCreate with
* tool return approvals, but provides a cleaner API for the common case.
*/
export interface ToolReturnCreate {
/**
* List of tool returns from client-side execution
*/
tool_returns: Array<MessagesAPI.ToolReturn>;
/**
* The message type to be created.
*/
type?: 'tool_return';
}
}
export interface MessageListParams extends ArrayPageParams {
/**
* Agent ID for agent-direct mode with 'default' conversation
*/
agent_id?: string | null;
/**
* Group ID to filter messages by.
*/
group_id?: string | null;
/**
* Whether to include error messages and error statuses. For debugging purposes
* only.
*/
include_err?: boolean | null;
}
export interface MessageCompactParams {
/**
* Agent ID for agent-direct mode with 'default' conversation. Use with
* conversation_id='default' in the URL path.
*/
agent_id?: string | null;
/**
* Configuration for conversation compaction / summarization.
*
* Per-model settings (temperature, max tokens, etc.) are derived from the default
* configuration for that handle.
*/
compaction_settings?: MessageCompactParams.CompactionSettings | null;
}
export namespace MessageCompactParams {
/**
* Configuration for conversation compaction / summarization.
*
* Per-model settings (temperature, max tokens, etc.) are derived from the default
* configuration for that handle.
*/
export interface CompactionSettings {
/**
* The maximum length of the summary in characters. If none, no clipping is
* performed.
*/
clip_chars?: number | null;
/**
* The type of summarization technique use.
*/
mode?: 'all' | 'sliding_window' | 'self_compact_all' | 'self_compact_sliding_window';
/**
* Model handle to use for sliding_window/all summarization (format:
* provider/model-name). If None, uses lightweight provider-specific defaults.
*/
model?: string | null;
/**
* Optional model settings used to override defaults for the summarizer model.
*/
model_settings?:
| AgentsAPI.OpenAIModelSettings
| AgentsAPI.AnthropicModelSettings
| AgentsAPI.GoogleAIModelSettings
| AgentsAPI.GoogleVertexModelSettings
| AgentsAPI.AzureModelSettings
| AgentsAPI.XaiModelSettings
| CompactionSettings.ZaiModelSettings
| AgentsAPI.GroqModelSettings
| AgentsAPI.DeepseekModelSettings
| AgentsAPI.TogetherModelSettings
| AgentsAPI.BedrockModelSettings
| CompactionSettings.OpenRouterModelSettings
| CompactionSettings.ChatGptoAuthModelSettings
| null;
/**
* The prompt to use for summarization. If None, uses mode-specific default.
*/
prompt?: string | null;
/**
* Whether to include an acknowledgement post-prompt (helps prevent non-summary
* outputs).
*/
prompt_acknowledgement?: boolean;
/**
* The percentage of the context window to keep post-summarization (only used in
* sliding window modes).
*/
sliding_window_percentage?: number;
}
export namespace CompactionSettings {
/**
* Z.ai (ZhipuAI) model configuration (OpenAI-compatible).
*/
export interface ZaiModelSettings {
/**
* The maximum number of tokens the model can generate.
*/
max_output_tokens?: number;
/**
* Whether to enable parallel tool calling.
*/
parallel_tool_calls?: boolean;
/**
* The type of the provider.
*/
provider_type?: 'zai';
/**
* The response format for the model.
*/
response_format?:
| AgentsAPI.TextResponseFormat
| AgentsAPI.JsonSchemaResponseFormat
| AgentsAPI.JsonObjectResponseFormat
| null;
/**
* The temperature of the model.
*/
temperature?: number;
/**
* The thinking configuration for GLM-4.5+ models.
*/
thinking?: ZaiModelSettings.Thinking;
}
export namespace ZaiModelSettings {
/**
* The thinking configuration for GLM-4.5+ models.
*/
export interface Thinking {
/**
* If False, preserved thinking is used (recommended for agents).
*/
clear_thinking?: boolean;
/**
* Whether thinking is enabled or disabled.
*/
type?: 'enabled' | 'disabled';
}
}
/**
* OpenRouter model configuration (OpenAI-compatible).
*/
export interface OpenRouterModelSettings {
/**
* The maximum number of tokens the model can generate.
*/
max_output_tokens?: number;
/**
* Whether to enable parallel tool calling.
*/
parallel_tool_calls?: boolean;
/**
* The type of the provider.
*/
provider_type?: 'openrouter';
/**
* The response format for the model.
*/
response_format?:
| AgentsAPI.TextResponseFormat
| AgentsAPI.JsonSchemaResponseFormat
| AgentsAPI.JsonObjectResponseFormat
| null;
/**
* The temperature of the model.
*/
temperature?: number;
}
/**
* ChatGPT OAuth model configuration (uses ChatGPT backend API).
*/
export interface ChatGptoAuthModelSettings {
/**
* The maximum number of tokens the model can generate.
*/
max_output_tokens?: number;
/**
* Whether to enable parallel tool calling.
*/
parallel_tool_calls?: boolean;
/**
* The type of the provider.
*/
provider_type?: 'chatgpt_oauth';
/**
* The reasoning configuration for the model.
*/
reasoning?: ChatGptoAuthModelSettings.Reasoning;
/**
* The temperature of the model.
*/
temperature?: number;
}
export namespace ChatGptoAuthModelSettings {
/**
* The reasoning configuration for the model.
*/
export interface Reasoning {
/**
* The reasoning effort level for GPT-5.x and o-series models.
*/
reasoning_effort?: 'none' | 'low' | 'medium' | 'high' | 'xhigh';
}
}
}
}
export interface MessageStreamParams {
/**
* Agent ID for agent-direct mode with 'default' conversation. Use with
* conversation_id='default' in the URL path.
*/
agent_id?: string | null;
/**
* Number of entries to read per batch.
*/
batch_size?: number | null;
/**
* Whether to include periodic keepalive ping messages in the stream to prevent
* connection timeouts.
*/
include_pings?: boolean | null;
/**
* Seconds to wait between polls when no new data.
*/
poll_interval?: number | null;
/**
* Sequence id to use as a cursor for pagination. Response will start streaming
* after this chunk sequence id
*/
starting_after?: number;
}
export declare namespace Messages {
export {
type CompactionRequest as CompactionRequest,
type CompactionResponse as CompactionResponse,
type MessageStreamResponse as MessageStreamResponse,
type MessageCreateParams as MessageCreateParams,
type MessageListParams as MessageListParams,
type MessageCompactParams as MessageCompactParams,
type MessageStreamParams as MessageStreamParams,
};
}
export { type MessagesArrayPage };