-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathbetasessionevent.go
More file actions
4879 lines (4344 loc) · 191 KB
/
betasessionevent.go
File metadata and controls
4879 lines (4344 loc) · 191 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 Stainless. See CONTRIBUTING.md for details.
package anthropic
import (
"context"
"encoding/json"
"errors"
"fmt"
"net/http"
"net/url"
"slices"
"time"
"github.com/anthropics/anthropic-sdk-go/internal/apijson"
"github.com/anthropics/anthropic-sdk-go/internal/apiquery"
"github.com/anthropics/anthropic-sdk-go/internal/requestconfig"
"github.com/anthropics/anthropic-sdk-go/option"
"github.com/anthropics/anthropic-sdk-go/packages/pagination"
"github.com/anthropics/anthropic-sdk-go/packages/param"
"github.com/anthropics/anthropic-sdk-go/packages/respjson"
"github.com/anthropics/anthropic-sdk-go/packages/ssestream"
)
// BetaSessionEventService contains methods and other services that help with
// interacting with the anthropic API.
//
// Note, unlike clients, this service does not read variables from the environment
// automatically. You should not instantiate this service directly, and instead use
// the [NewBetaSessionEventService] method instead.
type BetaSessionEventService struct {
Options []option.RequestOption
}
// NewBetaSessionEventService generates a new service that applies the given
// options to each request. These options are applied after the parent client's
// options (if there is one), and before any request-specific options.
func NewBetaSessionEventService(opts ...option.RequestOption) (r BetaSessionEventService) {
r = BetaSessionEventService{}
r.Options = opts
return
}
// List Events
func (r *BetaSessionEventService) List(ctx context.Context, sessionID string, params BetaSessionEventListParams, opts ...option.RequestOption) (res *pagination.PageCursor[BetaManagedAgentsSessionEventUnion], err error) {
var raw *http.Response
for _, v := range params.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01"), option.WithResponseInto(&raw)}, opts...)
if sessionID == "" {
err = errors.New("missing required session_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/sessions/%s/events?beta=true", sessionID)
cfg, err := requestconfig.NewRequestConfig(ctx, http.MethodGet, path, params, &res, opts...)
if err != nil {
return nil, err
}
err = cfg.Execute()
if err != nil {
return nil, err
}
res.SetPageConfig(cfg, raw)
return res, nil
}
// List Events
func (r *BetaSessionEventService) ListAutoPaging(ctx context.Context, sessionID string, params BetaSessionEventListParams, opts ...option.RequestOption) *pagination.PageCursorAutoPager[BetaManagedAgentsSessionEventUnion] {
return pagination.NewPageCursorAutoPager(r.List(ctx, sessionID, params, opts...))
}
// Send Events
func (r *BetaSessionEventService) Send(ctx context.Context, sessionID string, params BetaSessionEventSendParams, opts ...option.RequestOption) (res *BetaManagedAgentsSendSessionEvents, err error) {
for _, v := range params.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...)
if sessionID == "" {
err = errors.New("missing required session_id parameter")
return nil, err
}
path := fmt.Sprintf("v1/sessions/%s/events?beta=true", sessionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodPost, path, params, &res, opts...)
return res, err
}
// Stream Events
func (r *BetaSessionEventService) StreamEvents(ctx context.Context, sessionID string, query BetaSessionEventStreamParams, opts ...option.RequestOption) (stream *ssestream.Stream[BetaManagedAgentsStreamSessionEventsUnion]) {
var (
raw *http.Response
err error
)
for _, v := range query.Betas {
opts = append(opts, option.WithHeaderAdd("anthropic-beta", fmt.Sprintf("%v", v)))
}
opts = slices.Concat(r.Options, opts)
opts = append([]option.RequestOption{option.WithHeader("anthropic-beta", "managed-agents-2026-04-01")}, opts...)
if sessionID == "" {
err = errors.New("missing required session_id parameter")
return ssestream.NewStream[BetaManagedAgentsStreamSessionEventsUnion](nil, err)
}
path := fmt.Sprintf("v1/sessions/%s/events/stream?beta=true", sessionID)
err = requestconfig.ExecuteNewRequest(ctx, http.MethodGet, path, nil, &raw, opts...)
return ssestream.NewStream[BetaManagedAgentsStreamSessionEventsUnion](ssestream.NewDecoder(raw), err)
}
// Event emitted when the agent calls a custom tool. The session goes idle until
// the client sends a `user.custom_tool_result` event with the result.
type BetaManagedAgentsAgentCustomToolUseEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// Input parameters for the tool call.
Input map[string]any `json:"input" api:"required"`
// Name of the custom tool being called.
Name string `json:"name" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.custom_tool_use".
Type BetaManagedAgentsAgentCustomToolUseEventType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Input respjson.Field
Name respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentCustomToolUseEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentCustomToolUseEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentCustomToolUseEventType string
const (
BetaManagedAgentsAgentCustomToolUseEventTypeAgentCustomToolUse BetaManagedAgentsAgentCustomToolUseEventType = "agent.custom_tool_use"
)
// Event representing the result of an MCP tool execution.
type BetaManagedAgentsAgentMCPToolResultEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// The id of the `agent.mcp_tool_use` event this result corresponds to.
MCPToolUseID string `json:"mcp_tool_use_id" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.mcp_tool_result".
Type BetaManagedAgentsAgentMCPToolResultEventType `json:"type" api:"required"`
// The result content returned by the tool.
Content []BetaManagedAgentsAgentMCPToolResultEventContentUnion `json:"content"`
// Whether the tool execution resulted in an error.
IsError bool `json:"is_error" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
MCPToolUseID respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
Content respjson.Field
IsError respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentMCPToolResultEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentMCPToolResultEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentMCPToolResultEventType string
const (
BetaManagedAgentsAgentMCPToolResultEventTypeAgentMCPToolResult BetaManagedAgentsAgentMCPToolResultEventType = "agent.mcp_tool_result"
)
// BetaManagedAgentsAgentMCPToolResultEventContentUnion contains all possible
// properties and values from [BetaManagedAgentsTextBlock],
// [BetaManagedAgentsImageBlock], [BetaManagedAgentsDocumentBlock].
//
// Use the [BetaManagedAgentsAgentMCPToolResultEventContentUnion.AsAny] method to
// switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaManagedAgentsAgentMCPToolResultEventContentUnion struct {
// This field is from variant [BetaManagedAgentsTextBlock].
Text string `json:"text"`
// Any of "text", "image", "document".
Type string `json:"type"`
// This field is a union of [BetaManagedAgentsImageBlockSourceUnion],
// [BetaManagedAgentsDocumentBlockSourceUnion]
Source BetaManagedAgentsAgentMCPToolResultEventContentUnionSource `json:"source"`
// This field is from variant [BetaManagedAgentsDocumentBlock].
Context string `json:"context"`
// This field is from variant [BetaManagedAgentsDocumentBlock].
Title string `json:"title"`
JSON struct {
Text respjson.Field
Type respjson.Field
Source respjson.Field
Context respjson.Field
Title respjson.Field
raw string
} `json:"-"`
}
// anyBetaManagedAgentsAgentMCPToolResultEventContent is implemented by each
// variant of [BetaManagedAgentsAgentMCPToolResultEventContentUnion] to add type
// safety for the return type of
// [BetaManagedAgentsAgentMCPToolResultEventContentUnion.AsAny]
type anyBetaManagedAgentsAgentMCPToolResultEventContent interface {
implBetaManagedAgentsAgentMCPToolResultEventContentUnion()
}
func (BetaManagedAgentsTextBlock) implBetaManagedAgentsAgentMCPToolResultEventContentUnion() {}
func (BetaManagedAgentsImageBlock) implBetaManagedAgentsAgentMCPToolResultEventContentUnion() {}
func (BetaManagedAgentsDocumentBlock) implBetaManagedAgentsAgentMCPToolResultEventContentUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := BetaManagedAgentsAgentMCPToolResultEventContentUnion.AsAny().(type) {
// case anthropic.BetaManagedAgentsTextBlock:
// case anthropic.BetaManagedAgentsImageBlock:
// case anthropic.BetaManagedAgentsDocumentBlock:
// default:
// fmt.Errorf("no variant present")
// }
func (u BetaManagedAgentsAgentMCPToolResultEventContentUnion) AsAny() anyBetaManagedAgentsAgentMCPToolResultEventContent {
switch u.Type {
case "text":
return u.AsText()
case "image":
return u.AsImage()
case "document":
return u.AsDocument()
}
return nil
}
func (u BetaManagedAgentsAgentMCPToolResultEventContentUnion) AsText() (v BetaManagedAgentsTextBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsAgentMCPToolResultEventContentUnion) AsImage() (v BetaManagedAgentsImageBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsAgentMCPToolResultEventContentUnion) AsDocument() (v BetaManagedAgentsDocumentBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaManagedAgentsAgentMCPToolResultEventContentUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaManagedAgentsAgentMCPToolResultEventContentUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// BetaManagedAgentsAgentMCPToolResultEventContentUnionSource is an implicit
// subunion of [BetaManagedAgentsAgentMCPToolResultEventContentUnion].
// BetaManagedAgentsAgentMCPToolResultEventContentUnionSource provides convenient
// access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [BetaManagedAgentsAgentMCPToolResultEventContentUnion].
type BetaManagedAgentsAgentMCPToolResultEventContentUnionSource struct {
Data string `json:"data"`
MediaType string `json:"media_type"`
Type string `json:"type"`
URL string `json:"url"`
FileID string `json:"file_id"`
JSON struct {
Data respjson.Field
MediaType respjson.Field
Type respjson.Field
URL respjson.Field
FileID respjson.Field
raw string
} `json:"-"`
}
func (r *BetaManagedAgentsAgentMCPToolResultEventContentUnionSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Event emitted when the agent invokes a tool provided by an MCP server.
type BetaManagedAgentsAgentMCPToolUseEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// Input parameters for the tool call.
Input map[string]any `json:"input" api:"required"`
// Name of the MCP server providing the tool.
MCPServerName string `json:"mcp_server_name" api:"required"`
// Name of the MCP tool being used.
Name string `json:"name" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.mcp_tool_use".
Type BetaManagedAgentsAgentMCPToolUseEventType `json:"type" api:"required"`
// AgentEvaluatedPermission enum
//
// Any of "allow", "ask", "deny".
EvaluatedPermission BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermission `json:"evaluated_permission"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Input respjson.Field
MCPServerName respjson.Field
Name respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
EvaluatedPermission respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentMCPToolUseEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentMCPToolUseEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentMCPToolUseEventType string
const (
BetaManagedAgentsAgentMCPToolUseEventTypeAgentMCPToolUse BetaManagedAgentsAgentMCPToolUseEventType = "agent.mcp_tool_use"
)
// AgentEvaluatedPermission enum
type BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermission string
const (
BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermissionAllow BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermission = "allow"
BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermissionAsk BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermission = "ask"
BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermissionDeny BetaManagedAgentsAgentMCPToolUseEventEvaluatedPermission = "deny"
)
// An agent response event in the session conversation.
type BetaManagedAgentsAgentMessageEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// Array of text blocks comprising the agent response.
Content []BetaManagedAgentsTextBlock `json:"content" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.message".
Type BetaManagedAgentsAgentMessageEventType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Content respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentMessageEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentMessageEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentMessageEventType string
const (
BetaManagedAgentsAgentMessageEventTypeAgentMessage BetaManagedAgentsAgentMessageEventType = "agent.message"
)
// Indicates the agent is making forward progress via extended thinking. A progress
// signal, not a content carrier.
type BetaManagedAgentsAgentThinkingEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.thinking".
Type BetaManagedAgentsAgentThinkingEventType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentThinkingEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentThinkingEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentThinkingEventType string
const (
BetaManagedAgentsAgentThinkingEventTypeAgentThinking BetaManagedAgentsAgentThinkingEventType = "agent.thinking"
)
// Indicates that context compaction (summarization) occurred during the session.
type BetaManagedAgentsAgentThreadContextCompactedEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.thread_context_compacted".
Type BetaManagedAgentsAgentThreadContextCompactedEventType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentThreadContextCompactedEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentThreadContextCompactedEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentThreadContextCompactedEventType string
const (
BetaManagedAgentsAgentThreadContextCompactedEventTypeAgentThreadContextCompacted BetaManagedAgentsAgentThreadContextCompactedEventType = "agent.thread_context_compacted"
)
// Event representing the result of an agent tool execution.
type BetaManagedAgentsAgentToolResultEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// The id of the `agent.tool_use` event this result corresponds to.
ToolUseID string `json:"tool_use_id" api:"required"`
// Any of "agent.tool_result".
Type BetaManagedAgentsAgentToolResultEventType `json:"type" api:"required"`
// The result content returned by the tool.
Content []BetaManagedAgentsAgentToolResultEventContentUnion `json:"content"`
// Whether the tool execution resulted in an error.
IsError bool `json:"is_error" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
ProcessedAt respjson.Field
ToolUseID respjson.Field
Type respjson.Field
Content respjson.Field
IsError respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentToolResultEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentToolResultEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentToolResultEventType string
const (
BetaManagedAgentsAgentToolResultEventTypeAgentToolResult BetaManagedAgentsAgentToolResultEventType = "agent.tool_result"
)
// BetaManagedAgentsAgentToolResultEventContentUnion contains all possible
// properties and values from [BetaManagedAgentsTextBlock],
// [BetaManagedAgentsImageBlock], [BetaManagedAgentsDocumentBlock].
//
// Use the [BetaManagedAgentsAgentToolResultEventContentUnion.AsAny] method to
// switch on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaManagedAgentsAgentToolResultEventContentUnion struct {
// This field is from variant [BetaManagedAgentsTextBlock].
Text string `json:"text"`
// Any of "text", "image", "document".
Type string `json:"type"`
// This field is a union of [BetaManagedAgentsImageBlockSourceUnion],
// [BetaManagedAgentsDocumentBlockSourceUnion]
Source BetaManagedAgentsAgentToolResultEventContentUnionSource `json:"source"`
// This field is from variant [BetaManagedAgentsDocumentBlock].
Context string `json:"context"`
// This field is from variant [BetaManagedAgentsDocumentBlock].
Title string `json:"title"`
JSON struct {
Text respjson.Field
Type respjson.Field
Source respjson.Field
Context respjson.Field
Title respjson.Field
raw string
} `json:"-"`
}
// anyBetaManagedAgentsAgentToolResultEventContent is implemented by each variant
// of [BetaManagedAgentsAgentToolResultEventContentUnion] to add type safety for
// the return type of [BetaManagedAgentsAgentToolResultEventContentUnion.AsAny]
type anyBetaManagedAgentsAgentToolResultEventContent interface {
implBetaManagedAgentsAgentToolResultEventContentUnion()
}
func (BetaManagedAgentsTextBlock) implBetaManagedAgentsAgentToolResultEventContentUnion() {}
func (BetaManagedAgentsImageBlock) implBetaManagedAgentsAgentToolResultEventContentUnion() {}
func (BetaManagedAgentsDocumentBlock) implBetaManagedAgentsAgentToolResultEventContentUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := BetaManagedAgentsAgentToolResultEventContentUnion.AsAny().(type) {
// case anthropic.BetaManagedAgentsTextBlock:
// case anthropic.BetaManagedAgentsImageBlock:
// case anthropic.BetaManagedAgentsDocumentBlock:
// default:
// fmt.Errorf("no variant present")
// }
func (u BetaManagedAgentsAgentToolResultEventContentUnion) AsAny() anyBetaManagedAgentsAgentToolResultEventContent {
switch u.Type {
case "text":
return u.AsText()
case "image":
return u.AsImage()
case "document":
return u.AsDocument()
}
return nil
}
func (u BetaManagedAgentsAgentToolResultEventContentUnion) AsText() (v BetaManagedAgentsTextBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsAgentToolResultEventContentUnion) AsImage() (v BetaManagedAgentsImageBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsAgentToolResultEventContentUnion) AsDocument() (v BetaManagedAgentsDocumentBlock) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaManagedAgentsAgentToolResultEventContentUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaManagedAgentsAgentToolResultEventContentUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// BetaManagedAgentsAgentToolResultEventContentUnionSource is an implicit subunion
// of [BetaManagedAgentsAgentToolResultEventContentUnion].
// BetaManagedAgentsAgentToolResultEventContentUnionSource provides convenient
// access to the sub-properties of the union.
//
// For type safety it is recommended to directly use a variant of the
// [BetaManagedAgentsAgentToolResultEventContentUnion].
type BetaManagedAgentsAgentToolResultEventContentUnionSource struct {
Data string `json:"data"`
MediaType string `json:"media_type"`
Type string `json:"type"`
URL string `json:"url"`
FileID string `json:"file_id"`
JSON struct {
Data respjson.Field
MediaType respjson.Field
Type respjson.Field
URL respjson.Field
FileID respjson.Field
raw string
} `json:"-"`
}
func (r *BetaManagedAgentsAgentToolResultEventContentUnionSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Event emitted when the agent invokes a built-in agent tool.
type BetaManagedAgentsAgentToolUseEvent struct {
// Unique identifier for this event.
ID string `json:"id" api:"required"`
// Input parameters for the tool call.
Input map[string]any `json:"input" api:"required"`
// Name of the agent tool being used.
Name string `json:"name" api:"required"`
// A timestamp in RFC 3339 format
ProcessedAt time.Time `json:"processed_at" api:"required" format:"date-time"`
// Any of "agent.tool_use".
Type BetaManagedAgentsAgentToolUseEventType `json:"type" api:"required"`
// AgentEvaluatedPermission enum
//
// Any of "allow", "ask", "deny".
EvaluatedPermission BetaManagedAgentsAgentToolUseEventEvaluatedPermission `json:"evaluated_permission"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
ID respjson.Field
Input respjson.Field
Name respjson.Field
ProcessedAt respjson.Field
Type respjson.Field
EvaluatedPermission respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsAgentToolUseEvent) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsAgentToolUseEvent) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsAgentToolUseEventType string
const (
BetaManagedAgentsAgentToolUseEventTypeAgentToolUse BetaManagedAgentsAgentToolUseEventType = "agent.tool_use"
)
// AgentEvaluatedPermission enum
type BetaManagedAgentsAgentToolUseEventEvaluatedPermission string
const (
BetaManagedAgentsAgentToolUseEventEvaluatedPermissionAllow BetaManagedAgentsAgentToolUseEventEvaluatedPermission = "allow"
BetaManagedAgentsAgentToolUseEventEvaluatedPermissionAsk BetaManagedAgentsAgentToolUseEventEvaluatedPermission = "ask"
BetaManagedAgentsAgentToolUseEventEvaluatedPermissionDeny BetaManagedAgentsAgentToolUseEventEvaluatedPermission = "deny"
)
// Base64-encoded document data.
type BetaManagedAgentsBase64DocumentSource struct {
// Base64-encoded document data.
Data string `json:"data" api:"required"`
// MIME type of the document (e.g., "application/pdf").
MediaType string `json:"media_type" api:"required"`
// Any of "base64".
Type BetaManagedAgentsBase64DocumentSourceType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
MediaType respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsBase64DocumentSource) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsBase64DocumentSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this BetaManagedAgentsBase64DocumentSource to a
// BetaManagedAgentsBase64DocumentSourceParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// BetaManagedAgentsBase64DocumentSourceParam.Overrides()
func (r BetaManagedAgentsBase64DocumentSource) ToParam() BetaManagedAgentsBase64DocumentSourceParam {
return param.Override[BetaManagedAgentsBase64DocumentSourceParam](json.RawMessage(r.RawJSON()))
}
type BetaManagedAgentsBase64DocumentSourceType string
const (
BetaManagedAgentsBase64DocumentSourceTypeBase64 BetaManagedAgentsBase64DocumentSourceType = "base64"
)
// Base64-encoded document data.
//
// The properties Data, MediaType, Type are required.
type BetaManagedAgentsBase64DocumentSourceParam struct {
// Base64-encoded document data.
Data string `json:"data" api:"required"`
// MIME type of the document (e.g., "application/pdf").
MediaType string `json:"media_type" api:"required"`
// Any of "base64".
Type BetaManagedAgentsBase64DocumentSourceType `json:"type,omitzero" api:"required"`
paramObj
}
func (r BetaManagedAgentsBase64DocumentSourceParam) MarshalJSON() (data []byte, err error) {
type shadow BetaManagedAgentsBase64DocumentSourceParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaManagedAgentsBase64DocumentSourceParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// Base64-encoded image data.
type BetaManagedAgentsBase64ImageSource struct {
// Base64-encoded image data.
Data string `json:"data" api:"required"`
// MIME type of the image (e.g., "image/png", "image/jpeg", "image/gif",
// "image/webp").
MediaType string `json:"media_type" api:"required"`
// Any of "base64".
Type BetaManagedAgentsBase64ImageSourceType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Data respjson.Field
MediaType respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsBase64ImageSource) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsBase64ImageSource) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this BetaManagedAgentsBase64ImageSource to a
// BetaManagedAgentsBase64ImageSourceParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// BetaManagedAgentsBase64ImageSourceParam.Overrides()
func (r BetaManagedAgentsBase64ImageSource) ToParam() BetaManagedAgentsBase64ImageSourceParam {
return param.Override[BetaManagedAgentsBase64ImageSourceParam](json.RawMessage(r.RawJSON()))
}
type BetaManagedAgentsBase64ImageSourceType string
const (
BetaManagedAgentsBase64ImageSourceTypeBase64 BetaManagedAgentsBase64ImageSourceType = "base64"
)
// Base64-encoded image data.
//
// The properties Data, MediaType, Type are required.
type BetaManagedAgentsBase64ImageSourceParam struct {
// Base64-encoded image data.
Data string `json:"data" api:"required"`
// MIME type of the image (e.g., "image/png", "image/jpeg", "image/gif",
// "image/webp").
MediaType string `json:"media_type" api:"required"`
// Any of "base64".
Type BetaManagedAgentsBase64ImageSourceType `json:"type,omitzero" api:"required"`
paramObj
}
func (r BetaManagedAgentsBase64ImageSourceParam) MarshalJSON() (data []byte, err error) {
type shadow BetaManagedAgentsBase64ImageSourceParam
return param.MarshalObject(r, (*shadow)(&r))
}
func (r *BetaManagedAgentsBase64ImageSourceParam) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// The caller's organization or workspace cannot make model requests — out of
// credits or spend limit reached. Retrying with the same credentials will not
// succeed; the caller must resolve the billing state.
type BetaManagedAgentsBillingError struct {
// Human-readable error description.
Message string `json:"message" api:"required"`
// What the client should do next in response to this error.
RetryStatus BetaManagedAgentsBillingErrorRetryStatusUnion `json:"retry_status" api:"required"`
// Any of "billing_error".
Type BetaManagedAgentsBillingErrorType `json:"type" api:"required"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Message respjson.Field
RetryStatus respjson.Field
Type respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsBillingError) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsBillingError) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// BetaManagedAgentsBillingErrorRetryStatusUnion contains all possible properties
// and values from [BetaManagedAgentsRetryStatusRetrying],
// [BetaManagedAgentsRetryStatusExhausted], [BetaManagedAgentsRetryStatusTerminal].
//
// Use the [BetaManagedAgentsBillingErrorRetryStatusUnion.AsAny] method to switch
// on the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaManagedAgentsBillingErrorRetryStatusUnion struct {
// Any of "retrying", "exhausted", "terminal".
Type string `json:"type"`
JSON struct {
Type respjson.Field
raw string
} `json:"-"`
}
// anyBetaManagedAgentsBillingErrorRetryStatus is implemented by each variant of
// [BetaManagedAgentsBillingErrorRetryStatusUnion] to add type safety for the
// return type of [BetaManagedAgentsBillingErrorRetryStatusUnion.AsAny]
type anyBetaManagedAgentsBillingErrorRetryStatus interface {
implBetaManagedAgentsBillingErrorRetryStatusUnion()
}
func (BetaManagedAgentsRetryStatusRetrying) implBetaManagedAgentsBillingErrorRetryStatusUnion() {}
func (BetaManagedAgentsRetryStatusExhausted) implBetaManagedAgentsBillingErrorRetryStatusUnion() {}
func (BetaManagedAgentsRetryStatusTerminal) implBetaManagedAgentsBillingErrorRetryStatusUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := BetaManagedAgentsBillingErrorRetryStatusUnion.AsAny().(type) {
// case anthropic.BetaManagedAgentsRetryStatusRetrying:
// case anthropic.BetaManagedAgentsRetryStatusExhausted:
// case anthropic.BetaManagedAgentsRetryStatusTerminal:
// default:
// fmt.Errorf("no variant present")
// }
func (u BetaManagedAgentsBillingErrorRetryStatusUnion) AsAny() anyBetaManagedAgentsBillingErrorRetryStatus {
switch u.Type {
case "retrying":
return u.AsRetrying()
case "exhausted":
return u.AsExhausted()
case "terminal":
return u.AsTerminal()
}
return nil
}
func (u BetaManagedAgentsBillingErrorRetryStatusUnion) AsRetrying() (v BetaManagedAgentsRetryStatusRetrying) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsBillingErrorRetryStatusUnion) AsExhausted() (v BetaManagedAgentsRetryStatusExhausted) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsBillingErrorRetryStatusUnion) AsTerminal() (v BetaManagedAgentsRetryStatusTerminal) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaManagedAgentsBillingErrorRetryStatusUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaManagedAgentsBillingErrorRetryStatusUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
type BetaManagedAgentsBillingErrorType string
const (
BetaManagedAgentsBillingErrorTypeBillingError BetaManagedAgentsBillingErrorType = "billing_error"
)
// Document content, either specified directly as base64 data, as text, or as a
// reference via a URL.
type BetaManagedAgentsDocumentBlock struct {
// Union type for document source variants.
Source BetaManagedAgentsDocumentBlockSourceUnion `json:"source" api:"required"`
// Any of "document".
Type BetaManagedAgentsDocumentBlockType `json:"type" api:"required"`
// Additional context about the document for the model.
Context string `json:"context" api:"nullable"`
// The title of the document.
Title string `json:"title" api:"nullable"`
// JSON contains metadata for fields, check presence with [respjson.Field.Valid].
JSON struct {
Source respjson.Field
Type respjson.Field
Context respjson.Field
Title respjson.Field
ExtraFields map[string]respjson.Field
raw string
} `json:"-"`
}
// Returns the unmodified JSON received from the API
func (r BetaManagedAgentsDocumentBlock) RawJSON() string { return r.JSON.raw }
func (r *BetaManagedAgentsDocumentBlock) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}
// ToParam converts this BetaManagedAgentsDocumentBlock to a
// BetaManagedAgentsDocumentBlockParam.
//
// Warning: the fields of the param type will not be present. ToParam should only
// be used at the last possible moment before sending a request. Test for this with
// BetaManagedAgentsDocumentBlockParam.Overrides()
func (r BetaManagedAgentsDocumentBlock) ToParam() BetaManagedAgentsDocumentBlockParam {
return param.Override[BetaManagedAgentsDocumentBlockParam](json.RawMessage(r.RawJSON()))
}
// BetaManagedAgentsDocumentBlockSourceUnion contains all possible properties and
// values from [BetaManagedAgentsBase64DocumentSource],
// [BetaManagedAgentsPlainTextDocumentSource],
// [BetaManagedAgentsURLDocumentSource], [BetaManagedAgentsFileDocumentSource].
//
// Use the [BetaManagedAgentsDocumentBlockSourceUnion.AsAny] method to switch on
// the variant.
//
// Use the methods beginning with 'As' to cast the union to one of its variants.
type BetaManagedAgentsDocumentBlockSourceUnion struct {
Data string `json:"data"`
MediaType string `json:"media_type"`
// Any of "base64", "text", "url", "file".
Type string `json:"type"`
// This field is from variant [BetaManagedAgentsURLDocumentSource].
URL string `json:"url"`
// This field is from variant [BetaManagedAgentsFileDocumentSource].
FileID string `json:"file_id"`
JSON struct {
Data respjson.Field
MediaType respjson.Field
Type respjson.Field
URL respjson.Field
FileID respjson.Field
raw string
} `json:"-"`
}
// anyBetaManagedAgentsDocumentBlockSource is implemented by each variant of
// [BetaManagedAgentsDocumentBlockSourceUnion] to add type safety for the return
// type of [BetaManagedAgentsDocumentBlockSourceUnion.AsAny]
type anyBetaManagedAgentsDocumentBlockSource interface {
implBetaManagedAgentsDocumentBlockSourceUnion()
}
func (BetaManagedAgentsBase64DocumentSource) implBetaManagedAgentsDocumentBlockSourceUnion() {}
func (BetaManagedAgentsPlainTextDocumentSource) implBetaManagedAgentsDocumentBlockSourceUnion() {}
func (BetaManagedAgentsURLDocumentSource) implBetaManagedAgentsDocumentBlockSourceUnion() {}
func (BetaManagedAgentsFileDocumentSource) implBetaManagedAgentsDocumentBlockSourceUnion() {}
// Use the following switch statement to find the correct variant
//
// switch variant := BetaManagedAgentsDocumentBlockSourceUnion.AsAny().(type) {
// case anthropic.BetaManagedAgentsBase64DocumentSource:
// case anthropic.BetaManagedAgentsPlainTextDocumentSource:
// case anthropic.BetaManagedAgentsURLDocumentSource:
// case anthropic.BetaManagedAgentsFileDocumentSource:
// default:
// fmt.Errorf("no variant present")
// }
func (u BetaManagedAgentsDocumentBlockSourceUnion) AsAny() anyBetaManagedAgentsDocumentBlockSource {
switch u.Type {
case "base64":
return u.AsBase64()
case "text":
return u.AsText()
case "url":
return u.AsURL()
case "file":
return u.AsFile()
}
return nil
}
func (u BetaManagedAgentsDocumentBlockSourceUnion) AsBase64() (v BetaManagedAgentsBase64DocumentSource) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsDocumentBlockSourceUnion) AsText() (v BetaManagedAgentsPlainTextDocumentSource) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsDocumentBlockSourceUnion) AsURL() (v BetaManagedAgentsURLDocumentSource) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
func (u BetaManagedAgentsDocumentBlockSourceUnion) AsFile() (v BetaManagedAgentsFileDocumentSource) {
apijson.UnmarshalRoot(json.RawMessage(u.JSON.raw), &v)
return
}
// Returns the unmodified JSON received from the API
func (u BetaManagedAgentsDocumentBlockSourceUnion) RawJSON() string { return u.JSON.raw }
func (r *BetaManagedAgentsDocumentBlockSourceUnion) UnmarshalJSON(data []byte) error {
return apijson.UnmarshalRoot(data, r)
}