# This file was auto-generated by Fern from our API Definition.

import typing
from json.decoder import JSONDecodeError

from ..core.api_error import ApiError
from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.http_response import AsyncHttpResponse, HttpResponse
from ..core.jsonable_encoder import jsonable_encoder
from ..core.pydantic_utilities import parse_obj_as
from ..core.request_options import RequestOptions
from ..core.serialization import convert_and_respect_annotation_metadata
from ..errors.bad_request_error import BadRequestError
from ..errors.forbidden_error import ForbiddenError
from ..errors.internal_server_error import InternalServerError
from ..errors.not_found_error import NotFoundError
from ..errors.unauthorized_error import UnauthorizedError
from ..requests.create_agent_request_configuration_endpoint import CreateAgentRequestConfigurationEndpointParams
from ..requests.create_agent_request_template_variables_value import CreateAgentRequestTemplateVariablesValueParams
from ..requests.create_agent_request_tools_item import CreateAgentRequestToolsItemParams
from ..requests.task import TaskParams
from ..types.basic_error import BasicError
from ..types.create_agent_request_audio_format import CreateAgentRequestAudioFormat
from ..types.create_agent_request_background_noise import CreateAgentRequestBackgroundNoise
from ..types.language_code import LanguageCode
from .requests.update_agent_request_configuration_endpoint import UpdateAgentRequestConfigurationEndpointParams
from .requests.update_agent_request_template_variables_value import UpdateAgentRequestTemplateVariablesValueParams
from .requests.update_agent_request_tools_item import UpdateAgentRequestToolsItemParams
from .types.agents_create_response import AgentsCreateResponse
from .types.agents_delete_response import AgentsDeleteResponse
from .types.agents_get_response import AgentsGetResponse
from .types.agents_list_response import AgentsListResponse
from .types.agents_update_response import AgentsUpdateResponse
from .types.agents_upsert_response import AgentsUpsertResponse
from .types.update_agent_request_audio_format import UpdateAgentRequestAudioFormat
from .types.update_agent_request_background_noise import UpdateAgentRequestBackgroundNoise

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class RawAgentsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> HttpResponse[AgentsListResponse]:
        """
        Returns all agents in a project.

        Parameters
        ----------
        project : typing.Optional[str]
            The name of the project to list agents for.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AgentsListResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            "agents",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsListResponse,
                    parse_obj_as(
                        type_=AgentsListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BasicError,
                        parse_obj_as(
                            type_=BasicError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def create(
        self,
        *,
        name: str,
        project: typing.Optional[str] = None,
        phone_number: typing.Optional[typing.Literal["assign-automatically"]] = OMIT,
        timezone: typing.Optional[str] = OMIT,
        voice_id: typing.Optional[str] = OMIT,
        audio_format: typing.Optional[CreateAgentRequestAudioFormat] = OMIT,
        audio_speed: typing.Optional[float] = OMIT,
        background_noise_level: typing.Optional[float] = OMIT,
        background_noise: typing.Optional[CreateAgentRequestBackgroundNoise] = OMIT,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]] = OMIT,
        tasks: typing.Optional[typing.Sequence[TaskParams]] = OMIT,
        no_input_poke_sec: typing.Optional[int] = OMIT,
        no_input_poke_text: typing.Optional[str] = OMIT,
        no_input_end_conversation_sec: typing.Optional[int] = OMIT,
        languages: typing.Optional[typing.Sequence[LanguageCode]] = OMIT,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpointParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AgentsCreateResponse]:
        """
        Creates a new agent in a project.

        Parameters
        ----------
        name : str
            The name of the agent. Can only contain lowercase letters, numbers and hyphens. Must be unique within the project.

        project : typing.Optional[str]
            The name of the project to create the agent in.

        phone_number : typing.Optional[typing.Literal["assign-automatically"]]

        timezone : typing.Optional[str]
            The timezone of the agent. Used to format system variables like `{{system_time}}`.

        voice_id : typing.Optional[str]
            The voice ID to use.

        audio_format : typing.Optional[CreateAgentRequestAudioFormat]
            The audio format of the agent.

        audio_speed : typing.Optional[float]
            The audio speed of the agent.

        background_noise_level : typing.Optional[float]
            The background noise level of the agent.

        background_noise : typing.Optional[CreateAgentRequestBackgroundNoise]
            The background noise type. Can be "office", "call-center", "coffee-shop", or null.

        welcome_message : typing.Optional[str]
            Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`.

        system_prompt : typing.Optional[str]
            Instructions for the conversation. Can contain template variables like `{{subject}}`.

        template_variables : typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]]
            Variables that can be used in the welcome message and the system prompt.

        tools : typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]]
            Array of built-in or custom tool names to use.

        tasks : typing.Optional[typing.Sequence[TaskParams]]
            Array of task objects with `name` and `description` fields.

        no_input_poke_sec : typing.Optional[int]
            Number of seconds of silence before sending a poke message. `null` disables the poke message.

        no_input_poke_text : typing.Optional[str]
            The message to send after the specified silence.

        no_input_end_conversation_sec : typing.Optional[int]
            Seconds of silence before ending the conversation.

        languages : typing.Optional[typing.Sequence[LanguageCode]]
            Array of ISO 639-1 language codes that the agent should be able to recognize

        boosted_keywords : typing.Optional[typing.Sequence[str]]
            These words, or short phrases, will be more accurately recognized by the agent.

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpointParams]
            When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint when to get configuration options.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AgentsCreateResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            "agents",
            base_url=self._client_wrapper.get_environment().base,
            method="POST",
            params={
                "project": project,
            },
            json={
                "name": name,
                "phone_number": phone_number,
                "timezone": timezone,
                "voice_id": voice_id,
                "audio_format": audio_format,
                "audio_speed": audio_speed,
                "background_noise_level": background_noise_level,
                "background_noise": background_noise,
                "welcome_message": welcome_message,
                "system_prompt": system_prompt,
                "template_variables": convert_and_respect_annotation_metadata(
                    object_=template_variables,
                    annotation=typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams],
                    direction="write",
                ),
                "tools": convert_and_respect_annotation_metadata(
                    object_=tools, annotation=typing.Sequence[CreateAgentRequestToolsItemParams], direction="write"
                ),
                "tasks": convert_and_respect_annotation_metadata(
                    object_=tasks, annotation=typing.Sequence[TaskParams], direction="write"
                ),
                "no_input_poke_sec": no_input_poke_sec,
                "no_input_poke_text": no_input_poke_text,
                "no_input_end_conversation_sec": no_input_end_conversation_sec,
                "languages": languages,
                "boosted_keywords": boosted_keywords,
                "configuration_endpoint": convert_and_respect_annotation_metadata(
                    object_=configuration_endpoint,
                    annotation=typing.Optional[CreateAgentRequestConfigurationEndpointParams],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsCreateResponse,
                    parse_obj_as(
                        type_=AgentsCreateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BasicError,
                        parse_obj_as(
                            type_=BasicError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BasicError,
                        parse_obj_as(
                            type_=BasicError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def upsert(
        self,
        *,
        name: str,
        project: typing.Optional[str] = None,
        phone_number: typing.Optional[typing.Literal["assign-automatically"]] = OMIT,
        timezone: typing.Optional[str] = OMIT,
        voice_id: typing.Optional[str] = OMIT,
        audio_format: typing.Optional[CreateAgentRequestAudioFormat] = OMIT,
        audio_speed: typing.Optional[float] = OMIT,
        background_noise_level: typing.Optional[float] = OMIT,
        background_noise: typing.Optional[CreateAgentRequestBackgroundNoise] = OMIT,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]] = OMIT,
        tasks: typing.Optional[typing.Sequence[TaskParams]] = OMIT,
        no_input_poke_sec: typing.Optional[int] = OMIT,
        no_input_poke_text: typing.Optional[str] = OMIT,
        no_input_end_conversation_sec: typing.Optional[int] = OMIT,
        languages: typing.Optional[typing.Sequence[LanguageCode]] = OMIT,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpointParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AgentsUpsertResponse]:
        """
        Upserts an agent by name. If an agent with the same name already exists, it will be updated. Otherwise, it will be created.

        Parameters
        ----------
        name : str
            The name of the agent. Can only contain lowercase letters, numbers and hyphens. Must be unique within the project.

        project : typing.Optional[str]
            The name of the project containing the agent.

        phone_number : typing.Optional[typing.Literal["assign-automatically"]]

        timezone : typing.Optional[str]
            The timezone of the agent. Used to format system variables like `{{system_time}}`.

        voice_id : typing.Optional[str]
            The voice ID to use.

        audio_format : typing.Optional[CreateAgentRequestAudioFormat]
            The audio format of the agent.

        audio_speed : typing.Optional[float]
            The audio speed of the agent.

        background_noise_level : typing.Optional[float]
            The background noise level of the agent.

        background_noise : typing.Optional[CreateAgentRequestBackgroundNoise]
            The background noise type. Can be "office", "call-center", "coffee-shop", or null.

        welcome_message : typing.Optional[str]
            Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`.

        system_prompt : typing.Optional[str]
            Instructions for the conversation. Can contain template variables like `{{subject}}`.

        template_variables : typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]]
            Variables that can be used in the welcome message and the system prompt.

        tools : typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]]
            Array of built-in or custom tool names to use.

        tasks : typing.Optional[typing.Sequence[TaskParams]]
            Array of task objects with `name` and `description` fields.

        no_input_poke_sec : typing.Optional[int]
            Number of seconds of silence before sending a poke message. `null` disables the poke message.

        no_input_poke_text : typing.Optional[str]
            The message to send after the specified silence.

        no_input_end_conversation_sec : typing.Optional[int]
            Seconds of silence before ending the conversation.

        languages : typing.Optional[typing.Sequence[LanguageCode]]
            Array of ISO 639-1 language codes that the agent should be able to recognize

        boosted_keywords : typing.Optional[typing.Sequence[str]]
            These words, or short phrases, will be more accurately recognized by the agent.

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpointParams]
            When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint when to get configuration options.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AgentsUpsertResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            "agents/upsert",
            base_url=self._client_wrapper.get_environment().base,
            method="PUT",
            params={
                "project": project,
            },
            json={
                "name": name,
                "phone_number": phone_number,
                "timezone": timezone,
                "voice_id": voice_id,
                "audio_format": audio_format,
                "audio_speed": audio_speed,
                "background_noise_level": background_noise_level,
                "background_noise": background_noise,
                "welcome_message": welcome_message,
                "system_prompt": system_prompt,
                "template_variables": convert_and_respect_annotation_metadata(
                    object_=template_variables,
                    annotation=typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams],
                    direction="write",
                ),
                "tools": convert_and_respect_annotation_metadata(
                    object_=tools, annotation=typing.Sequence[CreateAgentRequestToolsItemParams], direction="write"
                ),
                "tasks": convert_and_respect_annotation_metadata(
                    object_=tasks, annotation=typing.Sequence[TaskParams], direction="write"
                ),
                "no_input_poke_sec": no_input_poke_sec,
                "no_input_poke_text": no_input_poke_text,
                "no_input_end_conversation_sec": no_input_end_conversation_sec,
                "languages": languages,
                "boosted_keywords": boosted_keywords,
                "configuration_endpoint": convert_and_respect_annotation_metadata(
                    object_=configuration_endpoint,
                    annotation=typing.Optional[CreateAgentRequestConfigurationEndpointParams],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsUpsertResponse,
                    parse_obj_as(
                        type_=AgentsUpsertResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AgentsGetResponse]:
        """
        Returns an agent by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the agent to get.

        project : typing.Optional[str]
            The name of the project containing the agent. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AgentsGetResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"agents/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsGetResponse,
                    parse_obj_as(
                        type_=AgentsGetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AgentsDeleteResponse]:
        """
        Deletes an agent by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the agent to delete.

        project : typing.Optional[str]
            The name of the project containing the agent. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AgentsDeleteResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"agents/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="DELETE",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsDeleteResponse,
                    parse_obj_as(
                        type_=AgentsDeleteResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    def update(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        name: typing.Optional[str] = OMIT,
        phone_number: typing.Optional[typing.Literal["assign-automatically"]] = OMIT,
        timezone: typing.Optional[str] = OMIT,
        voice_id: typing.Optional[str] = OMIT,
        audio_format: typing.Optional[UpdateAgentRequestAudioFormat] = OMIT,
        audio_speed: typing.Optional[float] = OMIT,
        background_noise_level: typing.Optional[float] = OMIT,
        background_noise: typing.Optional[UpdateAgentRequestBackgroundNoise] = OMIT,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, UpdateAgentRequestTemplateVariablesValueParams]] = OMIT,
        tools: typing.Optional[typing.Sequence[UpdateAgentRequestToolsItemParams]] = OMIT,
        tasks: typing.Optional[typing.Sequence[TaskParams]] = OMIT,
        no_input_poke_sec: typing.Optional[int] = OMIT,
        no_input_poke_text: typing.Optional[str] = OMIT,
        no_input_end_conversation_sec: typing.Optional[int] = OMIT,
        languages: typing.Optional[typing.Sequence[LanguageCode]] = OMIT,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[UpdateAgentRequestConfigurationEndpointParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[AgentsUpdateResponse]:
        """
        Updates an agent by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the agent to update.

        project : typing.Optional[str]
            The name of the project containing the agent. Only used when `nameOrId` is a name.

        name : typing.Optional[str]
            The name of the agent. Can only contain lowercase letters, numbers and hyphens. Must be unique within the project.

        phone_number : typing.Optional[typing.Literal["assign-automatically"]]

        timezone : typing.Optional[str]
            The timezone of the agent. Used to format system variables like `{{system_time}}`.

        voice_id : typing.Optional[str]
            The voice ID to use.

        audio_format : typing.Optional[UpdateAgentRequestAudioFormat]
            The audio format of the agent.

        audio_speed : typing.Optional[float]
            The audio speed of the agent.

        background_noise_level : typing.Optional[float]
            The background noise level of the agent.

        background_noise : typing.Optional[UpdateAgentRequestBackgroundNoise]
            The background noise type. Can be "office", "call-center", "coffee-shop", or null.

        welcome_message : typing.Optional[str]
            Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`.

        system_prompt : typing.Optional[str]
            Instructions for the conversation. Can contain template variables like `{{subject}}`.

        template_variables : typing.Optional[typing.Dict[str, UpdateAgentRequestTemplateVariablesValueParams]]
            Variables that can be used in the welcome message and the system prompt.

        tools : typing.Optional[typing.Sequence[UpdateAgentRequestToolsItemParams]]
            Array of built-in or custom tool names to use.

        tasks : typing.Optional[typing.Sequence[TaskParams]]
            Array of task objects with `name` and `description` fields.

        no_input_poke_sec : typing.Optional[int]
            Number of seconds of silence before sending a poke message. `null` disables the poke message.

        no_input_poke_text : typing.Optional[str]
            The message to send after the specified silence.

        no_input_end_conversation_sec : typing.Optional[int]
            Seconds of silence before ending the conversation.

        languages : typing.Optional[typing.Sequence[LanguageCode]]
            Array of ISO 639-1 language codes that the agent should be able to recognize

        boosted_keywords : typing.Optional[typing.Sequence[str]]
            These words, or short phrases, will be more accurately recognized by the agent.

        configuration_endpoint : typing.Optional[UpdateAgentRequestConfigurationEndpointParams]
            When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint when to get configuration options.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        HttpResponse[AgentsUpdateResponse]
            Success response
        """
        _response = self._client_wrapper.httpx_client.request(
            f"agents/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="PATCH",
            params={
                "project": project,
            },
            json={
                "name": name,
                "phone_number": phone_number,
                "timezone": timezone,
                "voice_id": voice_id,
                "audio_format": audio_format,
                "audio_speed": audio_speed,
                "background_noise_level": background_noise_level,
                "background_noise": background_noise,
                "welcome_message": welcome_message,
                "system_prompt": system_prompt,
                "template_variables": convert_and_respect_annotation_metadata(
                    object_=template_variables,
                    annotation=typing.Dict[str, UpdateAgentRequestTemplateVariablesValueParams],
                    direction="write",
                ),
                "tools": convert_and_respect_annotation_metadata(
                    object_=tools, annotation=typing.Sequence[UpdateAgentRequestToolsItemParams], direction="write"
                ),
                "tasks": convert_and_respect_annotation_metadata(
                    object_=tasks, annotation=typing.Sequence[TaskParams], direction="write"
                ),
                "no_input_poke_sec": no_input_poke_sec,
                "no_input_poke_text": no_input_poke_text,
                "no_input_end_conversation_sec": no_input_end_conversation_sec,
                "languages": languages,
                "boosted_keywords": boosted_keywords,
                "configuration_endpoint": convert_and_respect_annotation_metadata(
                    object_=configuration_endpoint,
                    annotation=typing.Optional[UpdateAgentRequestConfigurationEndpointParams],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsUpdateResponse,
                    parse_obj_as(
                        type_=AgentsUpdateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawAgentsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> AsyncHttpResponse[AgentsListResponse]:
        """
        Returns all agents in a project.

        Parameters
        ----------
        project : typing.Optional[str]
            The name of the project to list agents for.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AgentsListResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "agents",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsListResponse,
                    parse_obj_as(
                        type_=AgentsListResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BasicError,
                        parse_obj_as(
                            type_=BasicError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def create(
        self,
        *,
        name: str,
        project: typing.Optional[str] = None,
        phone_number: typing.Optional[typing.Literal["assign-automatically"]] = OMIT,
        timezone: typing.Optional[str] = OMIT,
        voice_id: typing.Optional[str] = OMIT,
        audio_format: typing.Optional[CreateAgentRequestAudioFormat] = OMIT,
        audio_speed: typing.Optional[float] = OMIT,
        background_noise_level: typing.Optional[float] = OMIT,
        background_noise: typing.Optional[CreateAgentRequestBackgroundNoise] = OMIT,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]] = OMIT,
        tasks: typing.Optional[typing.Sequence[TaskParams]] = OMIT,
        no_input_poke_sec: typing.Optional[int] = OMIT,
        no_input_poke_text: typing.Optional[str] = OMIT,
        no_input_end_conversation_sec: typing.Optional[int] = OMIT,
        languages: typing.Optional[typing.Sequence[LanguageCode]] = OMIT,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpointParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AgentsCreateResponse]:
        """
        Creates a new agent in a project.

        Parameters
        ----------
        name : str
            The name of the agent. Can only contain lowercase letters, numbers and hyphens. Must be unique within the project.

        project : typing.Optional[str]
            The name of the project to create the agent in.

        phone_number : typing.Optional[typing.Literal["assign-automatically"]]

        timezone : typing.Optional[str]
            The timezone of the agent. Used to format system variables like `{{system_time}}`.

        voice_id : typing.Optional[str]
            The voice ID to use.

        audio_format : typing.Optional[CreateAgentRequestAudioFormat]
            The audio format of the agent.

        audio_speed : typing.Optional[float]
            The audio speed of the agent.

        background_noise_level : typing.Optional[float]
            The background noise level of the agent.

        background_noise : typing.Optional[CreateAgentRequestBackgroundNoise]
            The background noise type. Can be "office", "call-center", "coffee-shop", or null.

        welcome_message : typing.Optional[str]
            Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`.

        system_prompt : typing.Optional[str]
            Instructions for the conversation. Can contain template variables like `{{subject}}`.

        template_variables : typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]]
            Variables that can be used in the welcome message and the system prompt.

        tools : typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]]
            Array of built-in or custom tool names to use.

        tasks : typing.Optional[typing.Sequence[TaskParams]]
            Array of task objects with `name` and `description` fields.

        no_input_poke_sec : typing.Optional[int]
            Number of seconds of silence before sending a poke message. `null` disables the poke message.

        no_input_poke_text : typing.Optional[str]
            The message to send after the specified silence.

        no_input_end_conversation_sec : typing.Optional[int]
            Seconds of silence before ending the conversation.

        languages : typing.Optional[typing.Sequence[LanguageCode]]
            Array of ISO 639-1 language codes that the agent should be able to recognize

        boosted_keywords : typing.Optional[typing.Sequence[str]]
            These words, or short phrases, will be more accurately recognized by the agent.

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpointParams]
            When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint when to get configuration options.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AgentsCreateResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "agents",
            base_url=self._client_wrapper.get_environment().base,
            method="POST",
            params={
                "project": project,
            },
            json={
                "name": name,
                "phone_number": phone_number,
                "timezone": timezone,
                "voice_id": voice_id,
                "audio_format": audio_format,
                "audio_speed": audio_speed,
                "background_noise_level": background_noise_level,
                "background_noise": background_noise,
                "welcome_message": welcome_message,
                "system_prompt": system_prompt,
                "template_variables": convert_and_respect_annotation_metadata(
                    object_=template_variables,
                    annotation=typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams],
                    direction="write",
                ),
                "tools": convert_and_respect_annotation_metadata(
                    object_=tools, annotation=typing.Sequence[CreateAgentRequestToolsItemParams], direction="write"
                ),
                "tasks": convert_and_respect_annotation_metadata(
                    object_=tasks, annotation=typing.Sequence[TaskParams], direction="write"
                ),
                "no_input_poke_sec": no_input_poke_sec,
                "no_input_poke_text": no_input_poke_text,
                "no_input_end_conversation_sec": no_input_end_conversation_sec,
                "languages": languages,
                "boosted_keywords": boosted_keywords,
                "configuration_endpoint": convert_and_respect_annotation_metadata(
                    object_=configuration_endpoint,
                    annotation=typing.Optional[CreateAgentRequestConfigurationEndpointParams],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsCreateResponse,
                    parse_obj_as(
                        type_=AgentsCreateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 401:
                raise UnauthorizedError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BasicError,
                        parse_obj_as(
                            type_=BasicError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 500:
                raise InternalServerError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        BasicError,
                        parse_obj_as(
                            type_=BasicError,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def upsert(
        self,
        *,
        name: str,
        project: typing.Optional[str] = None,
        phone_number: typing.Optional[typing.Literal["assign-automatically"]] = OMIT,
        timezone: typing.Optional[str] = OMIT,
        voice_id: typing.Optional[str] = OMIT,
        audio_format: typing.Optional[CreateAgentRequestAudioFormat] = OMIT,
        audio_speed: typing.Optional[float] = OMIT,
        background_noise_level: typing.Optional[float] = OMIT,
        background_noise: typing.Optional[CreateAgentRequestBackgroundNoise] = OMIT,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]] = OMIT,
        tasks: typing.Optional[typing.Sequence[TaskParams]] = OMIT,
        no_input_poke_sec: typing.Optional[int] = OMIT,
        no_input_poke_text: typing.Optional[str] = OMIT,
        no_input_end_conversation_sec: typing.Optional[int] = OMIT,
        languages: typing.Optional[typing.Sequence[LanguageCode]] = OMIT,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpointParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AgentsUpsertResponse]:
        """
        Upserts an agent by name. If an agent with the same name already exists, it will be updated. Otherwise, it will be created.

        Parameters
        ----------
        name : str
            The name of the agent. Can only contain lowercase letters, numbers and hyphens. Must be unique within the project.

        project : typing.Optional[str]
            The name of the project containing the agent.

        phone_number : typing.Optional[typing.Literal["assign-automatically"]]

        timezone : typing.Optional[str]
            The timezone of the agent. Used to format system variables like `{{system_time}}`.

        voice_id : typing.Optional[str]
            The voice ID to use.

        audio_format : typing.Optional[CreateAgentRequestAudioFormat]
            The audio format of the agent.

        audio_speed : typing.Optional[float]
            The audio speed of the agent.

        background_noise_level : typing.Optional[float]
            The background noise level of the agent.

        background_noise : typing.Optional[CreateAgentRequestBackgroundNoise]
            The background noise type. Can be "office", "call-center", "coffee-shop", or null.

        welcome_message : typing.Optional[str]
            Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`.

        system_prompt : typing.Optional[str]
            Instructions for the conversation. Can contain template variables like `{{subject}}`.

        template_variables : typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams]]
            Variables that can be used in the welcome message and the system prompt.

        tools : typing.Optional[typing.Sequence[CreateAgentRequestToolsItemParams]]
            Array of built-in or custom tool names to use.

        tasks : typing.Optional[typing.Sequence[TaskParams]]
            Array of task objects with `name` and `description` fields.

        no_input_poke_sec : typing.Optional[int]
            Number of seconds of silence before sending a poke message. `null` disables the poke message.

        no_input_poke_text : typing.Optional[str]
            The message to send after the specified silence.

        no_input_end_conversation_sec : typing.Optional[int]
            Seconds of silence before ending the conversation.

        languages : typing.Optional[typing.Sequence[LanguageCode]]
            Array of ISO 639-1 language codes that the agent should be able to recognize

        boosted_keywords : typing.Optional[typing.Sequence[str]]
            These words, or short phrases, will be more accurately recognized by the agent.

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpointParams]
            When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint when to get configuration options.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AgentsUpsertResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            "agents/upsert",
            base_url=self._client_wrapper.get_environment().base,
            method="PUT",
            params={
                "project": project,
            },
            json={
                "name": name,
                "phone_number": phone_number,
                "timezone": timezone,
                "voice_id": voice_id,
                "audio_format": audio_format,
                "audio_speed": audio_speed,
                "background_noise_level": background_noise_level,
                "background_noise": background_noise,
                "welcome_message": welcome_message,
                "system_prompt": system_prompt,
                "template_variables": convert_and_respect_annotation_metadata(
                    object_=template_variables,
                    annotation=typing.Dict[str, CreateAgentRequestTemplateVariablesValueParams],
                    direction="write",
                ),
                "tools": convert_and_respect_annotation_metadata(
                    object_=tools, annotation=typing.Sequence[CreateAgentRequestToolsItemParams], direction="write"
                ),
                "tasks": convert_and_respect_annotation_metadata(
                    object_=tasks, annotation=typing.Sequence[TaskParams], direction="write"
                ),
                "no_input_poke_sec": no_input_poke_sec,
                "no_input_poke_text": no_input_poke_text,
                "no_input_end_conversation_sec": no_input_end_conversation_sec,
                "languages": languages,
                "boosted_keywords": boosted_keywords,
                "configuration_endpoint": convert_and_respect_annotation_metadata(
                    object_=configuration_endpoint,
                    annotation=typing.Optional[CreateAgentRequestConfigurationEndpointParams],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsUpsertResponse,
                    parse_obj_as(
                        type_=AgentsUpsertResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AgentsGetResponse]:
        """
        Returns an agent by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the agent to get.

        project : typing.Optional[str]
            The name of the project containing the agent. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AgentsGetResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"agents/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsGetResponse,
                    parse_obj_as(
                        type_=AgentsGetResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AgentsDeleteResponse]:
        """
        Deletes an agent by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the agent to delete.

        project : typing.Optional[str]
            The name of the project containing the agent. Only used when `nameOrId` is a name.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AgentsDeleteResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"agents/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="DELETE",
            params={
                "project": project,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsDeleteResponse,
                    parse_obj_as(
                        type_=AgentsDeleteResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)

    async def update(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        name: typing.Optional[str] = OMIT,
        phone_number: typing.Optional[typing.Literal["assign-automatically"]] = OMIT,
        timezone: typing.Optional[str] = OMIT,
        voice_id: typing.Optional[str] = OMIT,
        audio_format: typing.Optional[UpdateAgentRequestAudioFormat] = OMIT,
        audio_speed: typing.Optional[float] = OMIT,
        background_noise_level: typing.Optional[float] = OMIT,
        background_noise: typing.Optional[UpdateAgentRequestBackgroundNoise] = OMIT,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, UpdateAgentRequestTemplateVariablesValueParams]] = OMIT,
        tools: typing.Optional[typing.Sequence[UpdateAgentRequestToolsItemParams]] = OMIT,
        tasks: typing.Optional[typing.Sequence[TaskParams]] = OMIT,
        no_input_poke_sec: typing.Optional[int] = OMIT,
        no_input_poke_text: typing.Optional[str] = OMIT,
        no_input_end_conversation_sec: typing.Optional[int] = OMIT,
        languages: typing.Optional[typing.Sequence[LanguageCode]] = OMIT,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[UpdateAgentRequestConfigurationEndpointParams] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[AgentsUpdateResponse]:
        """
        Updates an agent by name or ID.

        Parameters
        ----------
        name_or_id : str
            The name or the ID of the agent to update.

        project : typing.Optional[str]
            The name of the project containing the agent. Only used when `nameOrId` is a name.

        name : typing.Optional[str]
            The name of the agent. Can only contain lowercase letters, numbers and hyphens. Must be unique within the project.

        phone_number : typing.Optional[typing.Literal["assign-automatically"]]

        timezone : typing.Optional[str]
            The timezone of the agent. Used to format system variables like `{{system_time}}`.

        voice_id : typing.Optional[str]
            The voice ID to use.

        audio_format : typing.Optional[UpdateAgentRequestAudioFormat]
            The audio format of the agent.

        audio_speed : typing.Optional[float]
            The audio speed of the agent.

        background_noise_level : typing.Optional[float]
            The background noise level of the agent.

        background_noise : typing.Optional[UpdateAgentRequestBackgroundNoise]
            The background noise type. Can be "office", "call-center", "coffee-shop", or null.

        welcome_message : typing.Optional[str]
            Message to play when the conversation starts. Can contain template variables like `{{customer_name}}`.

        system_prompt : typing.Optional[str]
            Instructions for the conversation. Can contain template variables like `{{subject}}`.

        template_variables : typing.Optional[typing.Dict[str, UpdateAgentRequestTemplateVariablesValueParams]]
            Variables that can be used in the welcome message and the system prompt.

        tools : typing.Optional[typing.Sequence[UpdateAgentRequestToolsItemParams]]
            Array of built-in or custom tool names to use.

        tasks : typing.Optional[typing.Sequence[TaskParams]]
            Array of task objects with `name` and `description` fields.

        no_input_poke_sec : typing.Optional[int]
            Number of seconds of silence before sending a poke message. `null` disables the poke message.

        no_input_poke_text : typing.Optional[str]
            The message to send after the specified silence.

        no_input_end_conversation_sec : typing.Optional[int]
            Seconds of silence before ending the conversation.

        languages : typing.Optional[typing.Sequence[LanguageCode]]
            Array of ISO 639-1 language codes that the agent should be able to recognize

        boosted_keywords : typing.Optional[typing.Sequence[str]]
            These words, or short phrases, will be more accurately recognized by the agent.

        configuration_endpoint : typing.Optional[UpdateAgentRequestConfigurationEndpointParams]
            When not `null`, at the beginning of the conversation the agent will make a POST request to this endpoint when to get configuration options.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        AsyncHttpResponse[AgentsUpdateResponse]
            Success response
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"agents/{jsonable_encoder(name_or_id)}",
            base_url=self._client_wrapper.get_environment().base,
            method="PATCH",
            params={
                "project": project,
            },
            json={
                "name": name,
                "phone_number": phone_number,
                "timezone": timezone,
                "voice_id": voice_id,
                "audio_format": audio_format,
                "audio_speed": audio_speed,
                "background_noise_level": background_noise_level,
                "background_noise": background_noise,
                "welcome_message": welcome_message,
                "system_prompt": system_prompt,
                "template_variables": convert_and_respect_annotation_metadata(
                    object_=template_variables,
                    annotation=typing.Dict[str, UpdateAgentRequestTemplateVariablesValueParams],
                    direction="write",
                ),
                "tools": convert_and_respect_annotation_metadata(
                    object_=tools, annotation=typing.Sequence[UpdateAgentRequestToolsItemParams], direction="write"
                ),
                "tasks": convert_and_respect_annotation_metadata(
                    object_=tasks, annotation=typing.Sequence[TaskParams], direction="write"
                ),
                "no_input_poke_sec": no_input_poke_sec,
                "no_input_poke_text": no_input_poke_text,
                "no_input_end_conversation_sec": no_input_end_conversation_sec,
                "languages": languages,
                "boosted_keywords": boosted_keywords,
                "configuration_endpoint": convert_and_respect_annotation_metadata(
                    object_=configuration_endpoint,
                    annotation=typing.Optional[UpdateAgentRequestConfigurationEndpointParams],
                    direction="write",
                ),
            },
            headers={
                "content-type": "application/json",
            },
            request_options=request_options,
            omit=OMIT,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    AgentsUpdateResponse,
                    parse_obj_as(
                        type_=AgentsUpdateResponse,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 403:
                raise ForbiddenError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            if _response.status_code == 404:
                raise NotFoundError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Optional[typing.Any],
                        parse_obj_as(
                            type_=typing.Optional[typing.Any],  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
