-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathagents.ts
More file actions
4621 lines (3944 loc) · 102 KB
/
Copy pathagents.ts
File metadata and controls
4621 lines (3944 loc) · 102 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
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// File generated from our OpenAPI spec by Castiron. See CONTRIBUTING.md for details.
import { APIResource } from '../../../core/resource';
import * as AgentsAPI from './agents';
import * as TurnsAPI from './sessions/turns';
import * as EnvironmentsAPI from './environments/environments';
import { EnvironmentInfo, Environments } from './environments/environments';
import * as SessionsAPI from './sessions/sessions';
import {
SessionCreateParams,
SessionCreateParamsNonStreaming,
SessionCreateParamsStreaming,
SessionListParams,
SessionUpdateParams,
Sessions,
} from './sessions/sessions';
import * as VaultsAPI from './vaults/vaults';
import {
Vault,
VaultCreateParams,
VaultDeleted,
VaultListParams,
VaultStatus,
VaultStatusFilter,
Vaults,
VaultsPage,
} from './vaults/vaults';
import { APIPromise } from '../../../core/api-promise';
import { CursorPage, type CursorPageParams, PagePromise } from '../../../core/pagination';
import { buildHeaders } from '../../../internal/headers';
import { RequestOptions } from '../../../internal/request-options';
import { path } from '../../../internal/utils/path';
export class Agents extends APIResource {
environments: EnvironmentsAPI.Environments = new EnvironmentsAPI.Environments(this._client);
vaults: VaultsAPI.Vaults = new VaultsAPI.Vaults(this._client);
sessions: SessionsAPI.Sessions = new SessionsAPI.Sessions(this._client);
/**
* Creates a reusable agent without storing credentials. See
* [agent configuration](https://developers.openai.com/api/docs/guides/agents-api/configuration).
*
* @example
* ```ts
* const agent = await client.beta.agents.create({
* model: 'model',
* });
* ```
*/
create(body: AgentCreateParams, options?: RequestOptions): APIPromise<Agent> {
return this._client.post('/agents', {
body,
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
__security: { bearerAuth: true },
});
}
/**
* Retrieves a reusable agent by ID. See
* [agent configuration](https://developers.openai.com/api/docs/guides/agents-api/configuration).
*
* @example
* ```ts
* const agent = await client.beta.agents.retrieve('agent_id');
* ```
*/
retrieve(agentID: string, options?: RequestOptions): APIPromise<Agent> {
return this._client.get(path`/agents/${agentID}`, {
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
__security: { bearerAuth: true },
});
}
/**
* Updates a reusable agent. See
* [agent configuration](https://developers.openai.com/api/docs/guides/agents-api/configuration).
*
* @example
* ```ts
* const agent = await client.beta.agents.update('agent_id');
* ```
*/
update(
agentID: string,
body: AgentUpdateParams | null | undefined = {},
options?: RequestOptions,
): APIPromise<Agent> {
return this._client.post(path`/agents/${agentID}`, {
body,
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
__security: { bearerAuth: true },
});
}
/**
* Lists reusable agents in the current project. See
* [agent configuration](https://developers.openai.com/api/docs/guides/agents-api/configuration).
*
* @example
* ```ts
* // Automatically fetches more pages as needed.
* for await (const agent of client.beta.agents.list()) {
* // ...
* }
* ```
*/
list(
query: AgentListParams | null | undefined = {},
options?: RequestOptions,
): PagePromise<AgentsPage, Agent> {
return this._client.getAPIList('/agents', CursorPage<Agent>, {
query,
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
__security: { bearerAuth: true },
});
}
/**
* Deletes a reusable agent. See
* [agent configuration](https://developers.openai.com/api/docs/guides/agents-api/configuration).
*
* @example
* ```ts
* const agentDeleted = await client.beta.agents.delete(
* 'agent_id',
* );
* ```
*/
delete(agentID: string, options?: RequestOptions): APIPromise<AgentDeleted> {
return this._client.delete(path`/agents/${agentID}`, {
...options,
headers: buildHeaders([{ 'OpenAI-Beta': 'agents=v1' }, options?.headers]),
__security: { bearerAuth: true },
});
}
}
export type AgentsPage = CursorPage<Agent>;
export type AgentSessionsPage = CursorPage<AgentSession>;
export type SubagentsPage = CursorPage<Subagent>;
export type AgentSessionItemsPage = CursorPage<AgentSessionItem>;
/**
* A reusable agent scoped to the caller's project.
*/
export interface Agent {
/**
* The ID of the reusable agent.
*/
id: string;
/**
* The Unix timestamp, in seconds, when the agent was created.
*/
created_at: number;
/**
* Custom instructions appended to the agent's default base instructions.
*/
instructions: string | null;
/**
* Custom string key-value pairs attached to the agent.
*/
metadata: { [key: string]: string };
/**
* The requested model name used for inference.
*/
model: string;
/**
* The resolved configuration for creating and coordinating subagents.
*/
multi_agent: MultiAgentConfig;
/**
* A human-readable name for the agent, or null if it is unnamed.
*/
name: string | null;
/**
* The object type. Always `agent`.
*/
object: 'agent';
/**
* The resolved reasoning configuration, including the model default for an omitted
* effort.
*/
reasoning: AgentReasoning;
/**
* The resolved service-tier policy used for model requests.
*/
service_tier: 'auto' | 'default' | 'flex' | 'priority' | 'fast';
/**
* The resolved configuration for text generated by the agent.
*/
text: AgentText;
/**
* Tools available to the agent.
*/
tools: Array<PersistedAgentTool>;
/**
* The Unix timestamp, in seconds, when the agent was last updated.
*/
updated_at: number;
}
/**
* A request to close a subagent.
*/
export interface AgentCloseSubagentCallItem {
/**
* The ID of the tool call item.
*/
id: string;
/**
* The ID of the agent to close.
*/
recipient_agent_id: string;
/**
* The ID of the agent requesting the close.
*/
sender_agent_id: string;
/**
* The status of the tool call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `close_subagent_call`.
*/
type: 'close_subagent_call';
}
/**
* A command execution produced by the agent.
*/
export interface AgentCommandExecutionItem {
/**
* The ID of the command execution item.
*/
id: string;
/**
* The command that was executed.
*/
command: string;
/**
* The working directory used to execute the command.
*/
cwd: string | null;
/**
* The command duration in milliseconds.
*/
duration_ms: number | null;
/**
* The process exit code, if the command completed.
*/
exit_code: number | null;
/**
* The command output, if available.
*/
output: string | null;
/**
* The status of the command execution.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `command_execution`.
*/
type: 'command_execution';
}
/**
* A plaintext or encrypted content part exchanged between agents.
*/
export type AgentContent = OutputText | AgentContent.EncryptedContentResource;
export namespace AgentContent {
/**
* Encrypted content exchanged between agents.
*/
export interface EncryptedContentResource {
/**
* The encrypted content payload.
*/
encrypted_content: string;
/**
* The content type. Always `encrypted_content`.
*/
type: 'encrypted_content';
}
}
/**
* A request to spawn a subagent.
*/
export interface AgentCreateSubagentCallItem {
/**
* The ID of the tool call item.
*/
id: string;
/**
* The ID of the agent that requested the subagent.
*/
agent_id: string;
/**
* The task given to the spawned agent.
*/
content: Array<AgentContent>;
/**
* The model requested for the spawned agent.
*/
model: string | null;
/**
* The reasoning effort requested for the spawned agent.
*/
reasoning_effort: string | null;
/**
* The status of the tool call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `create_subagent_call`.
*/
type: 'create_subagent_call';
}
/**
* A deleted reusable agent.
*/
export interface AgentDeleted {
/**
* The ID of the deleted agent.
*/
id: string;
/**
* Whether the agent was deleted. Always `true`.
*/
deleted: boolean;
/**
* The object type. Always `agent.deleted`.
*/
object: 'agent.deleted';
}
/**
* A function call produced by the agent.
*/
export interface AgentFunctionCallItem {
/**
* The ID of the function call item.
*/
id: string;
/**
* The arguments to pass to the function.
*/
arguments: unknown;
/**
* The ID used to submit the function result.
*/
call_id: string;
/**
* The name of the function to call.
*/
name: string;
/**
* The status of the function call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `function_call`.
*/
type: 'function_call';
}
/**
* The text or model-input content supplied as a function result.
*/
export type AgentFunctionCallOutput = string | Array<InputContent>;
/**
* A function result represented as text or supported model-input content.
*/
export type AgentFunctionCallOutputParam = string | Array<InputContentParam>;
/**
* The status of a tool call.
*
* - `in_progress` - The call is in progress.
* - `completed` - The call completed successfully.
* - `failed` - The call failed.
* - `incomplete` - The call stopped before completing.
*/
export type AgentFunctionCallStatus = 'in_progress' | 'completed' | 'failed' | 'incomplete';
/**
* A request to interrupt a subagent's current turn. The subagent remains
* available.
*/
export interface AgentInterruptSubagentCallItem {
/**
* The ID of the tool call item.
*/
id: string;
/**
* The ID of the agent to interrupt.
*/
recipient_agent_id: string;
/**
* The ID of the agent requesting the interrupt.
*/
sender_agent_id: string;
/**
* The status of the tool call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `interrupt_subagent_call`.
*/
type: 'interrupt_subagent_call';
}
/**
* A call to a tool on an MCP server.
*/
export interface AgentMcpCallItem {
/**
* The ID of the MCP call item.
*/
id: string;
/**
* The arguments passed to the MCP tool.
*/
arguments: unknown;
/**
* The error returned by the MCP tool, if any.
*/
error: unknown;
/**
* The name of the MCP tool.
*/
name: string;
/**
* The output returned by the MCP tool, if any.
*/
output: unknown;
/**
* The label of the MCP server.
*/
server_label: string;
/**
* The status of the MCP tool call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `mcp_call`.
*/
type: 'mcp_call';
}
/**
* Emitted when command execution produces an output delta.
*/
export interface AgentOutputCommandExecutionOutputDeltaEvent {
/**
* The output text that was appended.
*/
delta: string;
/**
* The unique ID of the event.
*/
event_id: string;
/**
* The ID of the command execution item.
*/
item_id: string;
/**
* The index of the item in the turn output.
*/
output_index: number;
/**
* The ID of the session associated with the event.
*/
session_id: string;
/**
* The ID of the turn associated with the event, when applicable.
*/
turn_id: string | null;
/**
* The type of the object. Always `agent.output.command_execution_output.delta`.
*/
type: 'agent.output.command_execution_output.delta';
}
/**
* An output item produced by an agent.
*/
export type AgentOutputItem =
| AgentSessionAssistantMessage
| AgentReasoningItem
| AgentFunctionCallItem
| AgentMcpCallItem
| AgentWebSearchCallItem
| AgentCommandExecutionItem
| AgentCreateSubagentCallItem
| AgentSendSubagentInputCallItem
| AgentResumeSubagentCallItem
| AgentWaitForSubagentsCallItem
| AgentInterruptSubagentCallItem
| AgentCloseSubagentCallItem;
/**
* The status of an agent output item.
*
* - `in_progress` - The item is in progress.
* - `completed` - The item is complete.
* - `incomplete` - The item stopped before completing.
*/
export type AgentOutputItemStatus = 'in_progress' | 'completed' | 'incomplete';
/**
* The reasoning configuration used by an agent.
*/
export interface AgentReasoning {
/**
* The amount of reasoning effort used by an agent.
*/
effort: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | null;
/**
* The reasoning summary format requested from an agent.
*
* - `concise` - Returns a concise reasoning summary when supported.
* - `detailed` - Returns a detailed reasoning summary when supported.
* - `auto` - Automatically selects the most detailed summary supported by the
* model.
*/
summary: 'concise' | 'detailed' | 'auto' | null;
}
/**
* A reasoning item produced by the agent.
*/
export interface AgentReasoningItem {
/**
* The ID of the reasoning item.
*/
id: string;
/**
* The status of an agent output item.
*/
status: AgentOutputItemStatus | null;
/**
* The reasoning summaries produced by the agent.
*/
summary: Array<SummaryText>;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `reasoning`.
*/
type: 'reasoning';
}
/**
* Reasoning configuration for the agent.
*/
export interface AgentReasoningParam {
/**
* The amount of reasoning effort the model should use.
*/
effort?: 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh' | 'max' | null;
/**
* The reasoning summary format requested from the model.
*
* - `concise` - Returns a concise reasoning summary when supported.
* - `detailed` - Returns a detailed reasoning summary when supported.
* - `auto` - Automatically selects the most detailed summary supported by the
* model.
*/
summary?: 'concise' | 'detailed' | 'auto' | null;
}
/**
* A request to resume a subagent.
*/
export interface AgentResumeSubagentCallItem {
/**
* The ID of the tool call item.
*/
id: string;
/**
* The ID of the agent to resume.
*/
recipient_agent_id: string;
/**
* The ID of the agent requesting the resume.
*/
sender_agent_id: string;
/**
* The status of the tool call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `resume_subagent_call`.
*/
type: 'resume_subagent_call';
}
/**
* A request to send input to another agent.
*/
export interface AgentSendSubagentInputCallItem {
/**
* The ID of the tool call item.
*/
id: string;
/**
* The input sent to the receiving agent.
*/
content: Array<AgentContent>;
/**
* The ID of the agent receiving the input.
*/
recipient_agent_id: string;
/**
* The ID of the agent sending the input.
*/
sender_agent_id: string;
/**
* The status of the tool call.
*/
status: AgentFunctionCallStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `send_subagent_input_call`.
*/
type: 'send_subagent_input_call';
}
/**
* A Managed Agents session.
*/
export interface AgentSession {
/**
* The ID of the session.
*/
id: string;
/**
* The agent running in the session.
*/
agent: AgentSession.Agent;
/**
* The Unix timestamp, in seconds, when the session was created.
*/
created_at: number;
/**
* The execution environment for the session.
*/
environment: Environment;
/**
* The error that caused the session to fail, if any.
*/
error: string | null;
/**
* The Unix timestamp, in seconds, when the session was last active.
*/
last_active_at: number;
/**
* Custom string key-value pairs attached to the session.
*/
metadata: { [key: string]: string };
/**
* The object type. Always `agent.session`.
*/
object: 'agent.session';
/**
* Actions that must be completed before the session can continue.
*/
required_actions: Array<
| AgentSession.SessionRequiredActionResourceFunctionCall
| AgentSession.SessionRequiredActionResourceEnvironmentConnection
>;
/**
* The current status of the session.
*
* - `idle` - The session has no turn in progress and is ready for input. A hosted
* environment may still be provisioning.
* - `in_progress` - The session is processing a turn.
* - `requires_action` - The session is waiting for one or more required actions.
* - `failed` - The session failed.
*/
status: 'idle' | 'in_progress' | 'requires_action' | 'failed';
/**
* Recorded token usage for a session or turn. Usage is best effort and may change.
*/
usage: TokenUsage | null;
/**
* The IDs of vaults made available to the session.
*/
vault_ids: Array<string>;
}
export namespace AgentSession {
/**
* The agent running in the session.
*/
export interface Agent {
/**
* The ID of the agent.
*/
id: string;
/**
* Custom instructions appended to the agent's default base instructions.
*/
instructions: string | null;
/**
* The model used by the agent.
*/
model: string;
/**
* Configuration for creating and coordinating subagents.
*/
multi_agent: AgentsAPI.MultiAgentConfig;
/**
* The reusable agent's name when the session was created, or null if no name was
* saved. Later changes to the agent's name do not affect this value.
*/
name: string | null;
/**
* The agent's reasoning configuration.
*/
reasoning: AgentsAPI.AgentReasoning;
/**
* The effective service-tier policy for model requests. Defaults to `auto`.
*/
service_tier: 'auto' | 'default' | 'flex' | 'priority' | 'fast';
/**
* Configuration for text generated by the agent.
*/
text: AgentsAPI.AgentText;
/**
* Tools available to the agent.
*/
tools: Array<AgentsAPI.AgentTool>;
}
/**
* Run a function tool and submit its result.
*/
export interface SessionRequiredActionResourceFunctionCall {
/**
* The arguments supplied by the model.
*/
arguments: unknown;
/**
* The ID to include when submitting the function result.
*/
call_id: string;
/**
* The function name.
*/
name: string;
/**
* The ID of the turn that requested the function call.
*/
turn_id: string;
/**
* The type of the object. Always `function_call`.
*/
type: 'function_call';
}
/**
* Reconnect a session environment.
*/
export interface SessionRequiredActionResourceEnvironmentConnection {
/**
* The ID of the environment to reconnect.
*/
environment_id: string;
/**
* The type of the object. Always `environment_connection`.
*/
type: 'environment_connection';
}
}
/**
* An assistant message produced by the agent.
*/
export interface AgentSessionAssistantMessage {
/**
* The ID of the message.
*/
id: string;
/**
* The content of the message.
*/
content: Array<OutputText>;
/**
* The phase of an assistant message.
*
* - `commentary` - Commentary produced while the agent works.
* - `final_answer` - The agent's final answer.
*/
phase: 'commentary' | 'final_answer' | null;
/**
* The role of the message author. Always `assistant`.
*/
role: 'assistant';
/**
* The status of the message.
*/
status: AgentOutputItemStatus;
/**
* The ID of the turn that contains this item.
*/
turn_id: string;
/**
* The item type. Always `message`.
*/
type: 'message';
}
/**
* Emitted when a session is created.
*/
export interface AgentSessionCreatedEvent {
/**
* The unique ID of the event.
*/
event_id: string;
/**
* The session that was created.
*/
session: AgentSession;
/**
* The type of the object. Always `agent.session.created`.
*/
type: 'agent.session.created';
}
/**
* A Managed Agents session removed from the public API. Physical cleanup may
* continue asynchronously.
*/
export interface AgentSessionDeleted {
/**
* The ID of the deleted session.
*/
id: string;
/**
* Whether the session has been removed from the public API. Always `true`.
* Physical cleanup may still be in progress.
*/
deleted: boolean;