diff --git a/client-python/.openapi-generator/FILES b/client-python/.openapi-generator/FILES index 1546e01..ec448d4 100644 --- a/client-python/.openapi-generator/FILES +++ b/client-python/.openapi-generator/FILES @@ -29,6 +29,8 @@ ap_client/models/message_any_block.py ap_client/models/message_text_block.py ap_client/models/run.py ap_client/models/run_create.py +ap_client/models/run_resume.py +ap_client/models/run_resume_stream.py ap_client/models/run_search_request.py ap_client/models/run_status.py ap_client/models/run_stream.py @@ -40,6 +42,7 @@ ap_client/models/store_list_namespaces_request.py ap_client/models/store_put_request.py ap_client/models/store_search_request.py ap_client/models/stream_mode.py +ap_client/models/stream_mode1.py ap_client/models/thread.py ap_client/models/thread_checkpoint.py ap_client/models/thread_create.py @@ -65,6 +68,8 @@ docs/MessageAnyBlock.md docs/MessageTextBlock.md docs/Run.md docs/RunCreate.md +docs/RunResume.md +docs/RunResumeStream.md docs/RunSearchRequest.md docs/RunStatus.md docs/RunStream.md @@ -78,6 +83,7 @@ docs/StoreListNamespacesRequest.md docs/StorePutRequest.md docs/StoreSearchRequest.md docs/StreamMode.md +docs/StreamMode1.md docs/Thread.md docs/ThreadCheckpoint.md docs/ThreadCreate.md @@ -93,4 +99,7 @@ setup.cfg setup.py test-requirements.txt test/__init__.py +test/test_run_resume.py +test/test_run_resume_stream.py +test/test_stream_mode1.py tox.ini diff --git a/client-python/README.md b/client-python/README.md index b7ab24a..1fd431e 100644 --- a/client-python/README.md +++ b/client-python/README.md @@ -97,6 +97,9 @@ Class | Method | HTTP request | Description *BackgroundRunsApi* | [**wait_run**](docs/BackgroundRunsApi.md#wait_run) | **GET** /runs/{run_id}/wait | Wait for Run output *RunsApi* | [**create_and_stream_run**](docs/RunsApi.md#create_and_stream_run) | **POST** /runs/stream | Create Run, Stream Output *RunsApi* | [**create_and_wait_run**](docs/RunsApi.md#create_and_wait_run) | **POST** /runs/wait | Create Run, Wait for Output +*RunsApi* | [**resume_and_stream_run**](docs/RunsApi.md#resume_and_stream_run) | **PATCH** /runs/resume/stream | Resume Run and Stream Output +*RunsApi* | [**resume_and_wait_run**](docs/RunsApi.md#resume_and_wait_run) | **PATCH** /runs/resume/wait | Resume Run and Wait +*RunsApi* | [**resume_run**](docs/RunsApi.md#resume_run) | **PATCH** /runs/resume | Resume Run (start execution from interrupted thread) *StoreApi* | [**delete_item**](docs/StoreApi.md#delete_item) | **DELETE** /store/items | Delete Store Item *StoreApi* | [**get_item**](docs/StoreApi.md#get_item) | **GET** /store/items | Get Store Item *StoreApi* | [**list_namespaces**](docs/StoreApi.md#list_namespaces) | **POST** /store/namespaces | List namespaces @@ -127,6 +130,8 @@ Class | Method | HTTP request | Description - [MessageTextBlock](docs/MessageTextBlock.md) - [Run](docs/Run.md) - [RunCreate](docs/RunCreate.md) + - [RunResume](docs/RunResume.md) + - [RunResumeStream](docs/RunResumeStream.md) - [RunSearchRequest](docs/RunSearchRequest.md) - [RunStatus](docs/RunStatus.md) - [RunStream](docs/RunStream.md) @@ -138,6 +143,7 @@ Class | Method | HTTP request | Description - [StorePutRequest](docs/StorePutRequest.md) - [StoreSearchRequest](docs/StoreSearchRequest.md) - [StreamMode](docs/StreamMode.md) + - [StreamMode1](docs/StreamMode1.md) - [Thread](docs/Thread.md) - [ThreadCheckpoint](docs/ThreadCheckpoint.md) - [ThreadCreate](docs/ThreadCreate.md) diff --git a/client-python/ap_client/__init__.py b/client-python/ap_client/__init__.py index 531ecb7..14b2fed 100644 --- a/client-python/ap_client/__init__.py +++ b/client-python/ap_client/__init__.py @@ -48,6 +48,8 @@ from ap_client.models.message_text_block import MessageTextBlock from ap_client.models.run import Run from ap_client.models.run_create import RunCreate +from ap_client.models.run_resume import RunResume +from ap_client.models.run_resume_stream import RunResumeStream from ap_client.models.run_search_request import RunSearchRequest from ap_client.models.run_status import RunStatus from ap_client.models.run_stream import RunStream @@ -59,6 +61,7 @@ from ap_client.models.store_put_request import StorePutRequest from ap_client.models.store_search_request import StoreSearchRequest from ap_client.models.stream_mode import StreamMode +from ap_client.models.stream_mode1 import StreamMode1 from ap_client.models.thread import Thread from ap_client.models.thread_checkpoint import ThreadCheckpoint from ap_client.models.thread_create import ThreadCreate diff --git a/client-python/ap_client/api/runs_api.py b/client-python/ap_client/api/runs_api.py index 5e44344..b1dd977 100644 --- a/client-python/ap_client/api/runs_api.py +++ b/client-python/ap_client/api/runs_api.py @@ -15,7 +15,10 @@ from typing import Any, Dict, List, Optional, Tuple, Union from typing_extensions import Annotated +from ap_client.models.run import Run from ap_client.models.run_create import RunCreate +from ap_client.models.run_resume import RunResume +from ap_client.models.run_resume_stream import RunResumeStream from ap_client.models.run_stream import RunStream from ap_client.models.run_wait_response import RunWaitResponse @@ -555,3 +558,783 @@ def _create_and_wait_run_serialize( _host=_host, _request_auth=_request_auth, ) + + @validate_call + def resume_and_stream_run( + self, + run_resume_stream: RunResumeStream, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> str: + """Resume Run and Stream Output + + Resume a thread that is in an interrupted (suspended) state and stream its output. Convenience equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/stream. + + :param run_resume_stream: (required) + :type run_resume_stream: RunResumeStream + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_and_stream_run_serialize( + run_resume_stream=run_resume_stream, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "str", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + def resume_and_stream_run_with_http_info( + self, + run_resume_stream: RunResumeStream, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[str]: + """Resume Run and Stream Output + + Resume a thread that is in an interrupted (suspended) state and stream its output. Convenience equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/stream. + + :param run_resume_stream: (required) + :type run_resume_stream: RunResumeStream + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_and_stream_run_serialize( + run_resume_stream=run_resume_stream, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "str", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + def resume_and_stream_run_without_preload_content( + self, + run_resume_stream: RunResumeStream, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """Resume Run and Stream Output + + Resume a thread that is in an interrupted (suspended) state and stream its output. Convenience equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/stream. + + :param run_resume_stream: (required) + :type run_resume_stream: RunResumeStream + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_and_stream_run_serialize( + run_resume_stream=run_resume_stream, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "str", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + return response_data.response + + def _resume_and_stream_run_serialize( + self, + run_resume_stream, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + _host = None + + _collection_formats: Dict[str, str] = {} + + _path_params: Dict[str, str] = {} + _query_params: List[Tuple[str, str]] = [] + _header_params: Dict[str, Optional[str]] = _headers or {} + _form_params: List[Tuple[str, str]] = [] + _files: Dict[ + str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]] + ] = {} + _body_params: Optional[bytes] = None + + # process the path parameters + # process the query parameters + # process the header parameters + # process the form parameters + # process the body parameter + if run_resume_stream is not None: + _body_params = run_resume_stream + + # set the HTTP header `Accept` + if "Accept" not in _header_params: + _header_params["Accept"] = self.api_client.select_header_accept( + ["text/event-stream", "application/json"] + ) + + # set the HTTP header `Content-Type` + if _content_type: + _header_params["Content-Type"] = _content_type + else: + _default_content_type = self.api_client.select_header_content_type( + ["application/json"] + ) + if _default_content_type is not None: + _header_params["Content-Type"] = _default_content_type + + # authentication setting + _auth_settings: List[str] = [] + + return self.api_client.param_serialize( + method="PATCH", + resource_path="/runs/resume/stream", + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth, + ) + + @validate_call + def resume_and_wait_run( + self, + run_resume: RunResume, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RunWaitResponse: + """Resume Run and Wait + + Resume a thread that is in an interrupted state and wait for its completion. Equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/wait. + + :param run_resume: (required) + :type run_resume: RunResume + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_and_wait_run_serialize( + run_resume=run_resume, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "RunWaitResponse", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + def resume_and_wait_run_with_http_info( + self, + run_resume: RunResume, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[RunWaitResponse]: + """Resume Run and Wait + + Resume a thread that is in an interrupted state and wait for its completion. Equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/wait. + + :param run_resume: (required) + :type run_resume: RunResume + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_and_wait_run_serialize( + run_resume=run_resume, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "RunWaitResponse", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + def resume_and_wait_run_without_preload_content( + self, + run_resume: RunResume, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """Resume Run and Wait + + Resume a thread that is in an interrupted state and wait for its completion. Equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/wait. + + :param run_resume: (required) + :type run_resume: RunResume + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_and_wait_run_serialize( + run_resume=run_resume, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "RunWaitResponse", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + return response_data.response + + def _resume_and_wait_run_serialize( + self, + run_resume, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + _host = None + + _collection_formats: Dict[str, str] = {} + + _path_params: Dict[str, str] = {} + _query_params: List[Tuple[str, str]] = [] + _header_params: Dict[str, Optional[str]] = _headers or {} + _form_params: List[Tuple[str, str]] = [] + _files: Dict[ + str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]] + ] = {} + _body_params: Optional[bytes] = None + + # process the path parameters + # process the query parameters + # process the header parameters + # process the form parameters + # process the body parameter + if run_resume is not None: + _body_params = run_resume + + # set the HTTP header `Accept` + if "Accept" not in _header_params: + _header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) + + # set the HTTP header `Content-Type` + if _content_type: + _header_params["Content-Type"] = _content_type + else: + _default_content_type = self.api_client.select_header_content_type( + ["application/json"] + ) + if _default_content_type is not None: + _header_params["Content-Type"] = _default_content_type + + # authentication setting + _auth_settings: List[str] = [] + + return self.api_client.param_serialize( + method="PATCH", + resource_path="/runs/resume/wait", + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth, + ) + + @validate_call + def resume_run( + self, + run_resume: RunResume, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> Run: + """Resume Run (start execution from interrupted thread) + + Resume a thread that is in an interrupted (suspended) state. Thread ID is required. Returns the updated Run object (typically queued or in_progress). + + :param run_resume: (required) + :type run_resume: RunResume + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_run_serialize( + run_resume=run_resume, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "Run", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ).data + + @validate_call + def resume_run_with_http_info( + self, + run_resume: RunResume, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> ApiResponse[Run]: + """Resume Run (start execution from interrupted thread) + + Resume a thread that is in an interrupted (suspended) state. Thread ID is required. Returns the updated Run object (typically queued or in_progress). + + :param run_resume: (required) + :type run_resume: RunResume + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_run_serialize( + run_resume=run_resume, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "Run", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + response_data.read() + return self.api_client.response_deserialize( + response_data=response_data, + response_types_map=_response_types_map, + ) + + @validate_call + def resume_run_without_preload_content( + self, + run_resume: RunResume, + _request_timeout: Union[ + None, + Annotated[StrictFloat, Field(gt=0)], + Tuple[ + Annotated[StrictFloat, Field(gt=0)], Annotated[StrictFloat, Field(gt=0)] + ], + ] = None, + _request_auth: Optional[Dict[StrictStr, Any]] = None, + _content_type: Optional[StrictStr] = None, + _headers: Optional[Dict[StrictStr, Any]] = None, + _host_index: Annotated[StrictInt, Field(ge=0, le=0)] = 0, + ) -> RESTResponseType: + """Resume Run (start execution from interrupted thread) + + Resume a thread that is in an interrupted (suspended) state. Thread ID is required. Returns the updated Run object (typically queued or in_progress). + + :param run_resume: (required) + :type run_resume: RunResume + :param _request_timeout: timeout setting for this request. If one + number provided, it will be total request + timeout. It can also be a pair (tuple) of + (connection, read) timeouts. + :type _request_timeout: int, tuple(int, int), optional + :param _request_auth: set to override the auth_settings for an a single + request; this effectively ignores the + authentication in the spec for a single request. + :type _request_auth: dict, optional + :param _content_type: force content-type for the request. + :type _content_type: str, Optional + :param _headers: set to override the headers for a single + request; this effectively ignores the headers + in the spec for a single request. + :type _headers: dict, optional + :param _host_index: set to override the host_index for a single + request; this effectively ignores the host_index + in the spec for a single request. + :type _host_index: int, optional + :return: Returns the result object. + """ # noqa: E501 + + _param = self._resume_run_serialize( + run_resume=run_resume, + _request_auth=_request_auth, + _content_type=_content_type, + _headers=_headers, + _host_index=_host_index, + ) + + _response_types_map: Dict[str, Optional[str]] = { + "200": "Run", + "404": "ErrorResponse", + "409": "ErrorResponse", + "422": "ErrorResponse", + } + response_data = self.api_client.call_api( + *_param, _request_timeout=_request_timeout + ) + return response_data.response + + def _resume_run_serialize( + self, + run_resume, + _request_auth, + _content_type, + _headers, + _host_index, + ) -> RequestSerialized: + _host = None + + _collection_formats: Dict[str, str] = {} + + _path_params: Dict[str, str] = {} + _query_params: List[Tuple[str, str]] = [] + _header_params: Dict[str, Optional[str]] = _headers or {} + _form_params: List[Tuple[str, str]] = [] + _files: Dict[ + str, Union[str, bytes, List[str], List[bytes], List[Tuple[str, bytes]]] + ] = {} + _body_params: Optional[bytes] = None + + # process the path parameters + # process the query parameters + # process the header parameters + # process the form parameters + # process the body parameter + if run_resume is not None: + _body_params = run_resume + + # set the HTTP header `Accept` + if "Accept" not in _header_params: + _header_params["Accept"] = self.api_client.select_header_accept( + ["application/json"] + ) + + # set the HTTP header `Content-Type` + if _content_type: + _header_params["Content-Type"] = _content_type + else: + _default_content_type = self.api_client.select_header_content_type( + ["application/json"] + ) + if _default_content_type is not None: + _header_params["Content-Type"] = _default_content_type + + # authentication setting + _auth_settings: List[str] = [] + + return self.api_client.param_serialize( + method="PATCH", + resource_path="/runs/resume", + path_params=_path_params, + query_params=_query_params, + header_params=_header_params, + body=_body_params, + post_params=_form_params, + files=_files, + auth_settings=_auth_settings, + collection_formats=_collection_formats, + _host=_host, + _request_auth=_request_auth, + ) diff --git a/client-python/ap_client/models/__init__.py b/client-python/ap_client/models/__init__.py index b3155c0..26f7dff 100644 --- a/client-python/ap_client/models/__init__.py +++ b/client-python/ap_client/models/__init__.py @@ -27,6 +27,8 @@ from ap_client.models.message_text_block import MessageTextBlock from ap_client.models.run import Run from ap_client.models.run_create import RunCreate +from ap_client.models.run_resume import RunResume +from ap_client.models.run_resume_stream import RunResumeStream from ap_client.models.run_search_request import RunSearchRequest from ap_client.models.run_status import RunStatus from ap_client.models.run_stream import RunStream @@ -38,6 +40,7 @@ from ap_client.models.store_put_request import StorePutRequest from ap_client.models.store_search_request import StoreSearchRequest from ap_client.models.stream_mode import StreamMode +from ap_client.models.stream_mode1 import StreamMode1 from ap_client.models.thread import Thread from ap_client.models.thread_checkpoint import ThreadCheckpoint from ap_client.models.thread_create import ThreadCreate diff --git a/client-python/ap_client/models/run.py b/client-python/ap_client/models/run.py index 5e26ca4..9dfa4fb 100644 --- a/client-python/ap_client/models/run.py +++ b/client-python/ap_client/models/run.py @@ -24,7 +24,7 @@ from ap_client.models.input import Input from ap_client.models.message import Message from ap_client.models.run_status import RunStatus -from ap_client.models.stream_mode import StreamMode +from ap_client.models.stream_mode1 import StreamMode1 from typing import Set from typing_extensions import Self @@ -65,7 +65,7 @@ class Run(BaseModel): default="reject", description="How to handle missing thread. Must be either 'reject' (raise error if missing), or 'create' (create new thread).", ) - stream_mode: Optional[StreamMode] = None + stream_mode: Optional[StreamMode1] = None run_id: StrictStr = Field(description="The ID of the run.") created_at: datetime = Field(description="The time the run was created.") updated_at: datetime = Field(description="The last time the run was updated.") @@ -209,7 +209,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "if_not_exists": obj.get("if_not_exists") if obj.get("if_not_exists") is not None else "reject", - "stream_mode": StreamMode.from_dict(obj["stream_mode"]) + "stream_mode": StreamMode1.from_dict(obj["stream_mode"]) if obj.get("stream_mode") is not None else None, "run_id": obj.get("run_id"), diff --git a/client-python/ap_client/models/run_resume.py b/client-python/ap_client/models/run_resume.py new file mode 100644 index 0000000..d03cbe2 --- /dev/null +++ b/client-python/ap_client/models/run_resume.py @@ -0,0 +1,179 @@ +# coding: utf-8 + +""" +Agent Protocol + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +The version of the OpenAPI document: 0.1.6 +Generated by OpenAPI Generator (https://openapi-generator.tech) + +Do not edit the class manually. +""" # noqa: E501 + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from typing import Any, ClassVar, Dict, List, Optional +from typing_extensions import Annotated +from ap_client.models.config import Config +from ap_client.models.input import Input +from ap_client.models.message import Message +from typing import Set +from typing_extensions import Self + + +class RunResume(BaseModel): + """ + Payload for resuming a run from an interrupted thread. Requires an existing thread; does not create new threads. + """ # noqa: E501 + + thread_id: StrictStr = Field( + description="The ID of the thread to resume. Must refer to an existing thread." + ) + agent_id: Optional[StrictStr] = Field( + default=None, + description="The agent ID to run. If not provided will use the agent associated with this thread (or the default agent for this service). 'agent_id' is ignored unless Agents stage is implemented.", + ) + input: Optional[Input] = None + messages: Optional[List[Message]] = Field( + default=None, description="The messages to pass an input to the agent." + ) + metadata: Optional[Dict[str, Any]] = Field( + default=None, description="Metadata to assign to the run." + ) + config: Optional[Config] = None + webhook: Optional[ + Annotated[str, Field(min_length=1, strict=True, max_length=65536)] + ] = Field(default=None, description="Webhook to call after run finishes.") + on_completion: Optional[StrictStr] = Field( + default=None, + description="Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'keep'.", + ) + on_disconnect: Optional[StrictStr] = Field( + default="cancel", + description="The disconnect mode to use. Must be one of 'cancel' or 'continue'.", + ) + __properties: ClassVar[List[str]] = [ + "thread_id", + "agent_id", + "input", + "messages", + "metadata", + "config", + "webhook", + "on_completion", + "on_disconnect", + ] + + @field_validator("on_completion") + def on_completion_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(["keep", "delete"]): + raise ValueError("must be one of enum values ('keep', 'delete')") + return value + + @field_validator("on_disconnect") + def on_disconnect_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(["cancel", "continue"]): + raise ValueError("must be one of enum values ('cancel', 'continue')") + return value + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of RunResume from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of input + if self.input: + _dict["input"] = self.input.to_dict() + # override the default output from pydantic by calling `to_dict()` of each item in messages (list) + _items = [] + if self.messages: + for _item_messages in self.messages: + if _item_messages: + _items.append(_item_messages.to_dict()) + _dict["messages"] = _items + # override the default output from pydantic by calling `to_dict()` of config + if self.config: + _dict["config"] = self.config.to_dict() + # set to None if input (nullable) is None + # and model_fields_set contains the field + if self.input is None and "input" in self.model_fields_set: + _dict["input"] = None + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of RunResume from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate( + { + "thread_id": obj.get("thread_id"), + "agent_id": obj.get("agent_id"), + "input": Input.from_dict(obj["input"]) + if obj.get("input") is not None + else None, + "messages": [Message.from_dict(_item) for _item in obj["messages"]] + if obj.get("messages") is not None + else None, + "metadata": obj.get("metadata"), + "config": Config.from_dict(obj["config"]) + if obj.get("config") is not None + else None, + "webhook": obj.get("webhook"), + "on_completion": obj.get("on_completion"), + "on_disconnect": obj.get("on_disconnect") + if obj.get("on_disconnect") is not None + else "cancel", + } + ) + return _obj diff --git a/client-python/ap_client/models/run_resume_stream.py b/client-python/ap_client/models/run_resume_stream.py new file mode 100644 index 0000000..11f6b14 --- /dev/null +++ b/client-python/ap_client/models/run_resume_stream.py @@ -0,0 +1,188 @@ +# coding: utf-8 + +""" +Agent Protocol + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +The version of the OpenAPI document: 0.1.6 +Generated by OpenAPI Generator (https://openapi-generator.tech) + +Do not edit the class manually. +""" # noqa: E501 + +from __future__ import annotations +import pprint +import re # noqa: F401 +import json + +from pydantic import BaseModel, ConfigDict, Field, StrictStr, field_validator +from typing import Any, ClassVar, Dict, List, Optional +from typing_extensions import Annotated +from ap_client.models.config import Config +from ap_client.models.input import Input +from ap_client.models.message import Message +from ap_client.models.stream_mode import StreamMode +from typing import Set +from typing_extensions import Self + + +class RunResumeStream(BaseModel): + """ + Payload for resuming a run and streaming the output. + """ # noqa: E501 + + thread_id: StrictStr = Field( + description="The ID of the thread to resume. Must refer to an existing thread." + ) + agent_id: Optional[StrictStr] = Field( + default=None, + description="The agent ID to run. If not provided will use the agent associated with this thread (or the default agent for this service). 'agent_id' is ignored unless Agents stage is implemented.", + ) + input: Optional[Input] = None + messages: Optional[List[Message]] = Field( + default=None, description="The messages to pass an input to the agent." + ) + metadata: Optional[Dict[str, Any]] = Field( + default=None, description="Metadata to assign to the run." + ) + config: Optional[Config] = None + webhook: Optional[ + Annotated[str, Field(min_length=1, strict=True, max_length=65536)] + ] = Field(default=None, description="Webhook to call after run finishes.") + on_completion: Optional[StrictStr] = Field( + default=None, + description="Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'keep'.", + ) + on_disconnect: Optional[StrictStr] = Field( + default="cancel", + description="The disconnect mode to use. Must be one of 'cancel' or 'continue'.", + ) + stream_mode: Optional[StreamMode] = None + __properties: ClassVar[List[str]] = [ + "thread_id", + "agent_id", + "input", + "messages", + "metadata", + "config", + "webhook", + "on_completion", + "on_disconnect", + "stream_mode", + ] + + @field_validator("on_completion") + def on_completion_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(["keep", "delete"]): + raise ValueError("must be one of enum values ('keep', 'delete')") + return value + + @field_validator("on_disconnect") + def on_disconnect_validate_enum(cls, value): + """Validates the enum""" + if value is None: + return value + + if value not in set(["cancel", "continue"]): + raise ValueError("must be one of enum values ('cancel', 'continue')") + return value + + model_config = ConfigDict( + populate_by_name=True, + validate_assignment=True, + protected_namespaces=(), + ) + + def to_str(self) -> str: + """Returns the string representation of the model using alias""" + return pprint.pformat(self.model_dump(by_alias=True)) + + def to_json(self) -> str: + """Returns the JSON representation of the model using alias""" + # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead + return json.dumps(self.to_dict()) + + @classmethod + def from_json(cls, json_str: str) -> Optional[Self]: + """Create an instance of RunResumeStream from a JSON string""" + return cls.from_dict(json.loads(json_str)) + + def to_dict(self) -> Dict[str, Any]: + """Return the dictionary representation of the model using alias. + + This has the following differences from calling pydantic's + `self.model_dump(by_alias=True)`: + + * `None` is only added to the output dict for nullable fields that + were set at model initialization. Other fields with value `None` + are ignored. + """ + excluded_fields: Set[str] = set([]) + + _dict = self.model_dump( + by_alias=True, + exclude=excluded_fields, + exclude_none=True, + ) + # override the default output from pydantic by calling `to_dict()` of input + if self.input: + _dict["input"] = self.input.to_dict() + # override the default output from pydantic by calling `to_dict()` of each item in messages (list) + _items = [] + if self.messages: + for _item_messages in self.messages: + if _item_messages: + _items.append(_item_messages.to_dict()) + _dict["messages"] = _items + # override the default output from pydantic by calling `to_dict()` of config + if self.config: + _dict["config"] = self.config.to_dict() + # override the default output from pydantic by calling `to_dict()` of stream_mode + if self.stream_mode: + _dict["stream_mode"] = self.stream_mode.to_dict() + # set to None if input (nullable) is None + # and model_fields_set contains the field + if self.input is None and "input" in self.model_fields_set: + _dict["input"] = None + + return _dict + + @classmethod + def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: + """Create an instance of RunResumeStream from a dict""" + if obj is None: + return None + + if not isinstance(obj, dict): + return cls.model_validate(obj) + + _obj = cls.model_validate( + { + "thread_id": obj.get("thread_id"), + "agent_id": obj.get("agent_id"), + "input": Input.from_dict(obj["input"]) + if obj.get("input") is not None + else None, + "messages": [Message.from_dict(_item) for _item in obj["messages"]] + if obj.get("messages") is not None + else None, + "metadata": obj.get("metadata"), + "config": Config.from_dict(obj["config"]) + if obj.get("config") is not None + else None, + "webhook": obj.get("webhook"), + "on_completion": obj.get("on_completion"), + "on_disconnect": obj.get("on_disconnect") + if obj.get("on_disconnect") is not None + else "cancel", + "stream_mode": StreamMode.from_dict(obj["stream_mode"]) + if obj.get("stream_mode") is not None + else None, + } + ) + return _obj diff --git a/client-python/ap_client/models/run_stream.py b/client-python/ap_client/models/run_stream.py index a9e86f4..508c782 100644 --- a/client-python/ap_client/models/run_stream.py +++ b/client-python/ap_client/models/run_stream.py @@ -22,7 +22,7 @@ from ap_client.models.config import Config from ap_client.models.input import Input from ap_client.models.message import Message -from ap_client.models.stream_mode import StreamMode +from ap_client.models.stream_mode1 import StreamMode1 from typing import Set from typing_extensions import Self @@ -63,7 +63,7 @@ class RunStream(BaseModel): default="reject", description="How to handle missing thread. Must be either 'reject' (raise error if missing), or 'create' (create new thread).", ) - stream_mode: Optional[StreamMode] = None + stream_mode: Optional[StreamMode1] = None __properties: ClassVar[List[str]] = [ "thread_id", "agent_id", @@ -199,7 +199,7 @@ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]: "if_not_exists": obj.get("if_not_exists") if obj.get("if_not_exists") is not None else "reject", - "stream_mode": StreamMode.from_dict(obj["stream_mode"]) + "stream_mode": StreamMode1.from_dict(obj["stream_mode"]) if obj.get("stream_mode") is not None else None, } diff --git a/client-python/ap_client/models/stream_mode1.py b/client-python/ap_client/models/stream_mode1.py new file mode 100644 index 0000000..abc61fd --- /dev/null +++ b/client-python/ap_client/models/stream_mode1.py @@ -0,0 +1,150 @@ +# coding: utf-8 + +""" +Agent Protocol + +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +The version of the OpenAPI document: 0.1.6 +Generated by OpenAPI Generator (https://openapi-generator.tech) + +Do not edit the class manually. +""" # noqa: E501 + +from __future__ import annotations +import json +import pprint +import re # noqa: F401 +from pydantic import ( + BaseModel, + ValidationError, + field_validator, +) +from typing import List, Optional +from ap_client.models.stream_mode import StreamMode +from typing import Union, Any, Set, TYPE_CHECKING, Dict +from typing_extensions import Self + +STREAMMODE1_ANY_OF_SCHEMAS = ["List[StreamMode]", "StreamMode"] + + +class StreamMode1(BaseModel): + """ + The stream mode(s) to use. + """ + + # data type: StreamMode + anyof_schema_1_validator: Optional[StreamMode] = None + # data type: List[StreamMode] + anyof_schema_2_validator: Optional[List[StreamMode]] = None + if TYPE_CHECKING: + actual_instance: Optional[Union[List[StreamMode], StreamMode]] = None + else: + actual_instance: Any = None + any_of_schemas: Set[str] = {"List[StreamMode]", "StreamMode"} + + model_config = { + "validate_assignment": True, + "protected_namespaces": (), + } + + def __init__(self, *args, **kwargs) -> None: + if args: + if len(args) > 1: + raise ValueError( + "If a position argument is used, only 1 is allowed to set `actual_instance`" + ) + if kwargs: + raise ValueError( + "If a position argument is used, keyword arguments cannot be used." + ) + super().__init__(actual_instance=args[0]) + else: + super().__init__(**kwargs) + + @field_validator("actual_instance") + def actual_instance_must_validate_anyof(cls, v): + instance = StreamMode1.model_construct() + error_messages = [] + # validate data type: StreamMode + if not isinstance(v, StreamMode): + error_messages.append(f"Error! Input type `{type(v)}` is not `StreamMode`") + else: + return v + + # validate data type: List[StreamMode] + try: + instance.anyof_schema_2_validator = v + return v + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + if error_messages: + # no match + raise ValueError( + "No match found when setting the actual_instance in StreamMode1 with anyOf schemas: List[StreamMode], StreamMode. Details: " + + ", ".join(error_messages) + ) + else: + return v + + @classmethod + def from_dict(cls, obj: Dict[str, Any]) -> Self: + return cls.from_json(json.dumps(obj)) + + @classmethod + def from_json(cls, json_str: str) -> Self: + """Returns the object represented by the json string""" + instance = cls.model_construct() + error_messages = [] + # anyof_schema_1_validator: Optional[StreamMode] = None + try: + instance.actual_instance = StreamMode.from_json(json_str) + return instance + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + # deserialize data into List[StreamMode] + try: + # validation + instance.anyof_schema_2_validator = json.loads(json_str) + # assign value to actual_instance + instance.actual_instance = instance.anyof_schema_2_validator + return instance + except (ValidationError, ValueError) as e: + error_messages.append(str(e)) + + if error_messages: + # no match + raise ValueError( + "No match found when deserializing the JSON string into StreamMode1 with anyOf schemas: List[StreamMode], StreamMode. Details: " + + ", ".join(error_messages) + ) + else: + return instance + + def to_json(self) -> str: + """Returns the JSON representation of the actual instance""" + if self.actual_instance is None: + return "null" + + if hasattr(self.actual_instance, "to_json") and callable( + self.actual_instance.to_json + ): + return self.actual_instance.to_json() + else: + return json.dumps(self.actual_instance) + + def to_dict(self) -> Optional[Union[Dict[str, Any], List[StreamMode], StreamMode]]: + """Returns the dict representation of the actual instance""" + if self.actual_instance is None: + return None + + if hasattr(self.actual_instance, "to_dict") and callable( + self.actual_instance.to_dict + ): + return self.actual_instance.to_dict() + else: + return self.actual_instance + + def to_str(self) -> str: + """Returns the string representation of the actual instance""" + return pprint.pformat(self.model_dump()) diff --git a/client-python/docs/Run.md b/client-python/docs/Run.md index d416c5e..fe648eb 100644 --- a/client-python/docs/Run.md +++ b/client-python/docs/Run.md @@ -15,7 +15,7 @@ Name | Type | Description | Notes **on_completion** | **str** | Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'delete' when thread_id not provided, otherwise 'keep'. | [optional] **on_disconnect** | **str** | The disconnect mode to use. Must be one of 'cancel' or 'continue'. | [optional] [default to 'cancel'] **if_not_exists** | **str** | How to handle missing thread. Must be either 'reject' (raise error if missing), or 'create' (create new thread). | [optional] [default to 'reject'] -**stream_mode** | [**StreamMode**](StreamMode.md) | | [optional] +**stream_mode** | [**StreamMode1**](StreamMode1.md) | | [optional] **run_id** | **str** | The ID of the run. | **created_at** | **datetime** | The time the run was created. | **updated_at** | **datetime** | The last time the run was updated. | diff --git a/client-python/docs/RunResume.md b/client-python/docs/RunResume.md new file mode 100644 index 0000000..ef2568a --- /dev/null +++ b/client-python/docs/RunResume.md @@ -0,0 +1,38 @@ +# RunResume + +Payload for resuming a run from an interrupted thread. Requires an existing thread; does not create new threads. + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**thread_id** | **str** | The ID of the thread to resume. Must refer to an existing thread. | +**agent_id** | **str** | The agent ID to run. If not provided will use the agent associated with this thread (or the default agent for this service). 'agent_id' is ignored unless Agents stage is implemented. | [optional] +**input** | [**Input**](Input.md) | | [optional] +**messages** | [**List[Message]**](Message.md) | The messages to pass an input to the agent. | [optional] +**metadata** | **object** | Metadata to assign to the run. | [optional] +**config** | [**Config**](Config.md) | | [optional] +**webhook** | **str** | Webhook to call after run finishes. | [optional] +**on_completion** | **str** | Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'keep'. | [optional] +**on_disconnect** | **str** | The disconnect mode to use. Must be one of 'cancel' or 'continue'. | [optional] [default to 'cancel'] + +## Example + +```python +from ap_client.models.run_resume import RunResume + +# TODO update the JSON string below +json = "{}" +# create an instance of RunResume from a JSON string +run_resume_instance = RunResume.from_json(json) +# print the JSON string representation of the object +print(RunResume.to_json()) + +# convert the object into a dict +run_resume_dict = run_resume_instance.to_dict() +# create an instance of RunResume from a dict +run_resume_from_dict = RunResume.from_dict(run_resume_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/client-python/docs/RunResumeStream.md b/client-python/docs/RunResumeStream.md new file mode 100644 index 0000000..065eba6 --- /dev/null +++ b/client-python/docs/RunResumeStream.md @@ -0,0 +1,39 @@ +# RunResumeStream + +Payload for resuming a run and streaming the output. + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**thread_id** | **str** | The ID of the thread to resume. Must refer to an existing thread. | +**agent_id** | **str** | The agent ID to run. If not provided will use the agent associated with this thread (or the default agent for this service). 'agent_id' is ignored unless Agents stage is implemented. | [optional] +**input** | [**Input**](Input.md) | | [optional] +**messages** | [**List[Message]**](Message.md) | The messages to pass an input to the agent. | [optional] +**metadata** | **object** | Metadata to assign to the run. | [optional] +**config** | [**Config**](Config.md) | | [optional] +**webhook** | **str** | Webhook to call after run finishes. | [optional] +**on_completion** | **str** | Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'keep'. | [optional] +**on_disconnect** | **str** | The disconnect mode to use. Must be one of 'cancel' or 'continue'. | [optional] [default to 'cancel'] +**stream_mode** | [**StreamMode**](StreamMode.md) | | [optional] + +## Example + +```python +from ap_client.models.run_resume_stream import RunResumeStream + +# TODO update the JSON string below +json = "{}" +# create an instance of RunResumeStream from a JSON string +run_resume_stream_instance = RunResumeStream.from_json(json) +# print the JSON string representation of the object +print(RunResumeStream.to_json()) + +# convert the object into a dict +run_resume_stream_dict = run_resume_stream_instance.to_dict() +# create an instance of RunResumeStream from a dict +run_resume_stream_from_dict = RunResumeStream.from_dict(run_resume_stream_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/client-python/docs/RunStream.md b/client-python/docs/RunStream.md index 254d0b6..983b6ea 100644 --- a/client-python/docs/RunStream.md +++ b/client-python/docs/RunStream.md @@ -15,7 +15,7 @@ Name | Type | Description | Notes **on_completion** | **str** | Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'delete' when thread_id not provided, otherwise 'keep'. | [optional] **on_disconnect** | **str** | The disconnect mode to use. Must be one of 'cancel' or 'continue'. | [optional] [default to 'cancel'] **if_not_exists** | **str** | How to handle missing thread. Must be either 'reject' (raise error if missing), or 'create' (create new thread). | [optional] [default to 'reject'] -**stream_mode** | [**StreamMode**](StreamMode.md) | | [optional] +**stream_mode** | [**StreamMode1**](StreamMode1.md) | | [optional] ## Example diff --git a/client-python/docs/RunsApi.md b/client-python/docs/RunsApi.md index a5e550e..8367f65 100644 --- a/client-python/docs/RunsApi.md +++ b/client-python/docs/RunsApi.md @@ -6,6 +6,9 @@ Method | HTTP request | Description ------------- | ------------- | ------------- [**create_and_stream_run**](RunsApi.md#create_and_stream_run) | **POST** /runs/stream | Create Run, Stream Output [**create_and_wait_run**](RunsApi.md#create_and_wait_run) | **POST** /runs/wait | Create Run, Wait for Output +[**resume_and_stream_run**](RunsApi.md#resume_and_stream_run) | **PATCH** /runs/resume/stream | Resume Run and Stream Output +[**resume_and_wait_run**](RunsApi.md#resume_and_wait_run) | **PATCH** /runs/resume/wait | Resume Run and Wait +[**resume_run**](RunsApi.md#resume_run) | **PATCH** /runs/resume | Resume Run (start execution from interrupted thread) # **create_and_stream_run** @@ -151,3 +154,218 @@ No authorization required [[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) +# **resume_and_stream_run** +> str resume_and_stream_run(run_resume_stream) + +Resume Run and Stream Output + +Resume a thread that is in an interrupted (suspended) state and stream its output. Convenience equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/stream. + +### Example + + +```python +import ap_client +from ap_client.models.run_resume_stream import RunResumeStream +from ap_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = ap_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with ap_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = ap_client.RunsApi(api_client) + run_resume_stream = ap_client.RunResumeStream() # RunResumeStream | + + try: + # Resume Run and Stream Output + api_response = api_instance.resume_and_stream_run(run_resume_stream) + print("The response of RunsApi->resume_and_stream_run:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling RunsApi->resume_and_stream_run: %s\n" % e) +``` + + + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **run_resume_stream** | [**RunResumeStream**](RunResumeStream.md)| | + +### Return type + +**str** + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: text/event-stream, application/json + +### HTTP response details + +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**200** | Success | - | +**404** | Not Found | - | +**409** | Conflict | - | +**422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **resume_and_wait_run** +> RunWaitResponse resume_and_wait_run(run_resume) + +Resume Run and Wait + +Resume a thread that is in an interrupted state and wait for its completion. Equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/wait. + +### Example + + +```python +import ap_client +from ap_client.models.run_resume import RunResume +from ap_client.models.run_wait_response import RunWaitResponse +from ap_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = ap_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with ap_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = ap_client.RunsApi(api_client) + run_resume = ap_client.RunResume() # RunResume | + + try: + # Resume Run and Wait + api_response = api_instance.resume_and_wait_run(run_resume) + print("The response of RunsApi->resume_and_wait_run:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling RunsApi->resume_and_wait_run: %s\n" % e) +``` + + + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **run_resume** | [**RunResume**](RunResume.md)| | + +### Return type + +[**RunWaitResponse**](RunWaitResponse.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**200** | Success | - | +**404** | Not Found | - | +**409** | Conflict | - | +**422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + +# **resume_run** +> Run resume_run(run_resume) + +Resume Run (start execution from interrupted thread) + +Resume a thread that is in an interrupted (suspended) state. Thread ID is required. Returns the updated Run object (typically queued or in_progress). + +### Example + + +```python +import ap_client +from ap_client.models.run import Run +from ap_client.models.run_resume import RunResume +from ap_client.rest import ApiException +from pprint import pprint + +# Defining the host is optional and defaults to http://localhost +# See configuration.py for a list of all supported configuration parameters. +configuration = ap_client.Configuration( + host = "http://localhost" +) + + +# Enter a context with an instance of the API client +with ap_client.ApiClient(configuration) as api_client: + # Create an instance of the API class + api_instance = ap_client.RunsApi(api_client) + run_resume = ap_client.RunResume() # RunResume | + + try: + # Resume Run (start execution from interrupted thread) + api_response = api_instance.resume_run(run_resume) + print("The response of RunsApi->resume_run:\n") + pprint(api_response) + except Exception as e: + print("Exception when calling RunsApi->resume_run: %s\n" % e) +``` + + + +### Parameters + + +Name | Type | Description | Notes +------------- | ------------- | ------------- | ------------- + **run_resume** | [**RunResume**](RunResume.md)| | + +### Return type + +[**Run**](Run.md) + +### Authorization + +No authorization required + +### HTTP request headers + + - **Content-Type**: application/json + - **Accept**: application/json + +### HTTP response details + +| Status code | Description | Response headers | +|-------------|-------------|------------------| +**200** | Success | - | +**404** | Not Found | - | +**409** | Conflict | - | +**422** | Validation Error | - | + +[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md) + diff --git a/client-python/docs/StreamMode1.md b/client-python/docs/StreamMode1.md new file mode 100644 index 0000000..2b819ca --- /dev/null +++ b/client-python/docs/StreamMode1.md @@ -0,0 +1,29 @@ +# StreamMode1 + +The stream mode(s) to use. + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- + +## Example + +```python +from ap_client.models.stream_mode1 import StreamMode1 + +# TODO update the JSON string below +json = "{}" +# create an instance of StreamMode1 from a JSON string +stream_mode1_instance = StreamMode1.from_json(json) +# print the JSON string representation of the object +print(StreamMode1.to_json()) + +# convert the object into a dict +stream_mode1_dict = stream_mode1_instance.to_dict() +# create an instance of StreamMode1 from a dict +stream_mode1_from_dict = StreamMode1.from_dict(stream_mode1_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/client-python/test/test_run_resume.py b/client-python/test/test_run_resume.py new file mode 100644 index 0000000..14d9362 --- /dev/null +++ b/client-python/test/test_run_resume.py @@ -0,0 +1,69 @@ +# coding: utf-8 + +""" + Agent Protocol + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.6 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from ap_client.models.run_resume import RunResume + +class TestRunResume(unittest.TestCase): + """RunResume unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> RunResume: + """Test RunResume + include_optional is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `RunResume` + """ + model = RunResume() + if include_optional: + return RunResume( + thread_id = '', + agent_id = '', + input = None, + messages = [ + { + 'key' : null + } + ], + metadata = ap_client.models.metadata.Metadata(), + config = ap_client.models.config.Config( + tags = [ + '' + ], + recursion_limit = 56, + configurable = ap_client.models.configurable.Configurable(), ), + webhook = '0', + on_completion = 'keep', + on_disconnect = 'cancel' + ) + else: + return RunResume( + thread_id = '', + ) + """ + + def testRunResume(self): + """Test RunResume""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/client-python/test/test_run_resume_stream.py b/client-python/test/test_run_resume_stream.py new file mode 100644 index 0000000..995aa6a --- /dev/null +++ b/client-python/test/test_run_resume_stream.py @@ -0,0 +1,70 @@ +# coding: utf-8 + +""" + Agent Protocol + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.6 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from ap_client.models.run_resume_stream import RunResumeStream + +class TestRunResumeStream(unittest.TestCase): + """RunResumeStream unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> RunResumeStream: + """Test RunResumeStream + include_optional is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `RunResumeStream` + """ + model = RunResumeStream() + if include_optional: + return RunResumeStream( + thread_id = '', + agent_id = '', + input = None, + messages = [ + { + 'key' : null + } + ], + metadata = ap_client.models.metadata.Metadata(), + config = ap_client.models.config.Config( + tags = [ + '' + ], + recursion_limit = 56, + configurable = ap_client.models.configurable.Configurable(), ), + webhook = '0', + on_completion = 'keep', + on_disconnect = 'cancel', + stream_mode = None + ) + else: + return RunResumeStream( + thread_id = '', + ) + """ + + def testRunResumeStream(self): + """Test RunResumeStream""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/client-python/test/test_stream_mode1.py b/client-python/test/test_stream_mode1.py new file mode 100644 index 0000000..496522d --- /dev/null +++ b/client-python/test/test_stream_mode1.py @@ -0,0 +1,50 @@ +# coding: utf-8 + +""" + Agent Protocol + + No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + + The version of the OpenAPI document: 0.1.6 + Generated by OpenAPI Generator (https://openapi-generator.tech) + + Do not edit the class manually. +""" # noqa: E501 + + +import unittest + +from ap_client.models.stream_mode1 import StreamMode1 + +class TestStreamMode1(unittest.TestCase): + """StreamMode1 unit test stubs""" + + def setUp(self): + pass + + def tearDown(self): + pass + + def make_instance(self, include_optional) -> StreamMode1: + """Test StreamMode1 + include_optional is a boolean, when False only required + params are included, when True both required and + optional params are included """ + # uncomment below to create an instance of `StreamMode1` + """ + model = StreamMode1() + if include_optional: + return StreamMode1( + ) + else: + return StreamMode1( + ) + """ + + def testStreamMode1(self): + """Test StreamMode1""" + # inst_req_only = self.make_instance(include_optional=False) + # inst_req_and_optional = self.make_instance(include_optional=True) + +if __name__ == '__main__': + unittest.main() diff --git a/openapi.json b/openapi.json index 0d1d05a..bc34045 100644 --- a/openapi.json +++ b/openapi.json @@ -973,6 +973,193 @@ } } }, + "/runs/resume": { + "patch": { + "tags": [ + "Runs" + ], + "summary": "Resume Run (start execution from interrupted thread)", + "description": "Resume a thread that is in an interrupted (suspended) state. Thread ID is required. Returns the updated Run object (typically queued or in_progress).", + "operationId": "resume_run", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RunResume" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Run" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "409": { + "description": "Conflict. This will be returned if the underlying thread is not in an interrupted state.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + } + } + }, + "/runs/resume/stream": { + "patch": { + "tags": [ + "Runs" + ], + "summary": "Resume Run and Stream Output", + "description": "Resume a thread that is in an interrupted (suspended) state and stream its output. Convenience equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/stream.", + "operationId": "resume_and_stream_run", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RunResumeStream" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Success", + "content": { + "text/event-stream": { + "schema": { + "type": "string", + "description": "The server will send a stream of events in SSE format.\n\n**Example event**:\n\nid: 1\n\nevent: message\n\ndata: {}" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "409": { + "description": "Conflict. This will be returned if the underlying thread is not in an interrupted state.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + } + } + }, + "/runs/resume/wait": { + "patch": { + "tags": [ + "Runs" + ], + "summary": "Resume Run and Wait", + "description": "Resume a thread that is in an interrupted state and wait for its completion. Equivalent to PATCH /runs/resume followed by GET /runs/{run_id}/wait.", + "operationId": "resume_and_wait_run", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RunResume" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Success", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/RunWaitResponse" + } + } + } + }, + "404": { + "description": "Not Found", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "409": { + "description": "Conflict. This will be returned if the underlying thread is not in an interrupted state.", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + }, + "422": { + "description": "Validation Error", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + } + } + } + } + }, "/runs/stream": { "post": { "tags": ["Runs"], @@ -1532,6 +1719,151 @@ "title": "RunCreate", "description": "Payload for creating a run." }, + "RunResume": { + "properties": { + "thread_id": { + "type": "string", + "format": "uuid", + "title": "Thread Id", + "description": "The ID of the thread to resume. Must refer to an existing thread that is in an interrupted state." + }, + "agent_id": { + "type": "string", + "title": "Agent Id", + "description": "The agent ID to run. If not provided will use the agent associated with this thread (or the default agent for this service). 'agent_id' is ignored unless Agents stage is implemented." + }, + "input": { + "anyOf": [ + { + "type": "object" + }, + { + "type": "array" + }, + { + "type": "string" + }, + { + "type": "number" + }, + { + "type": "boolean" + }, + { + "type": "null" + } + ], + "title": "Input", + "description": "The input to the agent." + }, + "messages": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Message" + }, + "title": "Messages", + "description": "The messages to pass an input to the agent." + }, + "metadata": { + "type": "object", + "title": "Metadata", + "description": "Metadata to assign to the run." + }, + "config": { + "properties": { + "tags": { + "items": { + "type": "string" + }, + "type": "array", + "title": "Tags" + }, + "recursion_limit": { + "type": "integer", + "title": "Recursion Limit" + }, + "configurable": { + "type": "object", + "title": "Configurable" + } + }, + "type": "object", + "title": "Config", + "description": "The configuration for the agent." + }, + "webhook": { + "type": "string", + "maxLength": 65536, + "minLength": 1, + "format": "uri", + "title": "Webhook", + "description": "Webhook to call after run finishes." + }, + "on_completion": { + "type": "string", + "enum": [ + "keep", + "delete" + ], + "title": "On Completion", + "description": "Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'keep'." + }, + "on_disconnect": { + "type": "string", + "enum": [ + "cancel", + "continue" + ], + "title": "On Disconnect", + "description": "The disconnect mode to use. Must be one of 'cancel' or 'continue'.", + "default": "cancel" + } + }, + "type": "object", + "required": [ + "thread_id" + ], + "title": "RunResume", + "description": "Payload for resuming a run from an interrupted thread. Requires an existing thread; does not create new threads." + }, + "RunResumeStream": { + "allOf": [ + { + "$ref": "#/components/schemas/RunResume" + }, + { + "properties": { + "stream_mode": { + "anyOf": [ + { + "$ref": "#/components/schemas/StreamMode" + }, + { + "items": { + "$ref": "#/components/schemas/StreamMode" + }, + "type": "array" + } + ], + "title": "Stream Mode", + "description": "The stream mode(s) to use.", + "default": "values" + } + }, + "type": "object", + "required": [ + "run_id", + "created_at", + "updated_at", + "status", + "metadata" + ], + "title": "Run" + } + ], + "title": "RunResumeStream", + "description": "Payload for resuming a run and streaming the output." + }, "RunStream": { "allOf": [ { diff --git a/server/ap_server/models.py b/server/ap_server/models.py index b8ba001..c9e69a3 100644 --- a/server/ap_server/models.py +++ b/server/ap_server/models.py @@ -105,6 +105,11 @@ class IfNotExists(Enum): reject = "reject" +class OnCompletion1(Enum): + keep = "keep" + delete = "delete" + + class RunSearchRequest(BaseModel): metadata: Optional[Dict[str, Any]] = Field( None, description="Run metadata to filter on.", title="Metadata" @@ -381,6 +386,52 @@ class RunCreate(BaseModel): ) +class RunResume(BaseModel): + thread_id: UUID = Field( + ..., + description="The ID of the thread to resume. Must refer to an existing thread.", + title="Thread Id", + ) + agent_id: Optional[str] = Field( + None, + description="The agent ID to run. If not provided will use the agent associated with this thread (or the default agent for this service). 'agent_id' is ignored unless Agents stage is implemented.", + title="Agent Id", + ) + input: Optional[Union[Dict[str, Any], List, str, float, bool]] = Field( + None, description="The input to the agent.", title="Input" + ) + messages: Optional[List[Message]] = Field( + None, + description="The messages to pass an input to the agent.", + title="Messages", + ) + metadata: Optional[Dict[str, Any]] = Field( + None, description="Metadata to assign to the run.", title="Metadata" + ) + config: Optional[Config] = Field( + None, description="The configuration for the agent.", title="Config" + ) + webhook: Optional[AnyUrl] = Field( + None, description="Webhook to call after run finishes.", title="Webhook" + ) + on_completion: Optional[OnCompletion1] = Field( + None, + description="Whether to delete or keep the thread when run completes. Must be one of 'delete' or 'keep'. Defaults to 'keep'.", + title="On Completion", + ) + on_disconnect: Optional[OnDisconnect] = Field( + "cancel", + description="The disconnect mode to use. Must be one of 'cancel' or 'continue'.", + title="On Disconnect", + ) + + +class RunResumeStream(RunResume): + stream_mode: Optional[Union[StreamMode, List[StreamMode]]] = Field( + "values", description="The stream mode(s) to use.", title="Stream Mode" + ) + + class RunStream(RunCreate): stream_mode: Optional[Union[StreamMode, List[StreamMode]]] = Field( "values", description="The stream mode(s) to use.", title="Stream Mode" diff --git a/server/ap_server/routers/runs.py b/server/ap_server/routers/runs.py index 65e30ca..44ea32a 100644 --- a/server/ap_server/routers/runs.py +++ b/server/ap_server/routers/runs.py @@ -5,11 +5,71 @@ from fastapi import APIRouter -from ..models import ErrorResponse, RunCreate, RunStream, RunWaitResponse, Union +from ..models import ( + ErrorResponse, + Run, + RunCreate, + RunResume, + RunResumeStream, + RunStream, + RunWaitResponse, + Union, +) router = APIRouter(tags=["Runs"]) +@router.patch( + "/runs/resume", + response_model=Run, + responses={ + "404": {"model": ErrorResponse}, + "409": {"model": ErrorResponse}, + "422": {"model": ErrorResponse}, + }, + tags=["Runs"], +) +def resume_run(body: RunResume) -> Union[Run, ErrorResponse]: + """ + Resume Run (start execution from interrupted thread) + """ + pass + + +@router.patch( + "/runs/resume/stream", + response_model=str, + responses={ + "404": {"model": ErrorResponse}, + "409": {"model": ErrorResponse}, + "422": {"model": ErrorResponse}, + }, + tags=["Runs"], +) +def resume_and_stream_run(body: RunResumeStream) -> Union[str, ErrorResponse]: + """ + Resume Run and Stream Output + """ + pass + + +@router.patch( + "/runs/resume/wait", + response_model=RunWaitResponse, + responses={ + "404": {"model": ErrorResponse}, + "409": {"model": ErrorResponse}, + "422": {"model": ErrorResponse}, + }, + tags=["Runs"], +) +def resume_and_wait_run(body: RunResume) -> Union[RunWaitResponse, ErrorResponse]: + """ + Resume Run and Wait + """ + pass + + @router.post( "/runs/stream", response_model=str, diff --git a/server/ap_server/routers/store.py b/server/ap_server/routers/store.py index f34da85..dcdceab 100644 --- a/server/ap_server/routers/store.py +++ b/server/ap_server/routers/store.py @@ -11,6 +11,7 @@ ErrorResponse, Item, ListNamespaceResponse, + Namespace, Optional, SearchItemsResponse, StoreDeleteRequest,