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,2657 @@
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 eventstreaming, get_security_from_env
8
+ from typing import Any, List, Mapping, Optional, Union
9
+
10
+ # region imports
11
+ import typing
12
+ from typing import AsyncGenerator
13
+ import logging
14
+ from collections import defaultdict
15
+
16
+ from mistralai.models import (
17
+ ResponseStartedEvent,
18
+ ConversationEventsData,
19
+ InputEntries,
20
+ )
21
+ from mistralai.extra.run.result import (
22
+ RunResult,
23
+ RunResultEvents,
24
+ FunctionResultEvent,
25
+ reconstitue_entries,
26
+ )
27
+ from mistralai.extra.run.utils import run_requirements
28
+
29
+ logger = logging.getLogger(__name__)
30
+
31
+ if typing.TYPE_CHECKING:
32
+ from mistralai.extra.run.context import RunContext
33
+
34
+ # endregion imports
35
+
36
+
37
+
38
+ class Conversations(BaseSDK):
39
+ # region sdk-class-body
40
+ # Custom run code allowing client side execution of code
41
+
42
+ @run_requirements
43
+ async def run_async(
44
+ self,
45
+ run_ctx: "RunContext",
46
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
47
+ instructions: OptionalNullable[str] = UNSET,
48
+ tools: OptionalNullable[
49
+ Union[List[models.Tools], List[models.ToolsTypedDict]]
50
+ ] = UNSET,
51
+ completion_args: OptionalNullable[
52
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
53
+ ] = UNSET,
54
+ name: OptionalNullable[str] = UNSET,
55
+ description: OptionalNullable[str] = UNSET,
56
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
57
+ server_url: Optional[str] = None,
58
+ timeout_ms: Optional[int] = None,
59
+ http_headers: Optional[Mapping[str, str]] = None,
60
+ ) -> RunResult:
61
+ """Run a conversation with the given inputs and context.
62
+
63
+ The execution of a run will only stop when no required local execution can be done."""
64
+ from mistralai.beta import Beta
65
+ from mistralai.extra.run.context import _validate_run
66
+ from mistralai.extra.run.tools import get_function_calls
67
+
68
+ req, run_result, input_entries = await _validate_run(
69
+ beta_client=Beta(self.sdk_configuration),
70
+ run_ctx=run_ctx,
71
+ inputs=inputs,
72
+ instructions=instructions,
73
+ tools=tools,
74
+ completion_args=completion_args,
75
+ )
76
+
77
+ while True:
78
+ if run_ctx.conversation_id is None:
79
+ res = await self.start_async(
80
+ inputs=input_entries,
81
+ http_headers=http_headers,
82
+ name=name,
83
+ description=description,
84
+ retries=retries,
85
+ server_url=server_url,
86
+ timeout_ms=timeout_ms,
87
+ **req,
88
+ )
89
+ run_result.conversation_id = res.conversation_id
90
+ run_ctx.conversation_id = res.conversation_id
91
+ logger.info(
92
+ f"Started Run with conversation with id {res.conversation_id}"
93
+ )
94
+ else:
95
+ res = await self.append_async(
96
+ conversation_id=run_ctx.conversation_id,
97
+ inputs=input_entries,
98
+ retries=retries,
99
+ server_url=server_url,
100
+ timeout_ms=timeout_ms,
101
+ )
102
+ run_ctx.request_count += 1
103
+ run_result.output_entries.extend(res.outputs)
104
+ fcalls = get_function_calls(res.outputs)
105
+ if not fcalls:
106
+ logger.debug("No more function calls to execute")
107
+ break
108
+ else:
109
+ fresults = await run_ctx.execute_function_calls(fcalls)
110
+ run_result.output_entries.extend(fresults)
111
+ input_entries = typing.cast(list[InputEntries], fresults)
112
+ return run_result
113
+
114
+ @run_requirements
115
+ async def run_stream_async(
116
+ self,
117
+ run_ctx: "RunContext",
118
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
119
+ instructions: OptionalNullable[str] = UNSET,
120
+ tools: OptionalNullable[
121
+ Union[List[models.Tools], List[models.ToolsTypedDict]]
122
+ ] = UNSET,
123
+ completion_args: OptionalNullable[
124
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
125
+ ] = UNSET,
126
+ name: OptionalNullable[str] = UNSET,
127
+ description: OptionalNullable[str] = UNSET,
128
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
129
+ server_url: Optional[str] = None,
130
+ timeout_ms: Optional[int] = None,
131
+ http_headers: Optional[Mapping[str, str]] = None,
132
+ ) -> AsyncGenerator[Union[RunResultEvents, RunResult], None]:
133
+ """Similar to `run_async` but returns a generator which streams events.
134
+
135
+ The last streamed object is the RunResult object which summarises what happened in the run."""
136
+ from mistralai.beta import Beta
137
+ from mistralai.extra.run.context import _validate_run
138
+ from mistralai.extra.run.tools import get_function_calls
139
+
140
+ req, run_result, input_entries = await _validate_run(
141
+ beta_client=Beta(self.sdk_configuration),
142
+ run_ctx=run_ctx,
143
+ inputs=inputs,
144
+ instructions=instructions,
145
+ tools=tools,
146
+ completion_args=completion_args,
147
+ )
148
+
149
+ async def run_generator() -> AsyncGenerator[Union[RunResultEvents, RunResult], None]:
150
+ current_entries = input_entries
151
+ while True:
152
+ received_event_tracker: defaultdict[
153
+ int, list[ConversationEventsData]
154
+ ] = defaultdict(list)
155
+ if run_ctx.conversation_id is None:
156
+ res = await self.start_stream_async(
157
+ inputs=current_entries,
158
+ http_headers=http_headers,
159
+ name=name,
160
+ description=description,
161
+ retries=retries,
162
+ server_url=server_url,
163
+ timeout_ms=timeout_ms,
164
+ **req,
165
+ )
166
+ else:
167
+ res = await self.append_stream_async(
168
+ conversation_id=run_ctx.conversation_id,
169
+ inputs=current_entries,
170
+ retries=retries,
171
+ server_url=server_url,
172
+ timeout_ms=timeout_ms,
173
+ )
174
+ async for event in res:
175
+ if (
176
+ isinstance(event.data, ResponseStartedEvent)
177
+ and run_ctx.conversation_id is None
178
+ ):
179
+ run_result.conversation_id = event.data.conversation_id
180
+ run_ctx.conversation_id = event.data.conversation_id
181
+ logger.info(
182
+ f"Started Run with conversation with id {run_ctx.conversation_id}"
183
+ )
184
+ if (
185
+ output_index := getattr(event.data, "output_index", None)
186
+ ) is not None:
187
+ received_event_tracker[output_index].append(event.data)
188
+ yield typing.cast(RunResultEvents, event)
189
+ run_ctx.request_count += 1
190
+ outputs = reconstitue_entries(received_event_tracker)
191
+ run_result.output_entries.extend(outputs)
192
+ fcalls = get_function_calls(outputs)
193
+ if not fcalls:
194
+ logger.debug("No more function calls to execute")
195
+ break
196
+ else:
197
+ fresults = await run_ctx.execute_function_calls(fcalls)
198
+ run_result.output_entries.extend(fresults)
199
+ for fresult in fresults:
200
+ yield RunResultEvents(
201
+ event="function.result",
202
+ data=FunctionResultEvent(
203
+ type="function.result",
204
+ result=fresult.result,
205
+ tool_call_id=fresult.tool_call_id,
206
+ ),
207
+ )
208
+ current_entries = typing.cast(list[InputEntries], fresults)
209
+ yield run_result
210
+
211
+ return run_generator()
212
+
213
+ # endregion sdk-class-body
214
+
215
+ def start(
216
+ self,
217
+ *,
218
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
219
+ stream: Optional[bool] = False,
220
+ store: OptionalNullable[bool] = UNSET,
221
+ handoff_execution: OptionalNullable[models.HandoffExecution] = UNSET,
222
+ instructions: OptionalNullable[str] = UNSET,
223
+ tools: OptionalNullable[
224
+ Union[List[models.Tools], List[models.ToolsTypedDict]]
225
+ ] = UNSET,
226
+ completion_args: OptionalNullable[
227
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
228
+ ] = UNSET,
229
+ name: OptionalNullable[str] = UNSET,
230
+ description: OptionalNullable[str] = UNSET,
231
+ agent_id: OptionalNullable[str] = UNSET,
232
+ model: OptionalNullable[str] = UNSET,
233
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
234
+ server_url: Optional[str] = None,
235
+ timeout_ms: Optional[int] = None,
236
+ http_headers: Optional[Mapping[str, str]] = None,
237
+ ) -> models.ConversationResponse:
238
+ r"""Create a conversation and append entries to it.
239
+
240
+ Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.
241
+
242
+ :param inputs:
243
+ :param stream:
244
+ :param store:
245
+ :param handoff_execution:
246
+ :param instructions:
247
+ :param tools:
248
+ :param completion_args:
249
+ :param name:
250
+ :param description:
251
+ :param agent_id:
252
+ :param model:
253
+ :param retries: Override the default retry configuration for this method
254
+ :param server_url: Override the default server URL for this method
255
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
256
+ :param http_headers: Additional headers to set or replace on requests.
257
+ """
258
+ base_url = None
259
+ url_variables = None
260
+ if timeout_ms is None:
261
+ timeout_ms = self.sdk_configuration.timeout_ms
262
+
263
+ if server_url is not None:
264
+ base_url = server_url
265
+ else:
266
+ base_url = self._get_url(base_url, url_variables)
267
+
268
+ request = models.ConversationRequest(
269
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
270
+ stream=stream,
271
+ store=store,
272
+ handoff_execution=handoff_execution,
273
+ instructions=instructions,
274
+ tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tools]]),
275
+ completion_args=utils.get_pydantic_model(
276
+ completion_args, OptionalNullable[models.CompletionArgs]
277
+ ),
278
+ name=name,
279
+ description=description,
280
+ agent_id=agent_id,
281
+ model=model,
282
+ )
283
+
284
+ req = self._build_request(
285
+ method="POST",
286
+ path="/v1/conversations",
287
+ base_url=base_url,
288
+ url_variables=url_variables,
289
+ request=request,
290
+ request_body_required=True,
291
+ request_has_path_params=False,
292
+ request_has_query_params=True,
293
+ user_agent_header="user-agent",
294
+ accept_header_value="application/json",
295
+ http_headers=http_headers,
296
+ security=self.sdk_configuration.security,
297
+ get_serialized_body=lambda: utils.serialize_request_body(
298
+ request, False, False, "json", models.ConversationRequest
299
+ ),
300
+ timeout_ms=timeout_ms,
301
+ )
302
+
303
+ if retries == UNSET:
304
+ if self.sdk_configuration.retry_config is not UNSET:
305
+ retries = self.sdk_configuration.retry_config
306
+
307
+ retry_config = None
308
+ if isinstance(retries, utils.RetryConfig):
309
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
310
+
311
+ http_res = self.do_request(
312
+ hook_ctx=HookContext(
313
+ base_url=base_url or "",
314
+ operation_id="agents_api_v1_conversations_start",
315
+ oauth2_scopes=[],
316
+ security_source=get_security_from_env(
317
+ self.sdk_configuration.security, models.Security
318
+ ),
319
+ ),
320
+ request=req,
321
+ error_status_codes=["422", "4XX", "5XX"],
322
+ retry_config=retry_config,
323
+ )
324
+
325
+ response_data: Any = None
326
+ if utils.match_response(http_res, "200", "application/json"):
327
+ return utils.unmarshal_json(http_res.text, models.ConversationResponse)
328
+ if utils.match_response(http_res, "422", "application/json"):
329
+ response_data = utils.unmarshal_json(
330
+ http_res.text, models.HTTPValidationErrorData
331
+ )
332
+ raise models.HTTPValidationError(data=response_data)
333
+ if utils.match_response(http_res, "4XX", "*"):
334
+ http_res_text = utils.stream_to_text(http_res)
335
+ raise models.SDKError(
336
+ "API error occurred", http_res.status_code, http_res_text, http_res
337
+ )
338
+ if utils.match_response(http_res, "5XX", "*"):
339
+ http_res_text = utils.stream_to_text(http_res)
340
+ raise models.SDKError(
341
+ "API error occurred", http_res.status_code, http_res_text, http_res
342
+ )
343
+
344
+ content_type = http_res.headers.get("Content-Type")
345
+ http_res_text = utils.stream_to_text(http_res)
346
+ raise models.SDKError(
347
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
348
+ http_res.status_code,
349
+ http_res_text,
350
+ http_res,
351
+ )
352
+
353
+ async def start_async(
354
+ self,
355
+ *,
356
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
357
+ stream: Optional[bool] = False,
358
+ store: OptionalNullable[bool] = UNSET,
359
+ handoff_execution: OptionalNullable[models.HandoffExecution] = UNSET,
360
+ instructions: OptionalNullable[str] = UNSET,
361
+ tools: OptionalNullable[
362
+ Union[List[models.Tools], List[models.ToolsTypedDict]]
363
+ ] = UNSET,
364
+ completion_args: OptionalNullable[
365
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
366
+ ] = UNSET,
367
+ name: OptionalNullable[str] = UNSET,
368
+ description: OptionalNullable[str] = UNSET,
369
+ agent_id: OptionalNullable[str] = UNSET,
370
+ model: OptionalNullable[str] = UNSET,
371
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
372
+ server_url: Optional[str] = None,
373
+ timeout_ms: Optional[int] = None,
374
+ http_headers: Optional[Mapping[str, str]] = None,
375
+ ) -> models.ConversationResponse:
376
+ r"""Create a conversation and append entries to it.
377
+
378
+ Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.
379
+
380
+ :param inputs:
381
+ :param stream:
382
+ :param store:
383
+ :param handoff_execution:
384
+ :param instructions:
385
+ :param tools:
386
+ :param completion_args:
387
+ :param name:
388
+ :param description:
389
+ :param agent_id:
390
+ :param model:
391
+ :param retries: Override the default retry configuration for this method
392
+ :param server_url: Override the default server URL for this method
393
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
394
+ :param http_headers: Additional headers to set or replace on requests.
395
+ """
396
+ base_url = None
397
+ url_variables = None
398
+ if timeout_ms is None:
399
+ timeout_ms = self.sdk_configuration.timeout_ms
400
+
401
+ if server_url is not None:
402
+ base_url = server_url
403
+ else:
404
+ base_url = self._get_url(base_url, url_variables)
405
+
406
+ request = models.ConversationRequest(
407
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
408
+ stream=stream,
409
+ store=store,
410
+ handoff_execution=handoff_execution,
411
+ instructions=instructions,
412
+ tools=utils.get_pydantic_model(tools, OptionalNullable[List[models.Tools]]),
413
+ completion_args=utils.get_pydantic_model(
414
+ completion_args, OptionalNullable[models.CompletionArgs]
415
+ ),
416
+ name=name,
417
+ description=description,
418
+ agent_id=agent_id,
419
+ model=model,
420
+ )
421
+
422
+ req = self._build_request_async(
423
+ method="POST",
424
+ path="/v1/conversations",
425
+ base_url=base_url,
426
+ url_variables=url_variables,
427
+ request=request,
428
+ request_body_required=True,
429
+ request_has_path_params=False,
430
+ request_has_query_params=True,
431
+ user_agent_header="user-agent",
432
+ accept_header_value="application/json",
433
+ http_headers=http_headers,
434
+ security=self.sdk_configuration.security,
435
+ get_serialized_body=lambda: utils.serialize_request_body(
436
+ request, False, False, "json", models.ConversationRequest
437
+ ),
438
+ timeout_ms=timeout_ms,
439
+ )
440
+
441
+ if retries == UNSET:
442
+ if self.sdk_configuration.retry_config is not UNSET:
443
+ retries = self.sdk_configuration.retry_config
444
+
445
+ retry_config = None
446
+ if isinstance(retries, utils.RetryConfig):
447
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
448
+
449
+ http_res = await self.do_request_async(
450
+ hook_ctx=HookContext(
451
+ base_url=base_url or "",
452
+ operation_id="agents_api_v1_conversations_start",
453
+ oauth2_scopes=[],
454
+ security_source=get_security_from_env(
455
+ self.sdk_configuration.security, models.Security
456
+ ),
457
+ ),
458
+ request=req,
459
+ error_status_codes=["422", "4XX", "5XX"],
460
+ retry_config=retry_config,
461
+ )
462
+
463
+ response_data: Any = None
464
+ if utils.match_response(http_res, "200", "application/json"):
465
+ return utils.unmarshal_json(http_res.text, models.ConversationResponse)
466
+ if utils.match_response(http_res, "422", "application/json"):
467
+ response_data = utils.unmarshal_json(
468
+ http_res.text, models.HTTPValidationErrorData
469
+ )
470
+ raise models.HTTPValidationError(data=response_data)
471
+ if utils.match_response(http_res, "4XX", "*"):
472
+ http_res_text = await utils.stream_to_text_async(http_res)
473
+ raise models.SDKError(
474
+ "API error occurred", http_res.status_code, http_res_text, http_res
475
+ )
476
+ if utils.match_response(http_res, "5XX", "*"):
477
+ http_res_text = await utils.stream_to_text_async(http_res)
478
+ raise models.SDKError(
479
+ "API error occurred", http_res.status_code, http_res_text, http_res
480
+ )
481
+
482
+ content_type = http_res.headers.get("Content-Type")
483
+ http_res_text = await utils.stream_to_text_async(http_res)
484
+ raise models.SDKError(
485
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
486
+ http_res.status_code,
487
+ http_res_text,
488
+ http_res,
489
+ )
490
+
491
+ def list(
492
+ self,
493
+ *,
494
+ page: Optional[int] = 0,
495
+ page_size: Optional[int] = 100,
496
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
497
+ server_url: Optional[str] = None,
498
+ timeout_ms: Optional[int] = None,
499
+ http_headers: Optional[Mapping[str, str]] = None,
500
+ ) -> List[models.ResponseBody]:
501
+ r"""List all created conversations.
502
+
503
+ Retrieve a list of conversation entities sorted by creation time.
504
+
505
+ :param page:
506
+ :param page_size:
507
+ :param retries: Override the default retry configuration for this method
508
+ :param server_url: Override the default server URL for this method
509
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
510
+ :param http_headers: Additional headers to set or replace on requests.
511
+ """
512
+ base_url = None
513
+ url_variables = None
514
+ if timeout_ms is None:
515
+ timeout_ms = self.sdk_configuration.timeout_ms
516
+
517
+ if server_url is not None:
518
+ base_url = server_url
519
+ else:
520
+ base_url = self._get_url(base_url, url_variables)
521
+
522
+ request = models.AgentsAPIV1ConversationsListRequest(
523
+ page=page,
524
+ page_size=page_size,
525
+ )
526
+
527
+ req = self._build_request(
528
+ method="GET",
529
+ path="/v1/conversations",
530
+ base_url=base_url,
531
+ url_variables=url_variables,
532
+ request=request,
533
+ request_body_required=False,
534
+ request_has_path_params=False,
535
+ request_has_query_params=True,
536
+ user_agent_header="user-agent",
537
+ accept_header_value="application/json",
538
+ http_headers=http_headers,
539
+ security=self.sdk_configuration.security,
540
+ timeout_ms=timeout_ms,
541
+ )
542
+
543
+ if retries == UNSET:
544
+ if self.sdk_configuration.retry_config is not UNSET:
545
+ retries = self.sdk_configuration.retry_config
546
+
547
+ retry_config = None
548
+ if isinstance(retries, utils.RetryConfig):
549
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
550
+
551
+ http_res = self.do_request(
552
+ hook_ctx=HookContext(
553
+ base_url=base_url or "",
554
+ operation_id="agents_api_v1_conversations_list",
555
+ oauth2_scopes=[],
556
+ security_source=get_security_from_env(
557
+ self.sdk_configuration.security, models.Security
558
+ ),
559
+ ),
560
+ request=req,
561
+ error_status_codes=["422", "4XX", "5XX"],
562
+ retry_config=retry_config,
563
+ )
564
+
565
+ response_data: Any = None
566
+ if utils.match_response(http_res, "200", "application/json"):
567
+ return utils.unmarshal_json(http_res.text, List[models.ResponseBody])
568
+ if utils.match_response(http_res, "422", "application/json"):
569
+ response_data = utils.unmarshal_json(
570
+ http_res.text, models.HTTPValidationErrorData
571
+ )
572
+ raise models.HTTPValidationError(data=response_data)
573
+ if utils.match_response(http_res, "4XX", "*"):
574
+ http_res_text = utils.stream_to_text(http_res)
575
+ raise models.SDKError(
576
+ "API error occurred", http_res.status_code, http_res_text, http_res
577
+ )
578
+ if utils.match_response(http_res, "5XX", "*"):
579
+ http_res_text = utils.stream_to_text(http_res)
580
+ raise models.SDKError(
581
+ "API error occurred", http_res.status_code, http_res_text, http_res
582
+ )
583
+
584
+ content_type = http_res.headers.get("Content-Type")
585
+ http_res_text = utils.stream_to_text(http_res)
586
+ raise models.SDKError(
587
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
588
+ http_res.status_code,
589
+ http_res_text,
590
+ http_res,
591
+ )
592
+
593
+ async def list_async(
594
+ self,
595
+ *,
596
+ page: Optional[int] = 0,
597
+ page_size: Optional[int] = 100,
598
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
599
+ server_url: Optional[str] = None,
600
+ timeout_ms: Optional[int] = None,
601
+ http_headers: Optional[Mapping[str, str]] = None,
602
+ ) -> List[models.ResponseBody]:
603
+ r"""List all created conversations.
604
+
605
+ Retrieve a list of conversation entities sorted by creation time.
606
+
607
+ :param page:
608
+ :param page_size:
609
+ :param retries: Override the default retry configuration for this method
610
+ :param server_url: Override the default server URL for this method
611
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
612
+ :param http_headers: Additional headers to set or replace on requests.
613
+ """
614
+ base_url = None
615
+ url_variables = None
616
+ if timeout_ms is None:
617
+ timeout_ms = self.sdk_configuration.timeout_ms
618
+
619
+ if server_url is not None:
620
+ base_url = server_url
621
+ else:
622
+ base_url = self._get_url(base_url, url_variables)
623
+
624
+ request = models.AgentsAPIV1ConversationsListRequest(
625
+ page=page,
626
+ page_size=page_size,
627
+ )
628
+
629
+ req = self._build_request_async(
630
+ method="GET",
631
+ path="/v1/conversations",
632
+ base_url=base_url,
633
+ url_variables=url_variables,
634
+ request=request,
635
+ request_body_required=False,
636
+ request_has_path_params=False,
637
+ request_has_query_params=True,
638
+ user_agent_header="user-agent",
639
+ accept_header_value="application/json",
640
+ http_headers=http_headers,
641
+ security=self.sdk_configuration.security,
642
+ timeout_ms=timeout_ms,
643
+ )
644
+
645
+ if retries == UNSET:
646
+ if self.sdk_configuration.retry_config is not UNSET:
647
+ retries = self.sdk_configuration.retry_config
648
+
649
+ retry_config = None
650
+ if isinstance(retries, utils.RetryConfig):
651
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
652
+
653
+ http_res = await self.do_request_async(
654
+ hook_ctx=HookContext(
655
+ base_url=base_url or "",
656
+ operation_id="agents_api_v1_conversations_list",
657
+ oauth2_scopes=[],
658
+ security_source=get_security_from_env(
659
+ self.sdk_configuration.security, models.Security
660
+ ),
661
+ ),
662
+ request=req,
663
+ error_status_codes=["422", "4XX", "5XX"],
664
+ retry_config=retry_config,
665
+ )
666
+
667
+ response_data: Any = None
668
+ if utils.match_response(http_res, "200", "application/json"):
669
+ return utils.unmarshal_json(http_res.text, List[models.ResponseBody])
670
+ if utils.match_response(http_res, "422", "application/json"):
671
+ response_data = utils.unmarshal_json(
672
+ http_res.text, models.HTTPValidationErrorData
673
+ )
674
+ raise models.HTTPValidationError(data=response_data)
675
+ if utils.match_response(http_res, "4XX", "*"):
676
+ http_res_text = await utils.stream_to_text_async(http_res)
677
+ raise models.SDKError(
678
+ "API error occurred", http_res.status_code, http_res_text, http_res
679
+ )
680
+ if utils.match_response(http_res, "5XX", "*"):
681
+ http_res_text = await utils.stream_to_text_async(http_res)
682
+ raise models.SDKError(
683
+ "API error occurred", http_res.status_code, http_res_text, http_res
684
+ )
685
+
686
+ content_type = http_res.headers.get("Content-Type")
687
+ http_res_text = await utils.stream_to_text_async(http_res)
688
+ raise models.SDKError(
689
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
690
+ http_res.status_code,
691
+ http_res_text,
692
+ http_res,
693
+ )
694
+
695
+ def get(
696
+ self,
697
+ *,
698
+ conversation_id: str,
699
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
700
+ server_url: Optional[str] = None,
701
+ timeout_ms: Optional[int] = None,
702
+ http_headers: Optional[Mapping[str, str]] = None,
703
+ ) -> models.AgentsAPIV1ConversationsGetResponseV1ConversationsGet:
704
+ r"""Retrieve a conversation information.
705
+
706
+ Given a conversation_id retrieve a conversation entity with its attributes.
707
+
708
+ :param conversation_id:
709
+ :param retries: Override the default retry configuration for this method
710
+ :param server_url: Override the default server URL for this method
711
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
712
+ :param http_headers: Additional headers to set or replace on requests.
713
+ """
714
+ base_url = None
715
+ url_variables = None
716
+ if timeout_ms is None:
717
+ timeout_ms = self.sdk_configuration.timeout_ms
718
+
719
+ if server_url is not None:
720
+ base_url = server_url
721
+ else:
722
+ base_url = self._get_url(base_url, url_variables)
723
+
724
+ request = models.AgentsAPIV1ConversationsGetRequest(
725
+ conversation_id=conversation_id,
726
+ )
727
+
728
+ req = self._build_request(
729
+ method="GET",
730
+ path="/v1/conversations/{conversation_id}",
731
+ base_url=base_url,
732
+ url_variables=url_variables,
733
+ request=request,
734
+ request_body_required=False,
735
+ request_has_path_params=True,
736
+ request_has_query_params=True,
737
+ user_agent_header="user-agent",
738
+ accept_header_value="application/json",
739
+ http_headers=http_headers,
740
+ security=self.sdk_configuration.security,
741
+ timeout_ms=timeout_ms,
742
+ )
743
+
744
+ if retries == UNSET:
745
+ if self.sdk_configuration.retry_config is not UNSET:
746
+ retries = self.sdk_configuration.retry_config
747
+
748
+ retry_config = None
749
+ if isinstance(retries, utils.RetryConfig):
750
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
751
+
752
+ http_res = self.do_request(
753
+ hook_ctx=HookContext(
754
+ base_url=base_url or "",
755
+ operation_id="agents_api_v1_conversations_get",
756
+ oauth2_scopes=[],
757
+ security_source=get_security_from_env(
758
+ self.sdk_configuration.security, models.Security
759
+ ),
760
+ ),
761
+ request=req,
762
+ error_status_codes=["422", "4XX", "5XX"],
763
+ retry_config=retry_config,
764
+ )
765
+
766
+ response_data: Any = None
767
+ if utils.match_response(http_res, "200", "application/json"):
768
+ return utils.unmarshal_json(
769
+ http_res.text,
770
+ models.AgentsAPIV1ConversationsGetResponseV1ConversationsGet,
771
+ )
772
+ if utils.match_response(http_res, "422", "application/json"):
773
+ response_data = utils.unmarshal_json(
774
+ http_res.text, models.HTTPValidationErrorData
775
+ )
776
+ raise models.HTTPValidationError(data=response_data)
777
+ if utils.match_response(http_res, "4XX", "*"):
778
+ http_res_text = utils.stream_to_text(http_res)
779
+ raise models.SDKError(
780
+ "API error occurred", http_res.status_code, http_res_text, http_res
781
+ )
782
+ if utils.match_response(http_res, "5XX", "*"):
783
+ http_res_text = utils.stream_to_text(http_res)
784
+ raise models.SDKError(
785
+ "API error occurred", http_res.status_code, http_res_text, http_res
786
+ )
787
+
788
+ content_type = http_res.headers.get("Content-Type")
789
+ http_res_text = utils.stream_to_text(http_res)
790
+ raise models.SDKError(
791
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
792
+ http_res.status_code,
793
+ http_res_text,
794
+ http_res,
795
+ )
796
+
797
+ async def get_async(
798
+ self,
799
+ *,
800
+ conversation_id: str,
801
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
802
+ server_url: Optional[str] = None,
803
+ timeout_ms: Optional[int] = None,
804
+ http_headers: Optional[Mapping[str, str]] = None,
805
+ ) -> models.AgentsAPIV1ConversationsGetResponseV1ConversationsGet:
806
+ r"""Retrieve a conversation information.
807
+
808
+ Given a conversation_id retrieve a conversation entity with its attributes.
809
+
810
+ :param conversation_id:
811
+ :param retries: Override the default retry configuration for this method
812
+ :param server_url: Override the default server URL for this method
813
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
814
+ :param http_headers: Additional headers to set or replace on requests.
815
+ """
816
+ base_url = None
817
+ url_variables = None
818
+ if timeout_ms is None:
819
+ timeout_ms = self.sdk_configuration.timeout_ms
820
+
821
+ if server_url is not None:
822
+ base_url = server_url
823
+ else:
824
+ base_url = self._get_url(base_url, url_variables)
825
+
826
+ request = models.AgentsAPIV1ConversationsGetRequest(
827
+ conversation_id=conversation_id,
828
+ )
829
+
830
+ req = self._build_request_async(
831
+ method="GET",
832
+ path="/v1/conversations/{conversation_id}",
833
+ base_url=base_url,
834
+ url_variables=url_variables,
835
+ request=request,
836
+ request_body_required=False,
837
+ request_has_path_params=True,
838
+ request_has_query_params=True,
839
+ user_agent_header="user-agent",
840
+ accept_header_value="application/json",
841
+ http_headers=http_headers,
842
+ security=self.sdk_configuration.security,
843
+ timeout_ms=timeout_ms,
844
+ )
845
+
846
+ if retries == UNSET:
847
+ if self.sdk_configuration.retry_config is not UNSET:
848
+ retries = self.sdk_configuration.retry_config
849
+
850
+ retry_config = None
851
+ if isinstance(retries, utils.RetryConfig):
852
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
853
+
854
+ http_res = await self.do_request_async(
855
+ hook_ctx=HookContext(
856
+ base_url=base_url or "",
857
+ operation_id="agents_api_v1_conversations_get",
858
+ oauth2_scopes=[],
859
+ security_source=get_security_from_env(
860
+ self.sdk_configuration.security, models.Security
861
+ ),
862
+ ),
863
+ request=req,
864
+ error_status_codes=["422", "4XX", "5XX"],
865
+ retry_config=retry_config,
866
+ )
867
+
868
+ response_data: Any = None
869
+ if utils.match_response(http_res, "200", "application/json"):
870
+ return utils.unmarshal_json(
871
+ http_res.text,
872
+ models.AgentsAPIV1ConversationsGetResponseV1ConversationsGet,
873
+ )
874
+ if utils.match_response(http_res, "422", "application/json"):
875
+ response_data = utils.unmarshal_json(
876
+ http_res.text, models.HTTPValidationErrorData
877
+ )
878
+ raise models.HTTPValidationError(data=response_data)
879
+ if utils.match_response(http_res, "4XX", "*"):
880
+ http_res_text = await utils.stream_to_text_async(http_res)
881
+ raise models.SDKError(
882
+ "API error occurred", http_res.status_code, http_res_text, http_res
883
+ )
884
+ if utils.match_response(http_res, "5XX", "*"):
885
+ http_res_text = await utils.stream_to_text_async(http_res)
886
+ raise models.SDKError(
887
+ "API error occurred", http_res.status_code, http_res_text, http_res
888
+ )
889
+
890
+ content_type = http_res.headers.get("Content-Type")
891
+ http_res_text = await utils.stream_to_text_async(http_res)
892
+ raise models.SDKError(
893
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
894
+ http_res.status_code,
895
+ http_res_text,
896
+ http_res,
897
+ )
898
+
899
+ def append(
900
+ self,
901
+ *,
902
+ conversation_id: str,
903
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
904
+ stream: Optional[bool] = False,
905
+ store: Optional[bool] = True,
906
+ handoff_execution: Optional[
907
+ models.ConversationAppendRequestHandoffExecution
908
+ ] = "server",
909
+ completion_args: Optional[
910
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
911
+ ] = None,
912
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
913
+ server_url: Optional[str] = None,
914
+ timeout_ms: Optional[int] = None,
915
+ http_headers: Optional[Mapping[str, str]] = None,
916
+ ) -> models.ConversationResponse:
917
+ r"""Append new entries to an existing conversation.
918
+
919
+ Run completion on the history of the conversation and the user entries. Return the new created entries.
920
+
921
+ :param conversation_id: ID of the conversation to which we append entries.
922
+ :param inputs:
923
+ :param stream:
924
+ :param store: Whether to store the results into our servers or not.
925
+ :param handoff_execution:
926
+ :param completion_args: White-listed arguments from the completion API
927
+ :param retries: Override the default retry configuration for this method
928
+ :param server_url: Override the default server URL for this method
929
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
930
+ :param http_headers: Additional headers to set or replace on requests.
931
+ """
932
+ base_url = None
933
+ url_variables = None
934
+ if timeout_ms is None:
935
+ timeout_ms = self.sdk_configuration.timeout_ms
936
+
937
+ if server_url is not None:
938
+ base_url = server_url
939
+ else:
940
+ base_url = self._get_url(base_url, url_variables)
941
+
942
+ request = models.AgentsAPIV1ConversationsAppendRequest(
943
+ conversation_id=conversation_id,
944
+ conversation_append_request=models.ConversationAppendRequest(
945
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
946
+ stream=stream,
947
+ store=store,
948
+ handoff_execution=handoff_execution,
949
+ completion_args=utils.get_pydantic_model(
950
+ completion_args, Optional[models.CompletionArgs]
951
+ ),
952
+ ),
953
+ )
954
+
955
+ req = self._build_request(
956
+ method="POST",
957
+ path="/v1/conversations/{conversation_id}",
958
+ base_url=base_url,
959
+ url_variables=url_variables,
960
+ request=request,
961
+ request_body_required=True,
962
+ request_has_path_params=True,
963
+ request_has_query_params=True,
964
+ user_agent_header="user-agent",
965
+ accept_header_value="application/json",
966
+ http_headers=http_headers,
967
+ security=self.sdk_configuration.security,
968
+ get_serialized_body=lambda: utils.serialize_request_body(
969
+ request.conversation_append_request,
970
+ False,
971
+ False,
972
+ "json",
973
+ models.ConversationAppendRequest,
974
+ ),
975
+ timeout_ms=timeout_ms,
976
+ )
977
+
978
+ if retries == UNSET:
979
+ if self.sdk_configuration.retry_config is not UNSET:
980
+ retries = self.sdk_configuration.retry_config
981
+
982
+ retry_config = None
983
+ if isinstance(retries, utils.RetryConfig):
984
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
985
+
986
+ http_res = self.do_request(
987
+ hook_ctx=HookContext(
988
+ base_url=base_url or "",
989
+ operation_id="agents_api_v1_conversations_append",
990
+ oauth2_scopes=[],
991
+ security_source=get_security_from_env(
992
+ self.sdk_configuration.security, models.Security
993
+ ),
994
+ ),
995
+ request=req,
996
+ error_status_codes=["422", "4XX", "5XX"],
997
+ retry_config=retry_config,
998
+ )
999
+
1000
+ response_data: Any = None
1001
+ if utils.match_response(http_res, "200", "application/json"):
1002
+ return utils.unmarshal_json(http_res.text, models.ConversationResponse)
1003
+ if utils.match_response(http_res, "422", "application/json"):
1004
+ response_data = utils.unmarshal_json(
1005
+ http_res.text, models.HTTPValidationErrorData
1006
+ )
1007
+ raise models.HTTPValidationError(data=response_data)
1008
+ if utils.match_response(http_res, "4XX", "*"):
1009
+ http_res_text = utils.stream_to_text(http_res)
1010
+ raise models.SDKError(
1011
+ "API error occurred", http_res.status_code, http_res_text, http_res
1012
+ )
1013
+ if utils.match_response(http_res, "5XX", "*"):
1014
+ http_res_text = utils.stream_to_text(http_res)
1015
+ raise models.SDKError(
1016
+ "API error occurred", http_res.status_code, http_res_text, http_res
1017
+ )
1018
+
1019
+ content_type = http_res.headers.get("Content-Type")
1020
+ http_res_text = utils.stream_to_text(http_res)
1021
+ raise models.SDKError(
1022
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1023
+ http_res.status_code,
1024
+ http_res_text,
1025
+ http_res,
1026
+ )
1027
+
1028
+ async def append_async(
1029
+ self,
1030
+ *,
1031
+ conversation_id: str,
1032
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
1033
+ stream: Optional[bool] = False,
1034
+ store: Optional[bool] = True,
1035
+ handoff_execution: Optional[
1036
+ models.ConversationAppendRequestHandoffExecution
1037
+ ] = "server",
1038
+ completion_args: Optional[
1039
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
1040
+ ] = None,
1041
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1042
+ server_url: Optional[str] = None,
1043
+ timeout_ms: Optional[int] = None,
1044
+ http_headers: Optional[Mapping[str, str]] = None,
1045
+ ) -> models.ConversationResponse:
1046
+ r"""Append new entries to an existing conversation.
1047
+
1048
+ Run completion on the history of the conversation and the user entries. Return the new created entries.
1049
+
1050
+ :param conversation_id: ID of the conversation to which we append entries.
1051
+ :param inputs:
1052
+ :param stream:
1053
+ :param store: Whether to store the results into our servers or not.
1054
+ :param handoff_execution:
1055
+ :param completion_args: White-listed arguments from the completion API
1056
+ :param retries: Override the default retry configuration for this method
1057
+ :param server_url: Override the default server URL for this method
1058
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1059
+ :param http_headers: Additional headers to set or replace on requests.
1060
+ """
1061
+ base_url = None
1062
+ url_variables = None
1063
+ if timeout_ms is None:
1064
+ timeout_ms = self.sdk_configuration.timeout_ms
1065
+
1066
+ if server_url is not None:
1067
+ base_url = server_url
1068
+ else:
1069
+ base_url = self._get_url(base_url, url_variables)
1070
+
1071
+ request = models.AgentsAPIV1ConversationsAppendRequest(
1072
+ conversation_id=conversation_id,
1073
+ conversation_append_request=models.ConversationAppendRequest(
1074
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
1075
+ stream=stream,
1076
+ store=store,
1077
+ handoff_execution=handoff_execution,
1078
+ completion_args=utils.get_pydantic_model(
1079
+ completion_args, Optional[models.CompletionArgs]
1080
+ ),
1081
+ ),
1082
+ )
1083
+
1084
+ req = self._build_request_async(
1085
+ method="POST",
1086
+ path="/v1/conversations/{conversation_id}",
1087
+ base_url=base_url,
1088
+ url_variables=url_variables,
1089
+ request=request,
1090
+ request_body_required=True,
1091
+ request_has_path_params=True,
1092
+ request_has_query_params=True,
1093
+ user_agent_header="user-agent",
1094
+ accept_header_value="application/json",
1095
+ http_headers=http_headers,
1096
+ security=self.sdk_configuration.security,
1097
+ get_serialized_body=lambda: utils.serialize_request_body(
1098
+ request.conversation_append_request,
1099
+ False,
1100
+ False,
1101
+ "json",
1102
+ models.ConversationAppendRequest,
1103
+ ),
1104
+ timeout_ms=timeout_ms,
1105
+ )
1106
+
1107
+ if retries == UNSET:
1108
+ if self.sdk_configuration.retry_config is not UNSET:
1109
+ retries = self.sdk_configuration.retry_config
1110
+
1111
+ retry_config = None
1112
+ if isinstance(retries, utils.RetryConfig):
1113
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1114
+
1115
+ http_res = await self.do_request_async(
1116
+ hook_ctx=HookContext(
1117
+ base_url=base_url or "",
1118
+ operation_id="agents_api_v1_conversations_append",
1119
+ oauth2_scopes=[],
1120
+ security_source=get_security_from_env(
1121
+ self.sdk_configuration.security, models.Security
1122
+ ),
1123
+ ),
1124
+ request=req,
1125
+ error_status_codes=["422", "4XX", "5XX"],
1126
+ retry_config=retry_config,
1127
+ )
1128
+
1129
+ response_data: Any = None
1130
+ if utils.match_response(http_res, "200", "application/json"):
1131
+ return utils.unmarshal_json(http_res.text, models.ConversationResponse)
1132
+ if utils.match_response(http_res, "422", "application/json"):
1133
+ response_data = utils.unmarshal_json(
1134
+ http_res.text, models.HTTPValidationErrorData
1135
+ )
1136
+ raise models.HTTPValidationError(data=response_data)
1137
+ if utils.match_response(http_res, "4XX", "*"):
1138
+ http_res_text = await utils.stream_to_text_async(http_res)
1139
+ raise models.SDKError(
1140
+ "API error occurred", http_res.status_code, http_res_text, http_res
1141
+ )
1142
+ if utils.match_response(http_res, "5XX", "*"):
1143
+ http_res_text = await utils.stream_to_text_async(http_res)
1144
+ raise models.SDKError(
1145
+ "API error occurred", http_res.status_code, http_res_text, http_res
1146
+ )
1147
+
1148
+ content_type = http_res.headers.get("Content-Type")
1149
+ http_res_text = await utils.stream_to_text_async(http_res)
1150
+ raise models.SDKError(
1151
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1152
+ http_res.status_code,
1153
+ http_res_text,
1154
+ http_res,
1155
+ )
1156
+
1157
+ def get_history(
1158
+ self,
1159
+ *,
1160
+ conversation_id: str,
1161
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1162
+ server_url: Optional[str] = None,
1163
+ timeout_ms: Optional[int] = None,
1164
+ http_headers: Optional[Mapping[str, str]] = None,
1165
+ ) -> models.ConversationHistory:
1166
+ r"""Retrieve all entries in a conversation.
1167
+
1168
+ Given a conversation_id retrieve all the entries belonging to that conversation. The entries are sorted in the order they were appended, those can be messages, connectors or function_call.
1169
+
1170
+ :param conversation_id:
1171
+ :param retries: Override the default retry configuration for this method
1172
+ :param server_url: Override the default server URL for this method
1173
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1174
+ :param http_headers: Additional headers to set or replace on requests.
1175
+ """
1176
+ base_url = None
1177
+ url_variables = None
1178
+ if timeout_ms is None:
1179
+ timeout_ms = self.sdk_configuration.timeout_ms
1180
+
1181
+ if server_url is not None:
1182
+ base_url = server_url
1183
+ else:
1184
+ base_url = self._get_url(base_url, url_variables)
1185
+
1186
+ request = models.AgentsAPIV1ConversationsHistoryRequest(
1187
+ conversation_id=conversation_id,
1188
+ )
1189
+
1190
+ req = self._build_request(
1191
+ method="GET",
1192
+ path="/v1/conversations/{conversation_id}/history",
1193
+ base_url=base_url,
1194
+ url_variables=url_variables,
1195
+ request=request,
1196
+ request_body_required=False,
1197
+ request_has_path_params=True,
1198
+ request_has_query_params=True,
1199
+ user_agent_header="user-agent",
1200
+ accept_header_value="application/json",
1201
+ http_headers=http_headers,
1202
+ security=self.sdk_configuration.security,
1203
+ timeout_ms=timeout_ms,
1204
+ )
1205
+
1206
+ if retries == UNSET:
1207
+ if self.sdk_configuration.retry_config is not UNSET:
1208
+ retries = self.sdk_configuration.retry_config
1209
+
1210
+ retry_config = None
1211
+ if isinstance(retries, utils.RetryConfig):
1212
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1213
+
1214
+ http_res = self.do_request(
1215
+ hook_ctx=HookContext(
1216
+ base_url=base_url or "",
1217
+ operation_id="agents_api_v1_conversations_history",
1218
+ oauth2_scopes=[],
1219
+ security_source=get_security_from_env(
1220
+ self.sdk_configuration.security, models.Security
1221
+ ),
1222
+ ),
1223
+ request=req,
1224
+ error_status_codes=["422", "4XX", "5XX"],
1225
+ retry_config=retry_config,
1226
+ )
1227
+
1228
+ response_data: Any = None
1229
+ if utils.match_response(http_res, "200", "application/json"):
1230
+ return utils.unmarshal_json(http_res.text, models.ConversationHistory)
1231
+ if utils.match_response(http_res, "422", "application/json"):
1232
+ response_data = utils.unmarshal_json(
1233
+ http_res.text, models.HTTPValidationErrorData
1234
+ )
1235
+ raise models.HTTPValidationError(data=response_data)
1236
+ if utils.match_response(http_res, "4XX", "*"):
1237
+ http_res_text = utils.stream_to_text(http_res)
1238
+ raise models.SDKError(
1239
+ "API error occurred", http_res.status_code, http_res_text, http_res
1240
+ )
1241
+ if utils.match_response(http_res, "5XX", "*"):
1242
+ http_res_text = utils.stream_to_text(http_res)
1243
+ raise models.SDKError(
1244
+ "API error occurred", http_res.status_code, http_res_text, http_res
1245
+ )
1246
+
1247
+ content_type = http_res.headers.get("Content-Type")
1248
+ http_res_text = utils.stream_to_text(http_res)
1249
+ raise models.SDKError(
1250
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1251
+ http_res.status_code,
1252
+ http_res_text,
1253
+ http_res,
1254
+ )
1255
+
1256
+ async def get_history_async(
1257
+ self,
1258
+ *,
1259
+ conversation_id: str,
1260
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1261
+ server_url: Optional[str] = None,
1262
+ timeout_ms: Optional[int] = None,
1263
+ http_headers: Optional[Mapping[str, str]] = None,
1264
+ ) -> models.ConversationHistory:
1265
+ r"""Retrieve all entries in a conversation.
1266
+
1267
+ Given a conversation_id retrieve all the entries belonging to that conversation. The entries are sorted in the order they were appended, those can be messages, connectors or function_call.
1268
+
1269
+ :param conversation_id:
1270
+ :param retries: Override the default retry configuration for this method
1271
+ :param server_url: Override the default server URL for this method
1272
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1273
+ :param http_headers: Additional headers to set or replace on requests.
1274
+ """
1275
+ base_url = None
1276
+ url_variables = None
1277
+ if timeout_ms is None:
1278
+ timeout_ms = self.sdk_configuration.timeout_ms
1279
+
1280
+ if server_url is not None:
1281
+ base_url = server_url
1282
+ else:
1283
+ base_url = self._get_url(base_url, url_variables)
1284
+
1285
+ request = models.AgentsAPIV1ConversationsHistoryRequest(
1286
+ conversation_id=conversation_id,
1287
+ )
1288
+
1289
+ req = self._build_request_async(
1290
+ method="GET",
1291
+ path="/v1/conversations/{conversation_id}/history",
1292
+ base_url=base_url,
1293
+ url_variables=url_variables,
1294
+ request=request,
1295
+ request_body_required=False,
1296
+ request_has_path_params=True,
1297
+ request_has_query_params=True,
1298
+ user_agent_header="user-agent",
1299
+ accept_header_value="application/json",
1300
+ http_headers=http_headers,
1301
+ security=self.sdk_configuration.security,
1302
+ timeout_ms=timeout_ms,
1303
+ )
1304
+
1305
+ if retries == UNSET:
1306
+ if self.sdk_configuration.retry_config is not UNSET:
1307
+ retries = self.sdk_configuration.retry_config
1308
+
1309
+ retry_config = None
1310
+ if isinstance(retries, utils.RetryConfig):
1311
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1312
+
1313
+ http_res = await self.do_request_async(
1314
+ hook_ctx=HookContext(
1315
+ base_url=base_url or "",
1316
+ operation_id="agents_api_v1_conversations_history",
1317
+ oauth2_scopes=[],
1318
+ security_source=get_security_from_env(
1319
+ self.sdk_configuration.security, models.Security
1320
+ ),
1321
+ ),
1322
+ request=req,
1323
+ error_status_codes=["422", "4XX", "5XX"],
1324
+ retry_config=retry_config,
1325
+ )
1326
+
1327
+ response_data: Any = None
1328
+ if utils.match_response(http_res, "200", "application/json"):
1329
+ return utils.unmarshal_json(http_res.text, models.ConversationHistory)
1330
+ if utils.match_response(http_res, "422", "application/json"):
1331
+ response_data = utils.unmarshal_json(
1332
+ http_res.text, models.HTTPValidationErrorData
1333
+ )
1334
+ raise models.HTTPValidationError(data=response_data)
1335
+ if utils.match_response(http_res, "4XX", "*"):
1336
+ http_res_text = await utils.stream_to_text_async(http_res)
1337
+ raise models.SDKError(
1338
+ "API error occurred", http_res.status_code, http_res_text, http_res
1339
+ )
1340
+ if utils.match_response(http_res, "5XX", "*"):
1341
+ http_res_text = await utils.stream_to_text_async(http_res)
1342
+ raise models.SDKError(
1343
+ "API error occurred", http_res.status_code, http_res_text, http_res
1344
+ )
1345
+
1346
+ content_type = http_res.headers.get("Content-Type")
1347
+ http_res_text = await utils.stream_to_text_async(http_res)
1348
+ raise models.SDKError(
1349
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1350
+ http_res.status_code,
1351
+ http_res_text,
1352
+ http_res,
1353
+ )
1354
+
1355
+ def get_messages(
1356
+ self,
1357
+ *,
1358
+ conversation_id: str,
1359
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1360
+ server_url: Optional[str] = None,
1361
+ timeout_ms: Optional[int] = None,
1362
+ http_headers: Optional[Mapping[str, str]] = None,
1363
+ ) -> models.ConversationMessages:
1364
+ r"""Retrieve all messages in a conversation.
1365
+
1366
+ Given a conversation_id retrieve all the messages belonging to that conversation. This is similar to retrieving all entries except we filter the messages only.
1367
+
1368
+ :param conversation_id:
1369
+ :param retries: Override the default retry configuration for this method
1370
+ :param server_url: Override the default server URL for this method
1371
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1372
+ :param http_headers: Additional headers to set or replace on requests.
1373
+ """
1374
+ base_url = None
1375
+ url_variables = None
1376
+ if timeout_ms is None:
1377
+ timeout_ms = self.sdk_configuration.timeout_ms
1378
+
1379
+ if server_url is not None:
1380
+ base_url = server_url
1381
+ else:
1382
+ base_url = self._get_url(base_url, url_variables)
1383
+
1384
+ request = models.AgentsAPIV1ConversationsMessagesRequest(
1385
+ conversation_id=conversation_id,
1386
+ )
1387
+
1388
+ req = self._build_request(
1389
+ method="GET",
1390
+ path="/v1/conversations/{conversation_id}/messages",
1391
+ base_url=base_url,
1392
+ url_variables=url_variables,
1393
+ request=request,
1394
+ request_body_required=False,
1395
+ request_has_path_params=True,
1396
+ request_has_query_params=True,
1397
+ user_agent_header="user-agent",
1398
+ accept_header_value="application/json",
1399
+ http_headers=http_headers,
1400
+ security=self.sdk_configuration.security,
1401
+ timeout_ms=timeout_ms,
1402
+ )
1403
+
1404
+ if retries == UNSET:
1405
+ if self.sdk_configuration.retry_config is not UNSET:
1406
+ retries = self.sdk_configuration.retry_config
1407
+
1408
+ retry_config = None
1409
+ if isinstance(retries, utils.RetryConfig):
1410
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1411
+
1412
+ http_res = self.do_request(
1413
+ hook_ctx=HookContext(
1414
+ base_url=base_url or "",
1415
+ operation_id="agents_api_v1_conversations_messages",
1416
+ oauth2_scopes=[],
1417
+ security_source=get_security_from_env(
1418
+ self.sdk_configuration.security, models.Security
1419
+ ),
1420
+ ),
1421
+ request=req,
1422
+ error_status_codes=["422", "4XX", "5XX"],
1423
+ retry_config=retry_config,
1424
+ )
1425
+
1426
+ response_data: Any = None
1427
+ if utils.match_response(http_res, "200", "application/json"):
1428
+ return utils.unmarshal_json(http_res.text, models.ConversationMessages)
1429
+ if utils.match_response(http_res, "422", "application/json"):
1430
+ response_data = utils.unmarshal_json(
1431
+ http_res.text, models.HTTPValidationErrorData
1432
+ )
1433
+ raise models.HTTPValidationError(data=response_data)
1434
+ if utils.match_response(http_res, "4XX", "*"):
1435
+ http_res_text = utils.stream_to_text(http_res)
1436
+ raise models.SDKError(
1437
+ "API error occurred", http_res.status_code, http_res_text, http_res
1438
+ )
1439
+ if utils.match_response(http_res, "5XX", "*"):
1440
+ http_res_text = utils.stream_to_text(http_res)
1441
+ raise models.SDKError(
1442
+ "API error occurred", http_res.status_code, http_res_text, http_res
1443
+ )
1444
+
1445
+ content_type = http_res.headers.get("Content-Type")
1446
+ http_res_text = utils.stream_to_text(http_res)
1447
+ raise models.SDKError(
1448
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1449
+ http_res.status_code,
1450
+ http_res_text,
1451
+ http_res,
1452
+ )
1453
+
1454
+ async def get_messages_async(
1455
+ self,
1456
+ *,
1457
+ conversation_id: str,
1458
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1459
+ server_url: Optional[str] = None,
1460
+ timeout_ms: Optional[int] = None,
1461
+ http_headers: Optional[Mapping[str, str]] = None,
1462
+ ) -> models.ConversationMessages:
1463
+ r"""Retrieve all messages in a conversation.
1464
+
1465
+ Given a conversation_id retrieve all the messages belonging to that conversation. This is similar to retrieving all entries except we filter the messages only.
1466
+
1467
+ :param conversation_id:
1468
+ :param retries: Override the default retry configuration for this method
1469
+ :param server_url: Override the default server URL for this method
1470
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1471
+ :param http_headers: Additional headers to set or replace on requests.
1472
+ """
1473
+ base_url = None
1474
+ url_variables = None
1475
+ if timeout_ms is None:
1476
+ timeout_ms = self.sdk_configuration.timeout_ms
1477
+
1478
+ if server_url is not None:
1479
+ base_url = server_url
1480
+ else:
1481
+ base_url = self._get_url(base_url, url_variables)
1482
+
1483
+ request = models.AgentsAPIV1ConversationsMessagesRequest(
1484
+ conversation_id=conversation_id,
1485
+ )
1486
+
1487
+ req = self._build_request_async(
1488
+ method="GET",
1489
+ path="/v1/conversations/{conversation_id}/messages",
1490
+ base_url=base_url,
1491
+ url_variables=url_variables,
1492
+ request=request,
1493
+ request_body_required=False,
1494
+ request_has_path_params=True,
1495
+ request_has_query_params=True,
1496
+ user_agent_header="user-agent",
1497
+ accept_header_value="application/json",
1498
+ http_headers=http_headers,
1499
+ security=self.sdk_configuration.security,
1500
+ timeout_ms=timeout_ms,
1501
+ )
1502
+
1503
+ if retries == UNSET:
1504
+ if self.sdk_configuration.retry_config is not UNSET:
1505
+ retries = self.sdk_configuration.retry_config
1506
+
1507
+ retry_config = None
1508
+ if isinstance(retries, utils.RetryConfig):
1509
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1510
+
1511
+ http_res = await self.do_request_async(
1512
+ hook_ctx=HookContext(
1513
+ base_url=base_url or "",
1514
+ operation_id="agents_api_v1_conversations_messages",
1515
+ oauth2_scopes=[],
1516
+ security_source=get_security_from_env(
1517
+ self.sdk_configuration.security, models.Security
1518
+ ),
1519
+ ),
1520
+ request=req,
1521
+ error_status_codes=["422", "4XX", "5XX"],
1522
+ retry_config=retry_config,
1523
+ )
1524
+
1525
+ response_data: Any = None
1526
+ if utils.match_response(http_res, "200", "application/json"):
1527
+ return utils.unmarshal_json(http_res.text, models.ConversationMessages)
1528
+ if utils.match_response(http_res, "422", "application/json"):
1529
+ response_data = utils.unmarshal_json(
1530
+ http_res.text, models.HTTPValidationErrorData
1531
+ )
1532
+ raise models.HTTPValidationError(data=response_data)
1533
+ if utils.match_response(http_res, "4XX", "*"):
1534
+ http_res_text = await utils.stream_to_text_async(http_res)
1535
+ raise models.SDKError(
1536
+ "API error occurred", http_res.status_code, http_res_text, http_res
1537
+ )
1538
+ if utils.match_response(http_res, "5XX", "*"):
1539
+ http_res_text = await utils.stream_to_text_async(http_res)
1540
+ raise models.SDKError(
1541
+ "API error occurred", http_res.status_code, http_res_text, http_res
1542
+ )
1543
+
1544
+ content_type = http_res.headers.get("Content-Type")
1545
+ http_res_text = await utils.stream_to_text_async(http_res)
1546
+ raise models.SDKError(
1547
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1548
+ http_res.status_code,
1549
+ http_res_text,
1550
+ http_res,
1551
+ )
1552
+
1553
+ def restart(
1554
+ self,
1555
+ *,
1556
+ conversation_id: str,
1557
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
1558
+ from_entry_id: str,
1559
+ stream: Optional[bool] = False,
1560
+ store: Optional[bool] = True,
1561
+ handoff_execution: Optional[
1562
+ models.ConversationRestartRequestHandoffExecution
1563
+ ] = "server",
1564
+ completion_args: Optional[
1565
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
1566
+ ] = None,
1567
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1568
+ server_url: Optional[str] = None,
1569
+ timeout_ms: Optional[int] = None,
1570
+ http_headers: Optional[Mapping[str, str]] = None,
1571
+ ) -> models.ConversationResponse:
1572
+ r"""Restart a conversation starting from a given entry.
1573
+
1574
+ Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.
1575
+
1576
+ :param conversation_id:
1577
+ :param inputs:
1578
+ :param from_entry_id:
1579
+ :param stream:
1580
+ :param store: Whether to store the results into our servers or not.
1581
+ :param handoff_execution:
1582
+ :param completion_args: White-listed arguments from the completion API
1583
+ :param retries: Override the default retry configuration for this method
1584
+ :param server_url: Override the default server URL for this method
1585
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1586
+ :param http_headers: Additional headers to set or replace on requests.
1587
+ """
1588
+ base_url = None
1589
+ url_variables = None
1590
+ if timeout_ms is None:
1591
+ timeout_ms = self.sdk_configuration.timeout_ms
1592
+
1593
+ if server_url is not None:
1594
+ base_url = server_url
1595
+ else:
1596
+ base_url = self._get_url(base_url, url_variables)
1597
+
1598
+ request = models.AgentsAPIV1ConversationsRestartRequest(
1599
+ conversation_id=conversation_id,
1600
+ conversation_restart_request=models.ConversationRestartRequest(
1601
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
1602
+ stream=stream,
1603
+ store=store,
1604
+ handoff_execution=handoff_execution,
1605
+ from_entry_id=from_entry_id,
1606
+ completion_args=utils.get_pydantic_model(
1607
+ completion_args, Optional[models.CompletionArgs]
1608
+ ),
1609
+ ),
1610
+ )
1611
+
1612
+ req = self._build_request(
1613
+ method="POST",
1614
+ path="/v1/conversations/{conversation_id}/restart",
1615
+ base_url=base_url,
1616
+ url_variables=url_variables,
1617
+ request=request,
1618
+ request_body_required=True,
1619
+ request_has_path_params=True,
1620
+ request_has_query_params=True,
1621
+ user_agent_header="user-agent",
1622
+ accept_header_value="application/json",
1623
+ http_headers=http_headers,
1624
+ security=self.sdk_configuration.security,
1625
+ get_serialized_body=lambda: utils.serialize_request_body(
1626
+ request.conversation_restart_request,
1627
+ False,
1628
+ False,
1629
+ "json",
1630
+ models.ConversationRestartRequest,
1631
+ ),
1632
+ timeout_ms=timeout_ms,
1633
+ )
1634
+
1635
+ if retries == UNSET:
1636
+ if self.sdk_configuration.retry_config is not UNSET:
1637
+ retries = self.sdk_configuration.retry_config
1638
+
1639
+ retry_config = None
1640
+ if isinstance(retries, utils.RetryConfig):
1641
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1642
+
1643
+ http_res = self.do_request(
1644
+ hook_ctx=HookContext(
1645
+ base_url=base_url or "",
1646
+ operation_id="agents_api_v1_conversations_restart",
1647
+ oauth2_scopes=[],
1648
+ security_source=get_security_from_env(
1649
+ self.sdk_configuration.security, models.Security
1650
+ ),
1651
+ ),
1652
+ request=req,
1653
+ error_status_codes=["422", "4XX", "5XX"],
1654
+ retry_config=retry_config,
1655
+ )
1656
+
1657
+ response_data: Any = None
1658
+ if utils.match_response(http_res, "200", "application/json"):
1659
+ return utils.unmarshal_json(http_res.text, models.ConversationResponse)
1660
+ if utils.match_response(http_res, "422", "application/json"):
1661
+ response_data = utils.unmarshal_json(
1662
+ http_res.text, models.HTTPValidationErrorData
1663
+ )
1664
+ raise models.HTTPValidationError(data=response_data)
1665
+ if utils.match_response(http_res, "4XX", "*"):
1666
+ http_res_text = utils.stream_to_text(http_res)
1667
+ raise models.SDKError(
1668
+ "API error occurred", http_res.status_code, http_res_text, http_res
1669
+ )
1670
+ if utils.match_response(http_res, "5XX", "*"):
1671
+ http_res_text = utils.stream_to_text(http_res)
1672
+ raise models.SDKError(
1673
+ "API error occurred", http_res.status_code, http_res_text, http_res
1674
+ )
1675
+
1676
+ content_type = http_res.headers.get("Content-Type")
1677
+ http_res_text = utils.stream_to_text(http_res)
1678
+ raise models.SDKError(
1679
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1680
+ http_res.status_code,
1681
+ http_res_text,
1682
+ http_res,
1683
+ )
1684
+
1685
+ async def restart_async(
1686
+ self,
1687
+ *,
1688
+ conversation_id: str,
1689
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
1690
+ from_entry_id: str,
1691
+ stream: Optional[bool] = False,
1692
+ store: Optional[bool] = True,
1693
+ handoff_execution: Optional[
1694
+ models.ConversationRestartRequestHandoffExecution
1695
+ ] = "server",
1696
+ completion_args: Optional[
1697
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
1698
+ ] = None,
1699
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1700
+ server_url: Optional[str] = None,
1701
+ timeout_ms: Optional[int] = None,
1702
+ http_headers: Optional[Mapping[str, str]] = None,
1703
+ ) -> models.ConversationResponse:
1704
+ r"""Restart a conversation starting from a given entry.
1705
+
1706
+ Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.
1707
+
1708
+ :param conversation_id:
1709
+ :param inputs:
1710
+ :param from_entry_id:
1711
+ :param stream:
1712
+ :param store: Whether to store the results into our servers or not.
1713
+ :param handoff_execution:
1714
+ :param completion_args: White-listed arguments from the completion API
1715
+ :param retries: Override the default retry configuration for this method
1716
+ :param server_url: Override the default server URL for this method
1717
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1718
+ :param http_headers: Additional headers to set or replace on requests.
1719
+ """
1720
+ base_url = None
1721
+ url_variables = None
1722
+ if timeout_ms is None:
1723
+ timeout_ms = self.sdk_configuration.timeout_ms
1724
+
1725
+ if server_url is not None:
1726
+ base_url = server_url
1727
+ else:
1728
+ base_url = self._get_url(base_url, url_variables)
1729
+
1730
+ request = models.AgentsAPIV1ConversationsRestartRequest(
1731
+ conversation_id=conversation_id,
1732
+ conversation_restart_request=models.ConversationRestartRequest(
1733
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
1734
+ stream=stream,
1735
+ store=store,
1736
+ handoff_execution=handoff_execution,
1737
+ from_entry_id=from_entry_id,
1738
+ completion_args=utils.get_pydantic_model(
1739
+ completion_args, Optional[models.CompletionArgs]
1740
+ ),
1741
+ ),
1742
+ )
1743
+
1744
+ req = self._build_request_async(
1745
+ method="POST",
1746
+ path="/v1/conversations/{conversation_id}/restart",
1747
+ base_url=base_url,
1748
+ url_variables=url_variables,
1749
+ request=request,
1750
+ request_body_required=True,
1751
+ request_has_path_params=True,
1752
+ request_has_query_params=True,
1753
+ user_agent_header="user-agent",
1754
+ accept_header_value="application/json",
1755
+ http_headers=http_headers,
1756
+ security=self.sdk_configuration.security,
1757
+ get_serialized_body=lambda: utils.serialize_request_body(
1758
+ request.conversation_restart_request,
1759
+ False,
1760
+ False,
1761
+ "json",
1762
+ models.ConversationRestartRequest,
1763
+ ),
1764
+ timeout_ms=timeout_ms,
1765
+ )
1766
+
1767
+ if retries == UNSET:
1768
+ if self.sdk_configuration.retry_config is not UNSET:
1769
+ retries = self.sdk_configuration.retry_config
1770
+
1771
+ retry_config = None
1772
+ if isinstance(retries, utils.RetryConfig):
1773
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1774
+
1775
+ http_res = await self.do_request_async(
1776
+ hook_ctx=HookContext(
1777
+ base_url=base_url or "",
1778
+ operation_id="agents_api_v1_conversations_restart",
1779
+ oauth2_scopes=[],
1780
+ security_source=get_security_from_env(
1781
+ self.sdk_configuration.security, models.Security
1782
+ ),
1783
+ ),
1784
+ request=req,
1785
+ error_status_codes=["422", "4XX", "5XX"],
1786
+ retry_config=retry_config,
1787
+ )
1788
+
1789
+ response_data: Any = None
1790
+ if utils.match_response(http_res, "200", "application/json"):
1791
+ return utils.unmarshal_json(http_res.text, models.ConversationResponse)
1792
+ if utils.match_response(http_res, "422", "application/json"):
1793
+ response_data = utils.unmarshal_json(
1794
+ http_res.text, models.HTTPValidationErrorData
1795
+ )
1796
+ raise models.HTTPValidationError(data=response_data)
1797
+ if utils.match_response(http_res, "4XX", "*"):
1798
+ http_res_text = await utils.stream_to_text_async(http_res)
1799
+ raise models.SDKError(
1800
+ "API error occurred", http_res.status_code, http_res_text, http_res
1801
+ )
1802
+ if utils.match_response(http_res, "5XX", "*"):
1803
+ http_res_text = await utils.stream_to_text_async(http_res)
1804
+ raise models.SDKError(
1805
+ "API error occurred", http_res.status_code, http_res_text, http_res
1806
+ )
1807
+
1808
+ content_type = http_res.headers.get("Content-Type")
1809
+ http_res_text = await utils.stream_to_text_async(http_res)
1810
+ raise models.SDKError(
1811
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1812
+ http_res.status_code,
1813
+ http_res_text,
1814
+ http_res,
1815
+ )
1816
+
1817
+ def start_stream(
1818
+ self,
1819
+ *,
1820
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
1821
+ stream: Optional[bool] = True,
1822
+ store: OptionalNullable[bool] = UNSET,
1823
+ handoff_execution: OptionalNullable[
1824
+ models.ConversationStreamRequestHandoffExecution
1825
+ ] = UNSET,
1826
+ instructions: OptionalNullable[str] = UNSET,
1827
+ tools: OptionalNullable[
1828
+ Union[
1829
+ List[models.ConversationStreamRequestTools],
1830
+ List[models.ConversationStreamRequestToolsTypedDict],
1831
+ ]
1832
+ ] = UNSET,
1833
+ completion_args: OptionalNullable[
1834
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
1835
+ ] = UNSET,
1836
+ name: OptionalNullable[str] = UNSET,
1837
+ description: OptionalNullable[str] = UNSET,
1838
+ agent_id: OptionalNullable[str] = UNSET,
1839
+ model: OptionalNullable[str] = UNSET,
1840
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1841
+ server_url: Optional[str] = None,
1842
+ timeout_ms: Optional[int] = None,
1843
+ http_headers: Optional[Mapping[str, str]] = None,
1844
+ ) -> eventstreaming.EventStream[models.ConversationEvents]:
1845
+ r"""Create a conversation and append entries to it.
1846
+
1847
+ Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.
1848
+
1849
+ :param inputs:
1850
+ :param stream:
1851
+ :param store:
1852
+ :param handoff_execution:
1853
+ :param instructions:
1854
+ :param tools:
1855
+ :param completion_args:
1856
+ :param name:
1857
+ :param description:
1858
+ :param agent_id:
1859
+ :param model:
1860
+ :param retries: Override the default retry configuration for this method
1861
+ :param server_url: Override the default server URL for this method
1862
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
1863
+ :param http_headers: Additional headers to set or replace on requests.
1864
+ """
1865
+ base_url = None
1866
+ url_variables = None
1867
+ if timeout_ms is None:
1868
+ timeout_ms = self.sdk_configuration.timeout_ms
1869
+
1870
+ if server_url is not None:
1871
+ base_url = server_url
1872
+ else:
1873
+ base_url = self._get_url(base_url, url_variables)
1874
+
1875
+ request = models.ConversationStreamRequest(
1876
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
1877
+ stream=stream,
1878
+ store=store,
1879
+ handoff_execution=handoff_execution,
1880
+ instructions=instructions,
1881
+ tools=utils.get_pydantic_model(
1882
+ tools, OptionalNullable[List[models.ConversationStreamRequestTools]]
1883
+ ),
1884
+ completion_args=utils.get_pydantic_model(
1885
+ completion_args, OptionalNullable[models.CompletionArgs]
1886
+ ),
1887
+ name=name,
1888
+ description=description,
1889
+ agent_id=agent_id,
1890
+ model=model,
1891
+ )
1892
+
1893
+ req = self._build_request(
1894
+ method="POST",
1895
+ path="/v1/conversations#stream",
1896
+ base_url=base_url,
1897
+ url_variables=url_variables,
1898
+ request=request,
1899
+ request_body_required=True,
1900
+ request_has_path_params=False,
1901
+ request_has_query_params=True,
1902
+ user_agent_header="user-agent",
1903
+ accept_header_value="text/event-stream",
1904
+ http_headers=http_headers,
1905
+ security=self.sdk_configuration.security,
1906
+ get_serialized_body=lambda: utils.serialize_request_body(
1907
+ request, False, False, "json", models.ConversationStreamRequest
1908
+ ),
1909
+ timeout_ms=timeout_ms,
1910
+ )
1911
+
1912
+ if retries == UNSET:
1913
+ if self.sdk_configuration.retry_config is not UNSET:
1914
+ retries = self.sdk_configuration.retry_config
1915
+
1916
+ retry_config = None
1917
+ if isinstance(retries, utils.RetryConfig):
1918
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
1919
+
1920
+ http_res = self.do_request(
1921
+ hook_ctx=HookContext(
1922
+ base_url=base_url or "",
1923
+ operation_id="agents_api_v1_conversations_start_stream",
1924
+ oauth2_scopes=[],
1925
+ security_source=get_security_from_env(
1926
+ self.sdk_configuration.security, models.Security
1927
+ ),
1928
+ ),
1929
+ request=req,
1930
+ error_status_codes=["422", "4XX", "5XX"],
1931
+ stream=True,
1932
+ retry_config=retry_config,
1933
+ )
1934
+
1935
+ response_data: Any = None
1936
+ if utils.match_response(http_res, "200", "text/event-stream"):
1937
+ return eventstreaming.EventStream(
1938
+ http_res,
1939
+ lambda raw: utils.unmarshal_json(raw, models.ConversationEvents),
1940
+ )
1941
+ if utils.match_response(http_res, "422", "application/json"):
1942
+ http_res_text = utils.stream_to_text(http_res)
1943
+ response_data = utils.unmarshal_json(
1944
+ http_res_text, models.HTTPValidationErrorData
1945
+ )
1946
+ raise models.HTTPValidationError(data=response_data)
1947
+ if utils.match_response(http_res, "4XX", "*"):
1948
+ http_res_text = utils.stream_to_text(http_res)
1949
+ raise models.SDKError(
1950
+ "API error occurred", http_res.status_code, http_res_text, http_res
1951
+ )
1952
+ if utils.match_response(http_res, "5XX", "*"):
1953
+ http_res_text = utils.stream_to_text(http_res)
1954
+ raise models.SDKError(
1955
+ "API error occurred", http_res.status_code, http_res_text, http_res
1956
+ )
1957
+
1958
+ content_type = http_res.headers.get("Content-Type")
1959
+ http_res_text = utils.stream_to_text(http_res)
1960
+ raise models.SDKError(
1961
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
1962
+ http_res.status_code,
1963
+ http_res_text,
1964
+ http_res,
1965
+ )
1966
+
1967
+ async def start_stream_async(
1968
+ self,
1969
+ *,
1970
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
1971
+ stream: Optional[bool] = True,
1972
+ store: OptionalNullable[bool] = UNSET,
1973
+ handoff_execution: OptionalNullable[
1974
+ models.ConversationStreamRequestHandoffExecution
1975
+ ] = UNSET,
1976
+ instructions: OptionalNullable[str] = UNSET,
1977
+ tools: OptionalNullable[
1978
+ Union[
1979
+ List[models.ConversationStreamRequestTools],
1980
+ List[models.ConversationStreamRequestToolsTypedDict],
1981
+ ]
1982
+ ] = UNSET,
1983
+ completion_args: OptionalNullable[
1984
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
1985
+ ] = UNSET,
1986
+ name: OptionalNullable[str] = UNSET,
1987
+ description: OptionalNullable[str] = UNSET,
1988
+ agent_id: OptionalNullable[str] = UNSET,
1989
+ model: OptionalNullable[str] = UNSET,
1990
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
1991
+ server_url: Optional[str] = None,
1992
+ timeout_ms: Optional[int] = None,
1993
+ http_headers: Optional[Mapping[str, str]] = None,
1994
+ ) -> eventstreaming.EventStreamAsync[models.ConversationEvents]:
1995
+ r"""Create a conversation and append entries to it.
1996
+
1997
+ Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.
1998
+
1999
+ :param inputs:
2000
+ :param stream:
2001
+ :param store:
2002
+ :param handoff_execution:
2003
+ :param instructions:
2004
+ :param tools:
2005
+ :param completion_args:
2006
+ :param name:
2007
+ :param description:
2008
+ :param agent_id:
2009
+ :param model:
2010
+ :param retries: Override the default retry configuration for this method
2011
+ :param server_url: Override the default server URL for this method
2012
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2013
+ :param http_headers: Additional headers to set or replace on requests.
2014
+ """
2015
+ base_url = None
2016
+ url_variables = None
2017
+ if timeout_ms is None:
2018
+ timeout_ms = self.sdk_configuration.timeout_ms
2019
+
2020
+ if server_url is not None:
2021
+ base_url = server_url
2022
+ else:
2023
+ base_url = self._get_url(base_url, url_variables)
2024
+
2025
+ request = models.ConversationStreamRequest(
2026
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
2027
+ stream=stream,
2028
+ store=store,
2029
+ handoff_execution=handoff_execution,
2030
+ instructions=instructions,
2031
+ tools=utils.get_pydantic_model(
2032
+ tools, OptionalNullable[List[models.ConversationStreamRequestTools]]
2033
+ ),
2034
+ completion_args=utils.get_pydantic_model(
2035
+ completion_args, OptionalNullable[models.CompletionArgs]
2036
+ ),
2037
+ name=name,
2038
+ description=description,
2039
+ agent_id=agent_id,
2040
+ model=model,
2041
+ )
2042
+
2043
+ req = self._build_request_async(
2044
+ method="POST",
2045
+ path="/v1/conversations#stream",
2046
+ base_url=base_url,
2047
+ url_variables=url_variables,
2048
+ request=request,
2049
+ request_body_required=True,
2050
+ request_has_path_params=False,
2051
+ request_has_query_params=True,
2052
+ user_agent_header="user-agent",
2053
+ accept_header_value="text/event-stream",
2054
+ http_headers=http_headers,
2055
+ security=self.sdk_configuration.security,
2056
+ get_serialized_body=lambda: utils.serialize_request_body(
2057
+ request, False, False, "json", models.ConversationStreamRequest
2058
+ ),
2059
+ timeout_ms=timeout_ms,
2060
+ )
2061
+
2062
+ if retries == UNSET:
2063
+ if self.sdk_configuration.retry_config is not UNSET:
2064
+ retries = self.sdk_configuration.retry_config
2065
+
2066
+ retry_config = None
2067
+ if isinstance(retries, utils.RetryConfig):
2068
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2069
+
2070
+ http_res = await self.do_request_async(
2071
+ hook_ctx=HookContext(
2072
+ base_url=base_url or "",
2073
+ operation_id="agents_api_v1_conversations_start_stream",
2074
+ oauth2_scopes=[],
2075
+ security_source=get_security_from_env(
2076
+ self.sdk_configuration.security, models.Security
2077
+ ),
2078
+ ),
2079
+ request=req,
2080
+ error_status_codes=["422", "4XX", "5XX"],
2081
+ stream=True,
2082
+ retry_config=retry_config,
2083
+ )
2084
+
2085
+ response_data: Any = None
2086
+ if utils.match_response(http_res, "200", "text/event-stream"):
2087
+ return eventstreaming.EventStreamAsync(
2088
+ http_res,
2089
+ lambda raw: utils.unmarshal_json(raw, models.ConversationEvents),
2090
+ )
2091
+ if utils.match_response(http_res, "422", "application/json"):
2092
+ http_res_text = await utils.stream_to_text_async(http_res)
2093
+ response_data = utils.unmarshal_json(
2094
+ http_res_text, models.HTTPValidationErrorData
2095
+ )
2096
+ raise models.HTTPValidationError(data=response_data)
2097
+ if utils.match_response(http_res, "4XX", "*"):
2098
+ http_res_text = await utils.stream_to_text_async(http_res)
2099
+ raise models.SDKError(
2100
+ "API error occurred", http_res.status_code, http_res_text, http_res
2101
+ )
2102
+ if utils.match_response(http_res, "5XX", "*"):
2103
+ http_res_text = await utils.stream_to_text_async(http_res)
2104
+ raise models.SDKError(
2105
+ "API error occurred", http_res.status_code, http_res_text, http_res
2106
+ )
2107
+
2108
+ content_type = http_res.headers.get("Content-Type")
2109
+ http_res_text = await utils.stream_to_text_async(http_res)
2110
+ raise models.SDKError(
2111
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2112
+ http_res.status_code,
2113
+ http_res_text,
2114
+ http_res,
2115
+ )
2116
+
2117
+ def append_stream(
2118
+ self,
2119
+ *,
2120
+ conversation_id: str,
2121
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
2122
+ stream: Optional[bool] = True,
2123
+ store: Optional[bool] = True,
2124
+ handoff_execution: Optional[
2125
+ models.ConversationAppendStreamRequestHandoffExecution
2126
+ ] = "server",
2127
+ completion_args: Optional[
2128
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
2129
+ ] = None,
2130
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2131
+ server_url: Optional[str] = None,
2132
+ timeout_ms: Optional[int] = None,
2133
+ http_headers: Optional[Mapping[str, str]] = None,
2134
+ ) -> eventstreaming.EventStream[models.ConversationEvents]:
2135
+ r"""Append new entries to an existing conversation.
2136
+
2137
+ Run completion on the history of the conversation and the user entries. Return the new created entries.
2138
+
2139
+ :param conversation_id: ID of the conversation to which we append entries.
2140
+ :param inputs:
2141
+ :param stream:
2142
+ :param store: Whether to store the results into our servers or not.
2143
+ :param handoff_execution:
2144
+ :param completion_args: White-listed arguments from the completion API
2145
+ :param retries: Override the default retry configuration for this method
2146
+ :param server_url: Override the default server URL for this method
2147
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2148
+ :param http_headers: Additional headers to set or replace on requests.
2149
+ """
2150
+ base_url = None
2151
+ url_variables = None
2152
+ if timeout_ms is None:
2153
+ timeout_ms = self.sdk_configuration.timeout_ms
2154
+
2155
+ if server_url is not None:
2156
+ base_url = server_url
2157
+ else:
2158
+ base_url = self._get_url(base_url, url_variables)
2159
+
2160
+ request = models.AgentsAPIV1ConversationsAppendStreamRequest(
2161
+ conversation_id=conversation_id,
2162
+ conversation_append_stream_request=models.ConversationAppendStreamRequest(
2163
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
2164
+ stream=stream,
2165
+ store=store,
2166
+ handoff_execution=handoff_execution,
2167
+ completion_args=utils.get_pydantic_model(
2168
+ completion_args, Optional[models.CompletionArgs]
2169
+ ),
2170
+ ),
2171
+ )
2172
+
2173
+ req = self._build_request(
2174
+ method="POST",
2175
+ path="/v1/conversations/{conversation_id}#stream",
2176
+ base_url=base_url,
2177
+ url_variables=url_variables,
2178
+ request=request,
2179
+ request_body_required=True,
2180
+ request_has_path_params=True,
2181
+ request_has_query_params=True,
2182
+ user_agent_header="user-agent",
2183
+ accept_header_value="text/event-stream",
2184
+ http_headers=http_headers,
2185
+ security=self.sdk_configuration.security,
2186
+ get_serialized_body=lambda: utils.serialize_request_body(
2187
+ request.conversation_append_stream_request,
2188
+ False,
2189
+ False,
2190
+ "json",
2191
+ models.ConversationAppendStreamRequest,
2192
+ ),
2193
+ timeout_ms=timeout_ms,
2194
+ )
2195
+
2196
+ if retries == UNSET:
2197
+ if self.sdk_configuration.retry_config is not UNSET:
2198
+ retries = self.sdk_configuration.retry_config
2199
+
2200
+ retry_config = None
2201
+ if isinstance(retries, utils.RetryConfig):
2202
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2203
+
2204
+ http_res = self.do_request(
2205
+ hook_ctx=HookContext(
2206
+ base_url=base_url or "",
2207
+ operation_id="agents_api_v1_conversations_append_stream",
2208
+ oauth2_scopes=[],
2209
+ security_source=get_security_from_env(
2210
+ self.sdk_configuration.security, models.Security
2211
+ ),
2212
+ ),
2213
+ request=req,
2214
+ error_status_codes=["422", "4XX", "5XX"],
2215
+ stream=True,
2216
+ retry_config=retry_config,
2217
+ )
2218
+
2219
+ response_data: Any = None
2220
+ if utils.match_response(http_res, "200", "text/event-stream"):
2221
+ return eventstreaming.EventStream(
2222
+ http_res,
2223
+ lambda raw: utils.unmarshal_json(raw, models.ConversationEvents),
2224
+ )
2225
+ if utils.match_response(http_res, "422", "application/json"):
2226
+ http_res_text = utils.stream_to_text(http_res)
2227
+ response_data = utils.unmarshal_json(
2228
+ http_res_text, models.HTTPValidationErrorData
2229
+ )
2230
+ raise models.HTTPValidationError(data=response_data)
2231
+ if utils.match_response(http_res, "4XX", "*"):
2232
+ http_res_text = utils.stream_to_text(http_res)
2233
+ raise models.SDKError(
2234
+ "API error occurred", http_res.status_code, http_res_text, http_res
2235
+ )
2236
+ if utils.match_response(http_res, "5XX", "*"):
2237
+ http_res_text = utils.stream_to_text(http_res)
2238
+ raise models.SDKError(
2239
+ "API error occurred", http_res.status_code, http_res_text, http_res
2240
+ )
2241
+
2242
+ content_type = http_res.headers.get("Content-Type")
2243
+ http_res_text = utils.stream_to_text(http_res)
2244
+ raise models.SDKError(
2245
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2246
+ http_res.status_code,
2247
+ http_res_text,
2248
+ http_res,
2249
+ )
2250
+
2251
+ async def append_stream_async(
2252
+ self,
2253
+ *,
2254
+ conversation_id: str,
2255
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
2256
+ stream: Optional[bool] = True,
2257
+ store: Optional[bool] = True,
2258
+ handoff_execution: Optional[
2259
+ models.ConversationAppendStreamRequestHandoffExecution
2260
+ ] = "server",
2261
+ completion_args: Optional[
2262
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
2263
+ ] = None,
2264
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2265
+ server_url: Optional[str] = None,
2266
+ timeout_ms: Optional[int] = None,
2267
+ http_headers: Optional[Mapping[str, str]] = None,
2268
+ ) -> eventstreaming.EventStreamAsync[models.ConversationEvents]:
2269
+ r"""Append new entries to an existing conversation.
2270
+
2271
+ Run completion on the history of the conversation and the user entries. Return the new created entries.
2272
+
2273
+ :param conversation_id: ID of the conversation to which we append entries.
2274
+ :param inputs:
2275
+ :param stream:
2276
+ :param store: Whether to store the results into our servers or not.
2277
+ :param handoff_execution:
2278
+ :param completion_args: White-listed arguments from the completion API
2279
+ :param retries: Override the default retry configuration for this method
2280
+ :param server_url: Override the default server URL for this method
2281
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2282
+ :param http_headers: Additional headers to set or replace on requests.
2283
+ """
2284
+ base_url = None
2285
+ url_variables = None
2286
+ if timeout_ms is None:
2287
+ timeout_ms = self.sdk_configuration.timeout_ms
2288
+
2289
+ if server_url is not None:
2290
+ base_url = server_url
2291
+ else:
2292
+ base_url = self._get_url(base_url, url_variables)
2293
+
2294
+ request = models.AgentsAPIV1ConversationsAppendStreamRequest(
2295
+ conversation_id=conversation_id,
2296
+ conversation_append_stream_request=models.ConversationAppendStreamRequest(
2297
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
2298
+ stream=stream,
2299
+ store=store,
2300
+ handoff_execution=handoff_execution,
2301
+ completion_args=utils.get_pydantic_model(
2302
+ completion_args, Optional[models.CompletionArgs]
2303
+ ),
2304
+ ),
2305
+ )
2306
+
2307
+ req = self._build_request_async(
2308
+ method="POST",
2309
+ path="/v1/conversations/{conversation_id}#stream",
2310
+ base_url=base_url,
2311
+ url_variables=url_variables,
2312
+ request=request,
2313
+ request_body_required=True,
2314
+ request_has_path_params=True,
2315
+ request_has_query_params=True,
2316
+ user_agent_header="user-agent",
2317
+ accept_header_value="text/event-stream",
2318
+ http_headers=http_headers,
2319
+ security=self.sdk_configuration.security,
2320
+ get_serialized_body=lambda: utils.serialize_request_body(
2321
+ request.conversation_append_stream_request,
2322
+ False,
2323
+ False,
2324
+ "json",
2325
+ models.ConversationAppendStreamRequest,
2326
+ ),
2327
+ timeout_ms=timeout_ms,
2328
+ )
2329
+
2330
+ if retries == UNSET:
2331
+ if self.sdk_configuration.retry_config is not UNSET:
2332
+ retries = self.sdk_configuration.retry_config
2333
+
2334
+ retry_config = None
2335
+ if isinstance(retries, utils.RetryConfig):
2336
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2337
+
2338
+ http_res = await self.do_request_async(
2339
+ hook_ctx=HookContext(
2340
+ base_url=base_url or "",
2341
+ operation_id="agents_api_v1_conversations_append_stream",
2342
+ oauth2_scopes=[],
2343
+ security_source=get_security_from_env(
2344
+ self.sdk_configuration.security, models.Security
2345
+ ),
2346
+ ),
2347
+ request=req,
2348
+ error_status_codes=["422", "4XX", "5XX"],
2349
+ stream=True,
2350
+ retry_config=retry_config,
2351
+ )
2352
+
2353
+ response_data: Any = None
2354
+ if utils.match_response(http_res, "200", "text/event-stream"):
2355
+ return eventstreaming.EventStreamAsync(
2356
+ http_res,
2357
+ lambda raw: utils.unmarshal_json(raw, models.ConversationEvents),
2358
+ )
2359
+ if utils.match_response(http_res, "422", "application/json"):
2360
+ http_res_text = await utils.stream_to_text_async(http_res)
2361
+ response_data = utils.unmarshal_json(
2362
+ http_res_text, models.HTTPValidationErrorData
2363
+ )
2364
+ raise models.HTTPValidationError(data=response_data)
2365
+ if utils.match_response(http_res, "4XX", "*"):
2366
+ http_res_text = await utils.stream_to_text_async(http_res)
2367
+ raise models.SDKError(
2368
+ "API error occurred", http_res.status_code, http_res_text, http_res
2369
+ )
2370
+ if utils.match_response(http_res, "5XX", "*"):
2371
+ http_res_text = await utils.stream_to_text_async(http_res)
2372
+ raise models.SDKError(
2373
+ "API error occurred", http_res.status_code, http_res_text, http_res
2374
+ )
2375
+
2376
+ content_type = http_res.headers.get("Content-Type")
2377
+ http_res_text = await utils.stream_to_text_async(http_res)
2378
+ raise models.SDKError(
2379
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2380
+ http_res.status_code,
2381
+ http_res_text,
2382
+ http_res,
2383
+ )
2384
+
2385
+ def restart_stream(
2386
+ self,
2387
+ *,
2388
+ conversation_id: str,
2389
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
2390
+ from_entry_id: str,
2391
+ stream: Optional[bool] = True,
2392
+ store: Optional[bool] = True,
2393
+ handoff_execution: Optional[
2394
+ models.ConversationRestartStreamRequestHandoffExecution
2395
+ ] = "server",
2396
+ completion_args: Optional[
2397
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
2398
+ ] = None,
2399
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2400
+ server_url: Optional[str] = None,
2401
+ timeout_ms: Optional[int] = None,
2402
+ http_headers: Optional[Mapping[str, str]] = None,
2403
+ ) -> eventstreaming.EventStream[models.ConversationEvents]:
2404
+ r"""Restart a conversation starting from a given entry.
2405
+
2406
+ Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.
2407
+
2408
+ :param conversation_id:
2409
+ :param inputs:
2410
+ :param from_entry_id:
2411
+ :param stream:
2412
+ :param store: Whether to store the results into our servers or not.
2413
+ :param handoff_execution:
2414
+ :param completion_args: White-listed arguments from the completion API
2415
+ :param retries: Override the default retry configuration for this method
2416
+ :param server_url: Override the default server URL for this method
2417
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2418
+ :param http_headers: Additional headers to set or replace on requests.
2419
+ """
2420
+ base_url = None
2421
+ url_variables = None
2422
+ if timeout_ms is None:
2423
+ timeout_ms = self.sdk_configuration.timeout_ms
2424
+
2425
+ if server_url is not None:
2426
+ base_url = server_url
2427
+ else:
2428
+ base_url = self._get_url(base_url, url_variables)
2429
+
2430
+ request = models.AgentsAPIV1ConversationsRestartStreamRequest(
2431
+ conversation_id=conversation_id,
2432
+ conversation_restart_stream_request=models.ConversationRestartStreamRequest(
2433
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
2434
+ stream=stream,
2435
+ store=store,
2436
+ handoff_execution=handoff_execution,
2437
+ from_entry_id=from_entry_id,
2438
+ completion_args=utils.get_pydantic_model(
2439
+ completion_args, Optional[models.CompletionArgs]
2440
+ ),
2441
+ ),
2442
+ )
2443
+
2444
+ req = self._build_request(
2445
+ method="POST",
2446
+ path="/v1/conversations/{conversation_id}/restart#stream",
2447
+ base_url=base_url,
2448
+ url_variables=url_variables,
2449
+ request=request,
2450
+ request_body_required=True,
2451
+ request_has_path_params=True,
2452
+ request_has_query_params=True,
2453
+ user_agent_header="user-agent",
2454
+ accept_header_value="text/event-stream",
2455
+ http_headers=http_headers,
2456
+ security=self.sdk_configuration.security,
2457
+ get_serialized_body=lambda: utils.serialize_request_body(
2458
+ request.conversation_restart_stream_request,
2459
+ False,
2460
+ False,
2461
+ "json",
2462
+ models.ConversationRestartStreamRequest,
2463
+ ),
2464
+ timeout_ms=timeout_ms,
2465
+ )
2466
+
2467
+ if retries == UNSET:
2468
+ if self.sdk_configuration.retry_config is not UNSET:
2469
+ retries = self.sdk_configuration.retry_config
2470
+
2471
+ retry_config = None
2472
+ if isinstance(retries, utils.RetryConfig):
2473
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2474
+
2475
+ http_res = self.do_request(
2476
+ hook_ctx=HookContext(
2477
+ base_url=base_url or "",
2478
+ operation_id="agents_api_v1_conversations_restart_stream",
2479
+ oauth2_scopes=[],
2480
+ security_source=get_security_from_env(
2481
+ self.sdk_configuration.security, models.Security
2482
+ ),
2483
+ ),
2484
+ request=req,
2485
+ error_status_codes=["422", "4XX", "5XX"],
2486
+ stream=True,
2487
+ retry_config=retry_config,
2488
+ )
2489
+
2490
+ response_data: Any = None
2491
+ if utils.match_response(http_res, "200", "text/event-stream"):
2492
+ return eventstreaming.EventStream(
2493
+ http_res,
2494
+ lambda raw: utils.unmarshal_json(raw, models.ConversationEvents),
2495
+ )
2496
+ if utils.match_response(http_res, "422", "application/json"):
2497
+ http_res_text = utils.stream_to_text(http_res)
2498
+ response_data = utils.unmarshal_json(
2499
+ http_res_text, models.HTTPValidationErrorData
2500
+ )
2501
+ raise models.HTTPValidationError(data=response_data)
2502
+ if utils.match_response(http_res, "4XX", "*"):
2503
+ http_res_text = utils.stream_to_text(http_res)
2504
+ raise models.SDKError(
2505
+ "API error occurred", http_res.status_code, http_res_text, http_res
2506
+ )
2507
+ if utils.match_response(http_res, "5XX", "*"):
2508
+ http_res_text = utils.stream_to_text(http_res)
2509
+ raise models.SDKError(
2510
+ "API error occurred", http_res.status_code, http_res_text, http_res
2511
+ )
2512
+
2513
+ content_type = http_res.headers.get("Content-Type")
2514
+ http_res_text = utils.stream_to_text(http_res)
2515
+ raise models.SDKError(
2516
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2517
+ http_res.status_code,
2518
+ http_res_text,
2519
+ http_res,
2520
+ )
2521
+
2522
+ async def restart_stream_async(
2523
+ self,
2524
+ *,
2525
+ conversation_id: str,
2526
+ inputs: Union[models.ConversationInputs, models.ConversationInputsTypedDict],
2527
+ from_entry_id: str,
2528
+ stream: Optional[bool] = True,
2529
+ store: Optional[bool] = True,
2530
+ handoff_execution: Optional[
2531
+ models.ConversationRestartStreamRequestHandoffExecution
2532
+ ] = "server",
2533
+ completion_args: Optional[
2534
+ Union[models.CompletionArgs, models.CompletionArgsTypedDict]
2535
+ ] = None,
2536
+ retries: OptionalNullable[utils.RetryConfig] = UNSET,
2537
+ server_url: Optional[str] = None,
2538
+ timeout_ms: Optional[int] = None,
2539
+ http_headers: Optional[Mapping[str, str]] = None,
2540
+ ) -> eventstreaming.EventStreamAsync[models.ConversationEvents]:
2541
+ r"""Restart a conversation starting from a given entry.
2542
+
2543
+ Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.
2544
+
2545
+ :param conversation_id:
2546
+ :param inputs:
2547
+ :param from_entry_id:
2548
+ :param stream:
2549
+ :param store: Whether to store the results into our servers or not.
2550
+ :param handoff_execution:
2551
+ :param completion_args: White-listed arguments from the completion API
2552
+ :param retries: Override the default retry configuration for this method
2553
+ :param server_url: Override the default server URL for this method
2554
+ :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
2555
+ :param http_headers: Additional headers to set or replace on requests.
2556
+ """
2557
+ base_url = None
2558
+ url_variables = None
2559
+ if timeout_ms is None:
2560
+ timeout_ms = self.sdk_configuration.timeout_ms
2561
+
2562
+ if server_url is not None:
2563
+ base_url = server_url
2564
+ else:
2565
+ base_url = self._get_url(base_url, url_variables)
2566
+
2567
+ request = models.AgentsAPIV1ConversationsRestartStreamRequest(
2568
+ conversation_id=conversation_id,
2569
+ conversation_restart_stream_request=models.ConversationRestartStreamRequest(
2570
+ inputs=utils.get_pydantic_model(inputs, models.ConversationInputs),
2571
+ stream=stream,
2572
+ store=store,
2573
+ handoff_execution=handoff_execution,
2574
+ from_entry_id=from_entry_id,
2575
+ completion_args=utils.get_pydantic_model(
2576
+ completion_args, Optional[models.CompletionArgs]
2577
+ ),
2578
+ ),
2579
+ )
2580
+
2581
+ req = self._build_request_async(
2582
+ method="POST",
2583
+ path="/v1/conversations/{conversation_id}/restart#stream",
2584
+ base_url=base_url,
2585
+ url_variables=url_variables,
2586
+ request=request,
2587
+ request_body_required=True,
2588
+ request_has_path_params=True,
2589
+ request_has_query_params=True,
2590
+ user_agent_header="user-agent",
2591
+ accept_header_value="text/event-stream",
2592
+ http_headers=http_headers,
2593
+ security=self.sdk_configuration.security,
2594
+ get_serialized_body=lambda: utils.serialize_request_body(
2595
+ request.conversation_restart_stream_request,
2596
+ False,
2597
+ False,
2598
+ "json",
2599
+ models.ConversationRestartStreamRequest,
2600
+ ),
2601
+ timeout_ms=timeout_ms,
2602
+ )
2603
+
2604
+ if retries == UNSET:
2605
+ if self.sdk_configuration.retry_config is not UNSET:
2606
+ retries = self.sdk_configuration.retry_config
2607
+
2608
+ retry_config = None
2609
+ if isinstance(retries, utils.RetryConfig):
2610
+ retry_config = (retries, ["429", "500", "502", "503", "504"])
2611
+
2612
+ http_res = await self.do_request_async(
2613
+ hook_ctx=HookContext(
2614
+ base_url=base_url or "",
2615
+ operation_id="agents_api_v1_conversations_restart_stream",
2616
+ oauth2_scopes=[],
2617
+ security_source=get_security_from_env(
2618
+ self.sdk_configuration.security, models.Security
2619
+ ),
2620
+ ),
2621
+ request=req,
2622
+ error_status_codes=["422", "4XX", "5XX"],
2623
+ stream=True,
2624
+ retry_config=retry_config,
2625
+ )
2626
+
2627
+ response_data: Any = None
2628
+ if utils.match_response(http_res, "200", "text/event-stream"):
2629
+ return eventstreaming.EventStreamAsync(
2630
+ http_res,
2631
+ lambda raw: utils.unmarshal_json(raw, models.ConversationEvents),
2632
+ )
2633
+ if utils.match_response(http_res, "422", "application/json"):
2634
+ http_res_text = await utils.stream_to_text_async(http_res)
2635
+ response_data = utils.unmarshal_json(
2636
+ http_res_text, models.HTTPValidationErrorData
2637
+ )
2638
+ raise models.HTTPValidationError(data=response_data)
2639
+ if utils.match_response(http_res, "4XX", "*"):
2640
+ http_res_text = await utils.stream_to_text_async(http_res)
2641
+ raise models.SDKError(
2642
+ "API error occurred", http_res.status_code, http_res_text, http_res
2643
+ )
2644
+ if utils.match_response(http_res, "5XX", "*"):
2645
+ http_res_text = await utils.stream_to_text_async(http_res)
2646
+ raise models.SDKError(
2647
+ "API error occurred", http_res.status_code, http_res_text, http_res
2648
+ )
2649
+
2650
+ content_type = http_res.headers.get("Content-Type")
2651
+ http_res_text = await utils.stream_to_text_async(http_res)
2652
+ raise models.SDKError(
2653
+ f"Unexpected response received (code: {http_res.status_code}, type: {content_type})",
2654
+ http_res.status_code,
2655
+ http_res_text,
2656
+ http_res,
2657
+ )