mistralai 1.7.1__py3-none-any.whl → 1.8.0__py3-none-any.whl

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.
Files changed (86) hide show
  1. mistralai/_version.py +2 -2
  2. mistralai/beta.py +20 -0
  3. mistralai/conversations.py +2657 -0
  4. mistralai/extra/__init__.py +10 -2
  5. mistralai/extra/exceptions.py +14 -0
  6. mistralai/extra/mcp/__init__.py +0 -0
  7. mistralai/extra/mcp/auth.py +166 -0
  8. mistralai/extra/mcp/base.py +155 -0
  9. mistralai/extra/mcp/sse.py +165 -0
  10. mistralai/extra/mcp/stdio.py +22 -0
  11. mistralai/extra/run/__init__.py +0 -0
  12. mistralai/extra/run/context.py +295 -0
  13. mistralai/extra/run/result.py +212 -0
  14. mistralai/extra/run/tools.py +225 -0
  15. mistralai/extra/run/utils.py +36 -0
  16. mistralai/extra/tests/test_struct_chat.py +1 -1
  17. mistralai/mistral_agents.py +1158 -0
  18. mistralai/models/__init__.py +470 -1
  19. mistralai/models/agent.py +129 -0
  20. mistralai/models/agentconversation.py +71 -0
  21. mistralai/models/agentcreationrequest.py +109 -0
  22. mistralai/models/agenthandoffdoneevent.py +33 -0
  23. mistralai/models/agenthandoffentry.py +75 -0
  24. mistralai/models/agenthandoffstartedevent.py +33 -0
  25. mistralai/models/agents_api_v1_agents_getop.py +16 -0
  26. mistralai/models/agents_api_v1_agents_listop.py +24 -0
  27. mistralai/models/agents_api_v1_agents_update_versionop.py +21 -0
  28. mistralai/models/agents_api_v1_agents_updateop.py +23 -0
  29. mistralai/models/agents_api_v1_conversations_append_streamop.py +28 -0
  30. mistralai/models/agents_api_v1_conversations_appendop.py +28 -0
  31. mistralai/models/agents_api_v1_conversations_getop.py +33 -0
  32. mistralai/models/agents_api_v1_conversations_historyop.py +16 -0
  33. mistralai/models/agents_api_v1_conversations_listop.py +37 -0
  34. mistralai/models/agents_api_v1_conversations_messagesop.py +16 -0
  35. mistralai/models/agents_api_v1_conversations_restart_streamop.py +26 -0
  36. mistralai/models/agents_api_v1_conversations_restartop.py +26 -0
  37. mistralai/models/agentupdaterequest.py +111 -0
  38. mistralai/models/builtinconnectors.py +13 -0
  39. mistralai/models/codeinterpretertool.py +17 -0
  40. mistralai/models/completionargs.py +100 -0
  41. mistralai/models/completionargsstop.py +13 -0
  42. mistralai/models/completionjobout.py +3 -3
  43. mistralai/models/conversationappendrequest.py +35 -0
  44. mistralai/models/conversationappendstreamrequest.py +37 -0
  45. mistralai/models/conversationevents.py +72 -0
  46. mistralai/models/conversationhistory.py +58 -0
  47. mistralai/models/conversationinputs.py +14 -0
  48. mistralai/models/conversationmessages.py +28 -0
  49. mistralai/models/conversationrequest.py +133 -0
  50. mistralai/models/conversationresponse.py +51 -0
  51. mistralai/models/conversationrestartrequest.py +42 -0
  52. mistralai/models/conversationrestartstreamrequest.py +44 -0
  53. mistralai/models/conversationstreamrequest.py +135 -0
  54. mistralai/models/conversationusageinfo.py +63 -0
  55. mistralai/models/documentlibrarytool.py +22 -0
  56. mistralai/models/functioncallentry.py +76 -0
  57. mistralai/models/functioncallentryarguments.py +15 -0
  58. mistralai/models/functioncallevent.py +36 -0
  59. mistralai/models/functionresultentry.py +69 -0
  60. mistralai/models/functiontool.py +21 -0
  61. mistralai/models/imagegenerationtool.py +17 -0
  62. mistralai/models/inputentries.py +18 -0
  63. mistralai/models/messageentries.py +18 -0
  64. mistralai/models/messageinputcontentchunks.py +26 -0
  65. mistralai/models/messageinputentry.py +89 -0
  66. mistralai/models/messageoutputcontentchunks.py +30 -0
  67. mistralai/models/messageoutputentry.py +100 -0
  68. mistralai/models/messageoutputevent.py +93 -0
  69. mistralai/models/modelconversation.py +127 -0
  70. mistralai/models/outputcontentchunks.py +30 -0
  71. mistralai/models/responsedoneevent.py +25 -0
  72. mistralai/models/responseerrorevent.py +27 -0
  73. mistralai/models/responsestartedevent.py +24 -0
  74. mistralai/models/ssetypes.py +18 -0
  75. mistralai/models/toolexecutiondoneevent.py +34 -0
  76. mistralai/models/toolexecutionentry.py +70 -0
  77. mistralai/models/toolexecutionstartedevent.py +31 -0
  78. mistralai/models/toolfilechunk.py +61 -0
  79. mistralai/models/toolreferencechunk.py +61 -0
  80. mistralai/models/websearchpremiumtool.py +17 -0
  81. mistralai/models/websearchtool.py +17 -0
  82. mistralai/sdk.py +3 -0
  83. {mistralai-1.7.1.dist-info → mistralai-1.8.0.dist-info}/METADATA +42 -7
  84. {mistralai-1.7.1.dist-info → mistralai-1.8.0.dist-info}/RECORD +86 -10
  85. {mistralai-1.7.1.dist-info → mistralai-1.8.0.dist-info}/LICENSE +0 -0
  86. {mistralai-1.7.1.dist-info → mistralai-1.8.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,1158 @@
1
+ """Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
2
+
3
+ from .basesdk import BaseSDK
4
+ from mistralai import models, utils
5
+ from mistralai._hooks import HookContext
6
+ from mistralai.types import OptionalNullable, UNSET
7
+ from mistralai.utils import get_security_from_env
8
+ from typing import Any, List, Mapping, Optional, Union
9
+
10
+
11
+ class MistralAgents(BaseSDK):
12
+ def create(
13
+ self,
14
+ *,
15
+ model: str,
16
+ name: str,
17
+ instructions: OptionalNullable[str] = UNSET,
18
+ tools: Optional[
19
+ Union[
20
+ List[models.AgentCreationRequestTools],
21
+ List[models.AgentCreationRequestToolsTypedDict],
22
+ ]
23
+ ] = None,
24
+ completion_args: Optional[
25
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
26
+ ] = None,
27
+ description: OptionalNullable[str] = UNSET,
28
+ handoffs: OptionalNullable[List[str]] = UNSET,
29
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
30
+ server_url: Optional[str] = None,
31
+ timeout_ms: Optional[int] = None,
32
+ http_headers: Optional[Mapping[str, str]] = None,
33
+ ) -> models.Agent:
34
+ r"""Create a agent that can be used within a conversation.
35
+
36
+ Create a new agent giving it instructions, tools, description. The agent is then available to be used as a regular assistant in a conversation or as part of an agent pool from which it can be used.
37
+
38
+ :param model:
39
+ :param name:
40
+ :param instructions: Instruction prompt the model will follow during the conversation.
41
+ :param tools: List of tools which are available to the model during the conversation.
42
+ :param completion_args: White-listed arguments from the completion API
43
+ :param description:
44
+ :param handoffs:
45
+ :param retries: Override the default retry configuration for this method
46
+ :param server_url: Override the default server URL for this method
47
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
48
+ :param http_headers: Additional headers to set or replace on requests.
49
+ """
50
+ base_url = None
51
+ url_variables = None
52
+ if timeout_ms is None:
53
+ timeout_ms = self.sdk_configuration.timeout_ms
54
+
55
+ if server_url is not None:
56
+ base_url = server_url
57
+ else:
58
+ base_url = self._get_url(base_url, url_variables)
59
+
60
+ request = models.AgentCreationRequest(
61
+ instructions=instructions,
62
+ tools=utils.get_pydantic_model(
63
+ tools, Optional[List[models.AgentCreationRequestTools]]
64
+ ),
65
+ completion_args=utils.get_pydantic_model(
66
+ completion_args, Optional[models.CompletionArgs]
67
+ ),
68
+ model=model,
69
+ name=name,
70
+ description=description,
71
+ handoffs=handoffs,
72
+ )
73
+
74
+ req = self._build_request(
75
+ method="POST",
76
+ path="/v1/agents",
77
+ base_url=base_url,
78
+ url_variables=url_variables,
79
+ request=request,
80
+ request_body_required=True,
81
+ request_has_path_params=False,
82
+ request_has_query_params=True,
83
+ user_agent_header="user-agent",
84
+ accept_header_value="application/json",
85
+ http_headers=http_headers,
86
+ security=self.sdk_configuration.security,
87
+ get_serialized_body=lambda: utils.serialize_request_body(
88
+ request, False, False, "json", models.AgentCreationRequest
89
+ ),
90
+ timeout_ms=timeout_ms,
91
+ )
92
+
93
+ if retries == UNSET:
94
+ if self.sdk_configuration.retry_config is not UNSET:
95
+ retries = self.sdk_configuration.retry_config
96
+
97
+ retry_config = None
98
+ if isinstance(retries, utils.RetryConfig):
99
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
100
+
101
+ http_res = self.do_request(
102
+ hook_ctx=HookContext(
103
+ base_url=base_url or "",
104
+ operation_id="agents_api_v1_agents_create",
105
+ oauth2_scopes=[],
106
+ security_source=get_security_from_env(
107
+ self.sdk_configuration.security, models.Security
108
+ ),
109
+ ),
110
+ request=req,
111
+ error_status_codes=["422", "4XX", "5XX"],
112
+ retry_config=retry_config,
113
+ )
114
+
115
+ response_data: Any = None
116
+ if utils.match_response(http_res, "200", "application/json"):
117
+ return utils.unmarshal_json(http_res.text, models.Agent)
118
+ if utils.match_response(http_res, "422", "application/json"):
119
+ response_data = utils.unmarshal_json(
120
+ http_res.text, models.HTTPValidationErrorData
121
+ )
122
+ raise models.HTTPValidationError(data=response_data)
123
+ if utils.match_response(http_res, "4XX", "*"):
124
+ http_res_text = utils.stream_to_text(http_res)
125
+ raise models.SDKError(
126
+ "API error occurred", http_res.status_code, http_res_text, http_res
127
+ )
128
+ if utils.match_response(http_res, "5XX", "*"):
129
+ http_res_text = utils.stream_to_text(http_res)
130
+ raise models.SDKError(
131
+ "API error occurred", http_res.status_code, http_res_text, http_res
132
+ )
133
+
134
+ content_type = http_res.headers.get("Content-Type")
135
+ http_res_text = utils.stream_to_text(http_res)
136
+ raise models.SDKError(
137
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
138
+ http_res.status_code,
139
+ http_res_text,
140
+ http_res,
141
+ )
142
+
143
+ async def create_async(
144
+ self,
145
+ *,
146
+ model: str,
147
+ name: str,
148
+ instructions: OptionalNullable[str] = UNSET,
149
+ tools: Optional[
150
+ Union[
151
+ List[models.AgentCreationRequestTools],
152
+ List[models.AgentCreationRequestToolsTypedDict],
153
+ ]
154
+ ] = None,
155
+ completion_args: Optional[
156
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
157
+ ] = None,
158
+ description: OptionalNullable[str] = UNSET,
159
+ handoffs: OptionalNullable[List[str]] = UNSET,
160
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
161
+ server_url: Optional[str] = None,
162
+ timeout_ms: Optional[int] = None,
163
+ http_headers: Optional[Mapping[str, str]] = None,
164
+ ) -> models.Agent:
165
+ r"""Create a agent that can be used within a conversation.
166
+
167
+ Create a new agent giving it instructions, tools, description. The agent is then available to be used as a regular assistant in a conversation or as part of an agent pool from which it can be used.
168
+
169
+ :param model:
170
+ :param name:
171
+ :param instructions: Instruction prompt the model will follow during the conversation.
172
+ :param tools: List of tools which are available to the model during the conversation.
173
+ :param completion_args: White-listed arguments from the completion API
174
+ :param description:
175
+ :param handoffs:
176
+ :param retries: Override the default retry configuration for this method
177
+ :param server_url: Override the default server URL for this method
178
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
179
+ :param http_headers: Additional headers to set or replace on requests.
180
+ """
181
+ base_url = None
182
+ url_variables = None
183
+ if timeout_ms is None:
184
+ timeout_ms = self.sdk_configuration.timeout_ms
185
+
186
+ if server_url is not None:
187
+ base_url = server_url
188
+ else:
189
+ base_url = self._get_url(base_url, url_variables)
190
+
191
+ request = models.AgentCreationRequest(
192
+ instructions=instructions,
193
+ tools=utils.get_pydantic_model(
194
+ tools, Optional[List[models.AgentCreationRequestTools]]
195
+ ),
196
+ completion_args=utils.get_pydantic_model(
197
+ completion_args, Optional[models.CompletionArgs]
198
+ ),
199
+ model=model,
200
+ name=name,
201
+ description=description,
202
+ handoffs=handoffs,
203
+ )
204
+
205
+ req = self._build_request_async(
206
+ method="POST",
207
+ path="/v1/agents",
208
+ base_url=base_url,
209
+ url_variables=url_variables,
210
+ request=request,
211
+ request_body_required=True,
212
+ request_has_path_params=False,
213
+ request_has_query_params=True,
214
+ user_agent_header="user-agent",
215
+ accept_header_value="application/json",
216
+ http_headers=http_headers,
217
+ security=self.sdk_configuration.security,
218
+ get_serialized_body=lambda: utils.serialize_request_body(
219
+ request, False, False, "json", models.AgentCreationRequest
220
+ ),
221
+ timeout_ms=timeout_ms,
222
+ )
223
+
224
+ if retries == UNSET:
225
+ if self.sdk_configuration.retry_config is not UNSET:
226
+ retries = self.sdk_configuration.retry_config
227
+
228
+ retry_config = None
229
+ if isinstance(retries, utils.RetryConfig):
230
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
231
+
232
+ http_res = await self.do_request_async(
233
+ hook_ctx=HookContext(
234
+ base_url=base_url or "",
235
+ operation_id="agents_api_v1_agents_create",
236
+ oauth2_scopes=[],
237
+ security_source=get_security_from_env(
238
+ self.sdk_configuration.security, models.Security
239
+ ),
240
+ ),
241
+ request=req,
242
+ error_status_codes=["422", "4XX", "5XX"],
243
+ retry_config=retry_config,
244
+ )
245
+
246
+ response_data: Any = None
247
+ if utils.match_response(http_res, "200", "application/json"):
248
+ return utils.unmarshal_json(http_res.text, models.Agent)
249
+ if utils.match_response(http_res, "422", "application/json"):
250
+ response_data = utils.unmarshal_json(
251
+ http_res.text, models.HTTPValidationErrorData
252
+ )
253
+ raise models.HTTPValidationError(data=response_data)
254
+ if utils.match_response(http_res, "4XX", "*"):
255
+ http_res_text = await utils.stream_to_text_async(http_res)
256
+ raise models.SDKError(
257
+ "API error occurred", http_res.status_code, http_res_text, http_res
258
+ )
259
+ if utils.match_response(http_res, "5XX", "*"):
260
+ http_res_text = await utils.stream_to_text_async(http_res)
261
+ raise models.SDKError(
262
+ "API error occurred", http_res.status_code, http_res_text, http_res
263
+ )
264
+
265
+ content_type = http_res.headers.get("Content-Type")
266
+ http_res_text = await utils.stream_to_text_async(http_res)
267
+ raise models.SDKError(
268
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
269
+ http_res.status_code,
270
+ http_res_text,
271
+ http_res,
272
+ )
273
+
274
+ def list(
275
+ self,
276
+ *,
277
+ page: Optional[int] = 0,
278
+ page_size: Optional[int] = 20,
279
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
280
+ server_url: Optional[str] = None,
281
+ timeout_ms: Optional[int] = None,
282
+ http_headers: Optional[Mapping[str, str]] = None,
283
+ ) -> List[models.Agent]:
284
+ r"""List agent entities.
285
+
286
+ Retrieve a list of agent entities sorted by creation time.
287
+
288
+ :param page:
289
+ :param page_size:
290
+ :param retries: Override the default retry configuration for this method
291
+ :param server_url: Override the default server URL for this method
292
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
293
+ :param http_headers: Additional headers to set or replace on requests.
294
+ """
295
+ base_url = None
296
+ url_variables = None
297
+ if timeout_ms is None:
298
+ timeout_ms = self.sdk_configuration.timeout_ms
299
+
300
+ if server_url is not None:
301
+ base_url = server_url
302
+ else:
303
+ base_url = self._get_url(base_url, url_variables)
304
+
305
+ request = models.AgentsAPIV1AgentsListRequest(
306
+ page=page,
307
+ page_size=page_size,
308
+ )
309
+
310
+ req = self._build_request(
311
+ method="GET",
312
+ path="/v1/agents",
313
+ base_url=base_url,
314
+ url_variables=url_variables,
315
+ request=request,
316
+ request_body_required=False,
317
+ request_has_path_params=False,
318
+ request_has_query_params=True,
319
+ user_agent_header="user-agent",
320
+ accept_header_value="application/json",
321
+ http_headers=http_headers,
322
+ security=self.sdk_configuration.security,
323
+ timeout_ms=timeout_ms,
324
+ )
325
+
326
+ if retries == UNSET:
327
+ if self.sdk_configuration.retry_config is not UNSET:
328
+ retries = self.sdk_configuration.retry_config
329
+
330
+ retry_config = None
331
+ if isinstance(retries, utils.RetryConfig):
332
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
333
+
334
+ http_res = self.do_request(
335
+ hook_ctx=HookContext(
336
+ base_url=base_url or "",
337
+ operation_id="agents_api_v1_agents_list",
338
+ oauth2_scopes=[],
339
+ security_source=get_security_from_env(
340
+ self.sdk_configuration.security, models.Security
341
+ ),
342
+ ),
343
+ request=req,
344
+ error_status_codes=["422", "4XX", "5XX"],
345
+ retry_config=retry_config,
346
+ )
347
+
348
+ response_data: Any = None
349
+ if utils.match_response(http_res, "200", "application/json"):
350
+ return utils.unmarshal_json(http_res.text, List[models.Agent])
351
+ if utils.match_response(http_res, "422", "application/json"):
352
+ response_data = utils.unmarshal_json(
353
+ http_res.text, models.HTTPValidationErrorData
354
+ )
355
+ raise models.HTTPValidationError(data=response_data)
356
+ if utils.match_response(http_res, "4XX", "*"):
357
+ http_res_text = utils.stream_to_text(http_res)
358
+ raise models.SDKError(
359
+ "API error occurred", http_res.status_code, http_res_text, http_res
360
+ )
361
+ if utils.match_response(http_res, "5XX", "*"):
362
+ http_res_text = utils.stream_to_text(http_res)
363
+ raise models.SDKError(
364
+ "API error occurred", http_res.status_code, http_res_text, http_res
365
+ )
366
+
367
+ content_type = http_res.headers.get("Content-Type")
368
+ http_res_text = utils.stream_to_text(http_res)
369
+ raise models.SDKError(
370
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
371
+ http_res.status_code,
372
+ http_res_text,
373
+ http_res,
374
+ )
375
+
376
+ async def list_async(
377
+ self,
378
+ *,
379
+ page: Optional[int] = 0,
380
+ page_size: Optional[int] = 20,
381
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
382
+ server_url: Optional[str] = None,
383
+ timeout_ms: Optional[int] = None,
384
+ http_headers: Optional[Mapping[str, str]] = None,
385
+ ) -> List[models.Agent]:
386
+ r"""List agent entities.
387
+
388
+ Retrieve a list of agent entities sorted by creation time.
389
+
390
+ :param page:
391
+ :param page_size:
392
+ :param retries: Override the default retry configuration for this method
393
+ :param server_url: Override the default server URL for this method
394
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
395
+ :param http_headers: Additional headers to set or replace on requests.
396
+ """
397
+ base_url = None
398
+ url_variables = None
399
+ if timeout_ms is None:
400
+ timeout_ms = self.sdk_configuration.timeout_ms
401
+
402
+ if server_url is not None:
403
+ base_url = server_url
404
+ else:
405
+ base_url = self._get_url(base_url, url_variables)
406
+
407
+ request = models.AgentsAPIV1AgentsListRequest(
408
+ page=page,
409
+ page_size=page_size,
410
+ )
411
+
412
+ req = self._build_request_async(
413
+ method="GET",
414
+ path="/v1/agents",
415
+ base_url=base_url,
416
+ url_variables=url_variables,
417
+ request=request,
418
+ request_body_required=False,
419
+ request_has_path_params=False,
420
+ request_has_query_params=True,
421
+ user_agent_header="user-agent",
422
+ accept_header_value="application/json",
423
+ http_headers=http_headers,
424
+ security=self.sdk_configuration.security,
425
+ timeout_ms=timeout_ms,
426
+ )
427
+
428
+ if retries == UNSET:
429
+ if self.sdk_configuration.retry_config is not UNSET:
430
+ retries = self.sdk_configuration.retry_config
431
+
432
+ retry_config = None
433
+ if isinstance(retries, utils.RetryConfig):
434
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
435
+
436
+ http_res = await self.do_request_async(
437
+ hook_ctx=HookContext(
438
+ base_url=base_url or "",
439
+ operation_id="agents_api_v1_agents_list",
440
+ oauth2_scopes=[],
441
+ security_source=get_security_from_env(
442
+ self.sdk_configuration.security, models.Security
443
+ ),
444
+ ),
445
+ request=req,
446
+ error_status_codes=["422", "4XX", "5XX"],
447
+ retry_config=retry_config,
448
+ )
449
+
450
+ response_data: Any = None
451
+ if utils.match_response(http_res, "200", "application/json"):
452
+ return utils.unmarshal_json(http_res.text, List[models.Agent])
453
+ if utils.match_response(http_res, "422", "application/json"):
454
+ response_data = utils.unmarshal_json(
455
+ http_res.text, models.HTTPValidationErrorData
456
+ )
457
+ raise models.HTTPValidationError(data=response_data)
458
+ if utils.match_response(http_res, "4XX", "*"):
459
+ http_res_text = await utils.stream_to_text_async(http_res)
460
+ raise models.SDKError(
461
+ "API error occurred", http_res.status_code, http_res_text, http_res
462
+ )
463
+ if utils.match_response(http_res, "5XX", "*"):
464
+ http_res_text = await utils.stream_to_text_async(http_res)
465
+ raise models.SDKError(
466
+ "API error occurred", http_res.status_code, http_res_text, http_res
467
+ )
468
+
469
+ content_type = http_res.headers.get("Content-Type")
470
+ http_res_text = await utils.stream_to_text_async(http_res)
471
+ raise models.SDKError(
472
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
473
+ http_res.status_code,
474
+ http_res_text,
475
+ http_res,
476
+ )
477
+
478
+ def get(
479
+ self,
480
+ *,
481
+ agent_id: str,
482
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
483
+ server_url: Optional[str] = None,
484
+ timeout_ms: Optional[int] = None,
485
+ http_headers: Optional[Mapping[str, str]] = None,
486
+ ) -> models.Agent:
487
+ r"""Retrieve an agent entity.
488
+
489
+ Given an agent retrieve an agent entity with its attributes.
490
+
491
+ :param agent_id:
492
+ :param retries: Override the default retry configuration for this method
493
+ :param server_url: Override the default server URL for this method
494
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
495
+ :param http_headers: Additional headers to set or replace on requests.
496
+ """
497
+ base_url = None
498
+ url_variables = None
499
+ if timeout_ms is None:
500
+ timeout_ms = self.sdk_configuration.timeout_ms
501
+
502
+ if server_url is not None:
503
+ base_url = server_url
504
+ else:
505
+ base_url = self._get_url(base_url, url_variables)
506
+
507
+ request = models.AgentsAPIV1AgentsGetRequest(
508
+ agent_id=agent_id,
509
+ )
510
+
511
+ req = self._build_request(
512
+ method="GET",
513
+ path="/v1/agents/{agent_id}",
514
+ base_url=base_url,
515
+ url_variables=url_variables,
516
+ request=request,
517
+ request_body_required=False,
518
+ request_has_path_params=True,
519
+ request_has_query_params=True,
520
+ user_agent_header="user-agent",
521
+ accept_header_value="application/json",
522
+ http_headers=http_headers,
523
+ security=self.sdk_configuration.security,
524
+ timeout_ms=timeout_ms,
525
+ )
526
+
527
+ if retries == UNSET:
528
+ if self.sdk_configuration.retry_config is not UNSET:
529
+ retries = self.sdk_configuration.retry_config
530
+
531
+ retry_config = None
532
+ if isinstance(retries, utils.RetryConfig):
533
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
534
+
535
+ http_res = self.do_request(
536
+ hook_ctx=HookContext(
537
+ base_url=base_url or "",
538
+ operation_id="agents_api_v1_agents_get",
539
+ oauth2_scopes=[],
540
+ security_source=get_security_from_env(
541
+ self.sdk_configuration.security, models.Security
542
+ ),
543
+ ),
544
+ request=req,
545
+ error_status_codes=["422", "4XX", "5XX"],
546
+ retry_config=retry_config,
547
+ )
548
+
549
+ response_data: Any = None
550
+ if utils.match_response(http_res, "200", "application/json"):
551
+ return utils.unmarshal_json(http_res.text, models.Agent)
552
+ if utils.match_response(http_res, "422", "application/json"):
553
+ response_data = utils.unmarshal_json(
554
+ http_res.text, models.HTTPValidationErrorData
555
+ )
556
+ raise models.HTTPValidationError(data=response_data)
557
+ if utils.match_response(http_res, "4XX", "*"):
558
+ http_res_text = utils.stream_to_text(http_res)
559
+ raise models.SDKError(
560
+ "API error occurred", http_res.status_code, http_res_text, http_res
561
+ )
562
+ if utils.match_response(http_res, "5XX", "*"):
563
+ http_res_text = utils.stream_to_text(http_res)
564
+ raise models.SDKError(
565
+ "API error occurred", http_res.status_code, http_res_text, http_res
566
+ )
567
+
568
+ content_type = http_res.headers.get("Content-Type")
569
+ http_res_text = utils.stream_to_text(http_res)
570
+ raise models.SDKError(
571
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
572
+ http_res.status_code,
573
+ http_res_text,
574
+ http_res,
575
+ )
576
+
577
+ async def get_async(
578
+ self,
579
+ *,
580
+ agent_id: str,
581
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
582
+ server_url: Optional[str] = None,
583
+ timeout_ms: Optional[int] = None,
584
+ http_headers: Optional[Mapping[str, str]] = None,
585
+ ) -> models.Agent:
586
+ r"""Retrieve an agent entity.
587
+
588
+ Given an agent retrieve an agent entity with its attributes.
589
+
590
+ :param agent_id:
591
+ :param retries: Override the default retry configuration for this method
592
+ :param server_url: Override the default server URL for this method
593
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
594
+ :param http_headers: Additional headers to set or replace on requests.
595
+ """
596
+ base_url = None
597
+ url_variables = None
598
+ if timeout_ms is None:
599
+ timeout_ms = self.sdk_configuration.timeout_ms
600
+
601
+ if server_url is not None:
602
+ base_url = server_url
603
+ else:
604
+ base_url = self._get_url(base_url, url_variables)
605
+
606
+ request = models.AgentsAPIV1AgentsGetRequest(
607
+ agent_id=agent_id,
608
+ )
609
+
610
+ req = self._build_request_async(
611
+ method="GET",
612
+ path="/v1/agents/{agent_id}",
613
+ base_url=base_url,
614
+ url_variables=url_variables,
615
+ request=request,
616
+ request_body_required=False,
617
+ request_has_path_params=True,
618
+ request_has_query_params=True,
619
+ user_agent_header="user-agent",
620
+ accept_header_value="application/json",
621
+ http_headers=http_headers,
622
+ security=self.sdk_configuration.security,
623
+ timeout_ms=timeout_ms,
624
+ )
625
+
626
+ if retries == UNSET:
627
+ if self.sdk_configuration.retry_config is not UNSET:
628
+ retries = self.sdk_configuration.retry_config
629
+
630
+ retry_config = None
631
+ if isinstance(retries, utils.RetryConfig):
632
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
633
+
634
+ http_res = await self.do_request_async(
635
+ hook_ctx=HookContext(
636
+ base_url=base_url or "",
637
+ operation_id="agents_api_v1_agents_get",
638
+ oauth2_scopes=[],
639
+ security_source=get_security_from_env(
640
+ self.sdk_configuration.security, models.Security
641
+ ),
642
+ ),
643
+ request=req,
644
+ error_status_codes=["422", "4XX", "5XX"],
645
+ retry_config=retry_config,
646
+ )
647
+
648
+ response_data: Any = None
649
+ if utils.match_response(http_res, "200", "application/json"):
650
+ return utils.unmarshal_json(http_res.text, models.Agent)
651
+ if utils.match_response(http_res, "422", "application/json"):
652
+ response_data = utils.unmarshal_json(
653
+ http_res.text, models.HTTPValidationErrorData
654
+ )
655
+ raise models.HTTPValidationError(data=response_data)
656
+ if utils.match_response(http_res, "4XX", "*"):
657
+ http_res_text = await utils.stream_to_text_async(http_res)
658
+ raise models.SDKError(
659
+ "API error occurred", http_res.status_code, http_res_text, http_res
660
+ )
661
+ if utils.match_response(http_res, "5XX", "*"):
662
+ http_res_text = await utils.stream_to_text_async(http_res)
663
+ raise models.SDKError(
664
+ "API error occurred", http_res.status_code, http_res_text, http_res
665
+ )
666
+
667
+ content_type = http_res.headers.get("Content-Type")
668
+ http_res_text = await utils.stream_to_text_async(http_res)
669
+ raise models.SDKError(
670
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
671
+ http_res.status_code,
672
+ http_res_text,
673
+ http_res,
674
+ )
675
+
676
+ def update(
677
+ self,
678
+ *,
679
+ agent_id: str,
680
+ instructions: OptionalNullable[str] = UNSET,
681
+ tools: Optional[
682
+ Union[
683
+ List[models.AgentUpdateRequestTools],
684
+ List[models.AgentUpdateRequestToolsTypedDict],
685
+ ]
686
+ ] = None,
687
+ completion_args: Optional[
688
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
689
+ ] = None,
690
+ model: OptionalNullable[str] = UNSET,
691
+ name: OptionalNullable[str] = UNSET,
692
+ description: OptionalNullable[str] = UNSET,
693
+ handoffs: OptionalNullable[List[str]] = UNSET,
694
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
695
+ server_url: Optional[str] = None,
696
+ timeout_ms: Optional[int] = None,
697
+ http_headers: Optional[Mapping[str, str]] = None,
698
+ ) -> models.Agent:
699
+ r"""Update an agent entity.
700
+
701
+ Update an agent attributes and create a new version.
702
+
703
+ :param agent_id:
704
+ :param instructions: Instruction prompt the model will follow during the conversation.
705
+ :param tools: List of tools which are available to the model during the conversation.
706
+ :param completion_args: White-listed arguments from the completion API
707
+ :param model:
708
+ :param name:
709
+ :param description:
710
+ :param handoffs:
711
+ :param retries: Override the default retry configuration for this method
712
+ :param server_url: Override the default server URL for this method
713
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
714
+ :param http_headers: Additional headers to set or replace on requests.
715
+ """
716
+ base_url = None
717
+ url_variables = None
718
+ if timeout_ms is None:
719
+ timeout_ms = self.sdk_configuration.timeout_ms
720
+
721
+ if server_url is not None:
722
+ base_url = server_url
723
+ else:
724
+ base_url = self._get_url(base_url, url_variables)
725
+
726
+ request = models.AgentsAPIV1AgentsUpdateRequest(
727
+ agent_id=agent_id,
728
+ agent_update_request=models.AgentUpdateRequest(
729
+ instructions=instructions,
730
+ tools=utils.get_pydantic_model(
731
+ tools, Optional[List[models.AgentUpdateRequestTools]]
732
+ ),
733
+ completion_args=utils.get_pydantic_model(
734
+ completion_args, Optional[models.CompletionArgs]
735
+ ),
736
+ model=model,
737
+ name=name,
738
+ description=description,
739
+ handoffs=handoffs,
740
+ ),
741
+ )
742
+
743
+ req = self._build_request(
744
+ method="PATCH",
745
+ path="/v1/agents/{agent_id}",
746
+ base_url=base_url,
747
+ url_variables=url_variables,
748
+ request=request,
749
+ request_body_required=True,
750
+ request_has_path_params=True,
751
+ request_has_query_params=True,
752
+ user_agent_header="user-agent",
753
+ accept_header_value="application/json",
754
+ http_headers=http_headers,
755
+ security=self.sdk_configuration.security,
756
+ get_serialized_body=lambda: utils.serialize_request_body(
757
+ request.agent_update_request,
758
+ False,
759
+ False,
760
+ "json",
761
+ models.AgentUpdateRequest,
762
+ ),
763
+ timeout_ms=timeout_ms,
764
+ )
765
+
766
+ if retries == UNSET:
767
+ if self.sdk_configuration.retry_config is not UNSET:
768
+ retries = self.sdk_configuration.retry_config
769
+
770
+ retry_config = None
771
+ if isinstance(retries, utils.RetryConfig):
772
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
773
+
774
+ http_res = self.do_request(
775
+ hook_ctx=HookContext(
776
+ base_url=base_url or "",
777
+ operation_id="agents_api_v1_agents_update",
778
+ oauth2_scopes=[],
779
+ security_source=get_security_from_env(
780
+ self.sdk_configuration.security, models.Security
781
+ ),
782
+ ),
783
+ request=req,
784
+ error_status_codes=["422", "4XX", "5XX"],
785
+ retry_config=retry_config,
786
+ )
787
+
788
+ response_data: Any = None
789
+ if utils.match_response(http_res, "200", "application/json"):
790
+ return utils.unmarshal_json(http_res.text, models.Agent)
791
+ if utils.match_response(http_res, "422", "application/json"):
792
+ response_data = utils.unmarshal_json(
793
+ http_res.text, models.HTTPValidationErrorData
794
+ )
795
+ raise models.HTTPValidationError(data=response_data)
796
+ if utils.match_response(http_res, "4XX", "*"):
797
+ http_res_text = utils.stream_to_text(http_res)
798
+ raise models.SDKError(
799
+ "API error occurred", http_res.status_code, http_res_text, http_res
800
+ )
801
+ if utils.match_response(http_res, "5XX", "*"):
802
+ http_res_text = utils.stream_to_text(http_res)
803
+ raise models.SDKError(
804
+ "API error occurred", http_res.status_code, http_res_text, http_res
805
+ )
806
+
807
+ content_type = http_res.headers.get("Content-Type")
808
+ http_res_text = utils.stream_to_text(http_res)
809
+ raise models.SDKError(
810
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
811
+ http_res.status_code,
812
+ http_res_text,
813
+ http_res,
814
+ )
815
+
816
+ async def update_async(
817
+ self,
818
+ *,
819
+ agent_id: str,
820
+ instructions: OptionalNullable[str] = UNSET,
821
+ tools: Optional[
822
+ Union[
823
+ List[models.AgentUpdateRequestTools],
824
+ List[models.AgentUpdateRequestToolsTypedDict],
825
+ ]
826
+ ] = None,
827
+ completion_args: Optional[
828
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
829
+ ] = None,
830
+ model: OptionalNullable[str] = UNSET,
831
+ name: OptionalNullable[str] = UNSET,
832
+ description: OptionalNullable[str] = UNSET,
833
+ handoffs: OptionalNullable[List[str]] = UNSET,
834
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
835
+ server_url: Optional[str] = None,
836
+ timeout_ms: Optional[int] = None,
837
+ http_headers: Optional[Mapping[str, str]] = None,
838
+ ) -> models.Agent:
839
+ r"""Update an agent entity.
840
+
841
+ Update an agent attributes and create a new version.
842
+
843
+ :param agent_id:
844
+ :param instructions: Instruction prompt the model will follow during the conversation.
845
+ :param tools: List of tools which are available to the model during the conversation.
846
+ :param completion_args: White-listed arguments from the completion API
847
+ :param model:
848
+ :param name:
849
+ :param description:
850
+ :param handoffs:
851
+ :param retries: Override the default retry configuration for this method
852
+ :param server_url: Override the default server URL for this method
853
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
854
+ :param http_headers: Additional headers to set or replace on requests.
855
+ """
856
+ base_url = None
857
+ url_variables = None
858
+ if timeout_ms is None:
859
+ timeout_ms = self.sdk_configuration.timeout_ms
860
+
861
+ if server_url is not None:
862
+ base_url = server_url
863
+ else:
864
+ base_url = self._get_url(base_url, url_variables)
865
+
866
+ request = models.AgentsAPIV1AgentsUpdateRequest(
867
+ agent_id=agent_id,
868
+ agent_update_request=models.AgentUpdateRequest(
869
+ instructions=instructions,
870
+ tools=utils.get_pydantic_model(
871
+ tools, Optional[List[models.AgentUpdateRequestTools]]
872
+ ),
873
+ completion_args=utils.get_pydantic_model(
874
+ completion_args, Optional[models.CompletionArgs]
875
+ ),
876
+ model=model,
877
+ name=name,
878
+ description=description,
879
+ handoffs=handoffs,
880
+ ),
881
+ )
882
+
883
+ req = self._build_request_async(
884
+ method="PATCH",
885
+ path="/v1/agents/{agent_id}",
886
+ base_url=base_url,
887
+ url_variables=url_variables,
888
+ request=request,
889
+ request_body_required=True,
890
+ request_has_path_params=True,
891
+ request_has_query_params=True,
892
+ user_agent_header="user-agent",
893
+ accept_header_value="application/json",
894
+ http_headers=http_headers,
895
+ security=self.sdk_configuration.security,
896
+ get_serialized_body=lambda: utils.serialize_request_body(
897
+ request.agent_update_request,
898
+ False,
899
+ False,
900
+ "json",
901
+ models.AgentUpdateRequest,
902
+ ),
903
+ timeout_ms=timeout_ms,
904
+ )
905
+
906
+ if retries == UNSET:
907
+ if self.sdk_configuration.retry_config is not UNSET:
908
+ retries = self.sdk_configuration.retry_config
909
+
910
+ retry_config = None
911
+ if isinstance(retries, utils.RetryConfig):
912
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
913
+
914
+ http_res = await self.do_request_async(
915
+ hook_ctx=HookContext(
916
+ base_url=base_url or "",
917
+ operation_id="agents_api_v1_agents_update",
918
+ oauth2_scopes=[],
919
+ security_source=get_security_from_env(
920
+ self.sdk_configuration.security, models.Security
921
+ ),
922
+ ),
923
+ request=req,
924
+ error_status_codes=["422", "4XX", "5XX"],
925
+ retry_config=retry_config,
926
+ )
927
+
928
+ response_data: Any = None
929
+ if utils.match_response(http_res, "200", "application/json"):
930
+ return utils.unmarshal_json(http_res.text, models.Agent)
931
+ if utils.match_response(http_res, "422", "application/json"):
932
+ response_data = utils.unmarshal_json(
933
+ http_res.text, models.HTTPValidationErrorData
934
+ )
935
+ raise models.HTTPValidationError(data=response_data)
936
+ if utils.match_response(http_res, "4XX", "*"):
937
+ http_res_text = await utils.stream_to_text_async(http_res)
938
+ raise models.SDKError(
939
+ "API error occurred", http_res.status_code, http_res_text, http_res
940
+ )
941
+ if utils.match_response(http_res, "5XX", "*"):
942
+ http_res_text = await utils.stream_to_text_async(http_res)
943
+ raise models.SDKError(
944
+ "API error occurred", http_res.status_code, http_res_text, http_res
945
+ )
946
+
947
+ content_type = http_res.headers.get("Content-Type")
948
+ http_res_text = await utils.stream_to_text_async(http_res)
949
+ raise models.SDKError(
950
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
951
+ http_res.status_code,
952
+ http_res_text,
953
+ http_res,
954
+ )
955
+
956
+ def update_version(
957
+ self,
958
+ *,
959
+ agent_id: str,
960
+ version: int,
961
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
962
+ server_url: Optional[str] = None,
963
+ timeout_ms: Optional[int] = None,
964
+ http_headers: Optional[Mapping[str, str]] = None,
965
+ ) -> models.Agent:
966
+ r"""Update an agent version.
967
+
968
+ Switch the version of an agent.
969
+
970
+ :param agent_id:
971
+ :param version:
972
+ :param retries: Override the default retry configuration for this method
973
+ :param server_url: Override the default server URL for this method
974
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
975
+ :param http_headers: Additional headers to set or replace on requests.
976
+ """
977
+ base_url = None
978
+ url_variables = None
979
+ if timeout_ms is None:
980
+ timeout_ms = self.sdk_configuration.timeout_ms
981
+
982
+ if server_url is not None:
983
+ base_url = server_url
984
+ else:
985
+ base_url = self._get_url(base_url, url_variables)
986
+
987
+ request = models.AgentsAPIV1AgentsUpdateVersionRequest(
988
+ agent_id=agent_id,
989
+ version=version,
990
+ )
991
+
992
+ req = self._build_request(
993
+ method="PATCH",
994
+ path="/v1/agents/{agent_id}/version",
995
+ base_url=base_url,
996
+ url_variables=url_variables,
997
+ request=request,
998
+ request_body_required=False,
999
+ request_has_path_params=True,
1000
+ request_has_query_params=True,
1001
+ user_agent_header="user-agent",
1002
+ accept_header_value="application/json",
1003
+ http_headers=http_headers,
1004
+ security=self.sdk_configuration.security,
1005
+ timeout_ms=timeout_ms,
1006
+ )
1007
+
1008
+ if retries == UNSET:
1009
+ if self.sdk_configuration.retry_config is not UNSET:
1010
+ retries = self.sdk_configuration.retry_config
1011
+
1012
+ retry_config = None
1013
+ if isinstance(retries, utils.RetryConfig):
1014
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1015
+
1016
+ http_res = self.do_request(
1017
+ hook_ctx=HookContext(
1018
+ base_url=base_url or "",
1019
+ operation_id="agents_api_v1_agents_update_version",
1020
+ oauth2_scopes=[],
1021
+ security_source=get_security_from_env(
1022
+ self.sdk_configuration.security, models.Security
1023
+ ),
1024
+ ),
1025
+ request=req,
1026
+ error_status_codes=["422", "4XX", "5XX"],
1027
+ retry_config=retry_config,
1028
+ )
1029
+
1030
+ response_data: Any = None
1031
+ if utils.match_response(http_res, "200", "application/json"):
1032
+ return utils.unmarshal_json(http_res.text, models.Agent)
1033
+ if utils.match_response(http_res, "422", "application/json"):
1034
+ response_data = utils.unmarshal_json(
1035
+ http_res.text, models.HTTPValidationErrorData
1036
+ )
1037
+ raise models.HTTPValidationError(data=response_data)
1038
+ if utils.match_response(http_res, "4XX", "*"):
1039
+ http_res_text = utils.stream_to_text(http_res)
1040
+ raise models.SDKError(
1041
+ "API error occurred", http_res.status_code, http_res_text, http_res
1042
+ )
1043
+ if utils.match_response(http_res, "5XX", "*"):
1044
+ http_res_text = utils.stream_to_text(http_res)
1045
+ raise models.SDKError(
1046
+ "API error occurred", http_res.status_code, http_res_text, http_res
1047
+ )
1048
+
1049
+ content_type = http_res.headers.get("Content-Type")
1050
+ http_res_text = utils.stream_to_text(http_res)
1051
+ raise models.SDKError(
1052
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1053
+ http_res.status_code,
1054
+ http_res_text,
1055
+ http_res,
1056
+ )
1057
+
1058
+ async def update_version_async(
1059
+ self,
1060
+ *,
1061
+ agent_id: str,
1062
+ version: int,
1063
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1064
+ server_url: Optional[str] = None,
1065
+ timeout_ms: Optional[int] = None,
1066
+ http_headers: Optional[Mapping[str, str]] = None,
1067
+ ) -> models.Agent:
1068
+ r"""Update an agent version.
1069
+
1070
+ Switch the version of an agent.
1071
+
1072
+ :param agent_id:
1073
+ :param version:
1074
+ :param retries: Override the default retry configuration for this method
1075
+ :param server_url: Override the default server URL for this method
1076
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1077
+ :param http_headers: Additional headers to set or replace on requests.
1078
+ """
1079
+ base_url = None
1080
+ url_variables = None
1081
+ if timeout_ms is None:
1082
+ timeout_ms = self.sdk_configuration.timeout_ms
1083
+
1084
+ if server_url is not None:
1085
+ base_url = server_url
1086
+ else:
1087
+ base_url = self._get_url(base_url, url_variables)
1088
+
1089
+ request = models.AgentsAPIV1AgentsUpdateVersionRequest(
1090
+ agent_id=agent_id,
1091
+ version=version,
1092
+ )
1093
+
1094
+ req = self._build_request_async(
1095
+ method="PATCH",
1096
+ path="/v1/agents/{agent_id}/version",
1097
+ base_url=base_url,
1098
+ url_variables=url_variables,
1099
+ request=request,
1100
+ request_body_required=False,
1101
+ request_has_path_params=True,
1102
+ request_has_query_params=True,
1103
+ user_agent_header="user-agent",
1104
+ accept_header_value="application/json",
1105
+ http_headers=http_headers,
1106
+ security=self.sdk_configuration.security,
1107
+ timeout_ms=timeout_ms,
1108
+ )
1109
+
1110
+ if retries == UNSET:
1111
+ if self.sdk_configuration.retry_config is not UNSET:
1112
+ retries = self.sdk_configuration.retry_config
1113
+
1114
+ retry_config = None
1115
+ if isinstance(retries, utils.RetryConfig):
1116
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1117
+
1118
+ http_res = await self.do_request_async(
1119
+ hook_ctx=HookContext(
1120
+ base_url=base_url or "",
1121
+ operation_id="agents_api_v1_agents_update_version",
1122
+ oauth2_scopes=[],
1123
+ security_source=get_security_from_env(
1124
+ self.sdk_configuration.security, models.Security
1125
+ ),
1126
+ ),
1127
+ request=req,
1128
+ error_status_codes=["422", "4XX", "5XX"],
1129
+ retry_config=retry_config,
1130
+ )
1131
+
1132
+ response_data: Any = None
1133
+ if utils.match_response(http_res, "200", "application/json"):
1134
+ return utils.unmarshal_json(http_res.text, models.Agent)
1135
+ if utils.match_response(http_res, "422", "application/json"):
1136
+ response_data = utils.unmarshal_json(
1137
+ http_res.text, models.HTTPValidationErrorData
1138
+ )
1139
+ raise models.HTTPValidationError(data=response_data)
1140
+ if utils.match_response(http_res, "4XX", "*"):
1141
+ http_res_text = await utils.stream_to_text_async(http_res)
1142
+ raise models.SDKError(
1143
+ "API error occurred", http_res.status_code, http_res_text, http_res
1144
+ )
1145
+ if utils.match_response(http_res, "5XX", "*"):
1146
+ http_res_text = await utils.stream_to_text_async(http_res)
1147
+ raise models.SDKError(
1148
+ "API error occurred", http_res.status_code, http_res_text, http_res
1149
+ )
1150
+
1151
+ content_type = http_res.headers.get("Content-Type")
1152
+ http_res_text = await utils.stream_to_text_async(http_res)
1153
+ raise models.SDKError(
1154
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1155
+ http_res.status_code,
1156
+ http_res_text,
1157
+ http_res,
1158
+ )