|
15 | 15 | AgentThinkAgentManagementResponse as AgentThinkResponse, |
16 | 16 | ) |
17 | 17 | from ..agents.types.get_turns_agents_response import GetTurnsAgentsResponse |
18 | | -from ..agents.types.start_agents_request_properties import StartAgentsRequestProperties |
19 | | -from .agent import Agent, GetTurnsOptions, SayOptions, ThinkOptions |
| 18 | +from .agent import Agent, GetTurnsOptions, SayOptions, ThinkOptions, _start_properties_from_mapping |
20 | 19 | from .avatar_types import ( |
21 | 20 | is_akool_avatar, |
22 | 21 | is_anam_avatar, |
@@ -350,6 +349,44 @@ def _build_start_properties( |
350 | 349 |
|
351 | 350 | return properties |
352 | 351 |
|
| 352 | + @staticmethod |
| 353 | + def _request_properties_for_start( |
| 354 | + resolved_properties: typing.Dict[str, typing.Any], |
| 355 | + *, |
| 356 | + resolved_preset: typing.Optional[str], |
| 357 | + pipeline_id: typing.Optional[str], |
| 358 | + ) -> typing.Any: |
| 359 | + try: |
| 360 | + return _start_properties_from_mapping(resolved_properties) |
| 361 | + except Exception as exc: |
| 362 | + if pipeline_id: |
| 363 | + return resolved_properties |
| 364 | + if resolved_preset: |
| 365 | + preset_categories = { |
| 366 | + category |
| 367 | + for item in normalize_preset_input(resolved_preset).split(",") |
| 368 | + for category in [get_preset_category(item)] |
| 369 | + if category is not None |
| 370 | + } |
| 371 | + error_categories = _AgentSessionBase._validation_error_categories(exc) |
| 372 | + if error_categories and error_categories.issubset(preset_categories): |
| 373 | + return resolved_properties |
| 374 | + raise |
| 375 | + |
| 376 | + @staticmethod |
| 377 | + def _validation_error_categories(exc: Exception) -> typing.Set[str]: |
| 378 | + errors = getattr(exc, "errors", None) |
| 379 | + if not callable(errors): |
| 380 | + return set() |
| 381 | + categories: typing.Set[str] = set() |
| 382 | + for error in errors(): |
| 383 | + loc = error.get("loc") if isinstance(error, dict) else None |
| 384 | + if isinstance(loc, tuple) and loc: |
| 385 | + field = loc[0] |
| 386 | + if field in {"asr", "llm", "tts"}: |
| 387 | + categories.add(typing.cast(str, field)) |
| 388 | + return categories |
| 389 | + |
353 | 390 | def _vendor_validation_categories( |
354 | 391 | self, |
355 | 392 | pipeline_id: typing.Optional[str], |
@@ -514,10 +551,11 @@ def start(self) -> str: |
514 | 551 | "properties": resolved_properties, |
515 | 552 | }) |
516 | 553 |
|
517 | | - try: |
518 | | - request_properties: typing.Any = StartAgentsRequestProperties(**resolved_properties) |
519 | | - except Exception: |
520 | | - request_properties = resolved_properties |
| 554 | + request_properties = self._request_properties_for_start( |
| 555 | + resolved_properties, |
| 556 | + resolved_preset=resolved_preset, |
| 557 | + pipeline_id=pipeline_id, |
| 558 | + ) |
521 | 559 |
|
522 | 560 | response = self._client.agents.start( |
523 | 561 | self._app_id, |
@@ -841,10 +879,11 @@ async def start(self) -> str: |
841 | 879 | "properties": resolved_properties, |
842 | 880 | }) |
843 | 881 |
|
844 | | - try: |
845 | | - request_properties: typing.Any = StartAgentsRequestProperties(**resolved_properties) |
846 | | - except Exception: |
847 | | - request_properties = resolved_properties |
| 882 | + request_properties = self._request_properties_for_start( |
| 883 | + resolved_properties, |
| 884 | + resolved_preset=resolved_preset, |
| 885 | + pipeline_id=pipeline_id, |
| 886 | + ) |
848 | 887 |
|
849 | 888 | response = await self._client.agents.start( |
850 | 889 | self._app_id, |
|
0 commit comments