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

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.create_agent_request_audio_format import CreateAgentRequestAudioFormat
from ..types.create_agent_request_configuration_endpoint import CreateAgentRequestConfigurationEndpoint
from ..types.create_agent_request_template_variables_value import CreateAgentRequestTemplateVariablesValue
from ..types.create_agent_request_tools_item import CreateAgentRequestToolsItem
from ..types.task import Task
from .raw_client import AsyncRawAgentsClient, RawAgentsClient
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_configuration_endpoint import UpdateAgentRequestConfigurationEndpoint
from .types.update_agent_request_template_variables_value import UpdateAgentRequestTemplateVariablesValue
from .types.update_agent_request_tools_item import UpdateAgentRequestToolsItem

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


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

    @property
    def with_raw_response(self) -> RawAgentsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawAgentsClient
        """
        return self._raw_client

    def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> 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
        -------
        AgentsListResponse
            Success response

        Examples
        --------
        from phonic import Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.agents.list()
        """
        _response = self._raw_client.list(project=project, request_options=request_options)
        return _response.data

    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,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValue]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItem]] = OMIT,
        tasks: typing.Optional[typing.Sequence[Task]] = 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,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpoint] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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.

        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, CreateAgentRequestTemplateVariablesValue]]
            Variables that can be used in the welcome message and the system prompt.

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

        tasks : typing.Optional[typing.Sequence[Task]]
            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.

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

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpoint]
            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
        -------
        AgentsCreateResponse
            Success response

        Examples
        --------
        from phonic import (
            CreateAgentRequestConfigurationEndpoint,
            CreateAgentRequestTemplateVariablesValue,
            Phonic,
        )

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.agents.create(
            name="support-agent",
            timezone="America/Los_Angeles",
            voice_id="sarah",
            audio_speed=1.0,
            welcome_message="Hi {{customer_name}}. How can I help you today?",
            system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
            template_variables={
                "customer_name": CreateAgentRequestTemplateVariablesValue(),
                "subject": CreateAgentRequestTemplateVariablesValue(
                    default_value="Chess",
                ),
            },
            tools=[],
            no_input_poke_sec=30,
            no_input_poke_text="Are you still there?",
            boosted_keywords=["Load ID", "dispatch"],
            configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
                url="https://api.example.com/config",
                headers={"Authorization": "Bearer token123"},
                timeout_ms=7000,
            ),
        )
        """
        _response = self._raw_client.create(
            name=name,
            project=project,
            phone_number=phone_number,
            timezone=timezone,
            voice_id=voice_id,
            audio_format=audio_format,
            audio_speed=audio_speed,
            welcome_message=welcome_message,
            system_prompt=system_prompt,
            template_variables=template_variables,
            tools=tools,
            tasks=tasks,
            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,
            boosted_keywords=boosted_keywords,
            configuration_endpoint=configuration_endpoint,
            request_options=request_options,
        )
        return _response.data

    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,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValue]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItem]] = OMIT,
        tasks: typing.Optional[typing.Sequence[Task]] = 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,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpoint] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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.

        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, CreateAgentRequestTemplateVariablesValue]]
            Variables that can be used in the welcome message and the system prompt.

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

        tasks : typing.Optional[typing.Sequence[Task]]
            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.

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

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpoint]
            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
        -------
        AgentsUpsertResponse
            Success response

        Examples
        --------
        from phonic import (
            CreateAgentRequestConfigurationEndpoint,
            CreateAgentRequestTemplateVariablesValue,
            Phonic,
        )

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.agents.upsert(
            name="support-agent",
            phone_number="assign-automatically",
            timezone="America/Los_Angeles",
            voice_id="sarah",
            audio_speed=1.0,
            welcome_message="Hi {{customer_name}}. How can I help you today?",
            system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
            template_variables={
                "customer_name": CreateAgentRequestTemplateVariablesValue(),
                "subject": CreateAgentRequestTemplateVariablesValue(
                    default_value="Chess",
                ),
            },
            tools=[],
            no_input_poke_sec=30,
            no_input_poke_text="Are you still there?",
            boosted_keywords=["Load ID", "dispatch"],
            configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
                url="https://api.example.com/config",
                headers={"Authorization": "Bearer token123"},
                timeout_ms=7000,
            ),
        )
        """
        _response = self._raw_client.upsert(
            name=name,
            project=project,
            phone_number=phone_number,
            timezone=timezone,
            voice_id=voice_id,
            audio_format=audio_format,
            audio_speed=audio_speed,
            welcome_message=welcome_message,
            system_prompt=system_prompt,
            template_variables=template_variables,
            tools=tools,
            tasks=tasks,
            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,
            boosted_keywords=boosted_keywords,
            configuration_endpoint=configuration_endpoint,
            request_options=request_options,
        )
        return _response.data

    def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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
        -------
        AgentsGetResponse
            Success response

        Examples
        --------
        from phonic import Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.agents.get(
            name_or_id="nameOrId",
        )
        """
        _response = self._raw_client.get(name_or_id, project=project, request_options=request_options)
        return _response.data

    def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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
        -------
        AgentsDeleteResponse
            Success response

        Examples
        --------
        from phonic import Phonic

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.agents.delete(
            name_or_id="nameOrId",
        )
        """
        _response = self._raw_client.delete(name_or_id, project=project, request_options=request_options)
        return _response.data

    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,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, UpdateAgentRequestTemplateVariablesValue]] = OMIT,
        tools: typing.Optional[typing.Sequence[UpdateAgentRequestToolsItem]] = OMIT,
        tasks: typing.Optional[typing.Sequence[Task]] = 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,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[UpdateAgentRequestConfigurationEndpoint] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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.

        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, UpdateAgentRequestTemplateVariablesValue]]
            Variables that can be used in the welcome message and the system prompt.

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

        tasks : typing.Optional[typing.Sequence[Task]]
            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.

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

        configuration_endpoint : typing.Optional[UpdateAgentRequestConfigurationEndpoint]
            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
        -------
        AgentsUpdateResponse
            Success response

        Examples
        --------
        from phonic import Phonic
        from phonic.agents import (
            UpdateAgentRequestConfigurationEndpoint,
            UpdateAgentRequestTemplateVariablesValue,
        )

        client = Phonic(
            token="YOUR_TOKEN",
        )
        client.agents.update(
            name_or_id="nameOrId",
            name="updated-support-agent",
            phone_number="assign-automatically",
            timezone="America/Los_Angeles",
            voice_id="sarah",
            audio_speed=1.0,
            welcome_message="Hi {{customer_name}}. How can I help you today?",
            system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
            template_variables={
                "customer_name": UpdateAgentRequestTemplateVariablesValue(),
                "subject": UpdateAgentRequestTemplateVariablesValue(
                    default_value="Chess",
                ),
            },
            tools=[],
            no_input_poke_sec=30,
            no_input_poke_text="Are you still there?",
            boosted_keywords=["Load ID", "dispatch"],
            configuration_endpoint=UpdateAgentRequestConfigurationEndpoint(
                url="https://api.example.com/config",
                headers={"Authorization": "Bearer token123"},
                timeout_ms=7000,
            ),
        )
        """
        _response = self._raw_client.update(
            name_or_id,
            project=project,
            name=name,
            phone_number=phone_number,
            timezone=timezone,
            voice_id=voice_id,
            audio_format=audio_format,
            audio_speed=audio_speed,
            welcome_message=welcome_message,
            system_prompt=system_prompt,
            template_variables=template_variables,
            tools=tools,
            tasks=tasks,
            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,
            boosted_keywords=boosted_keywords,
            configuration_endpoint=configuration_endpoint,
            request_options=request_options,
        )
        return _response.data


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

    @property
    def with_raw_response(self) -> AsyncRawAgentsClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawAgentsClient
        """
        return self._raw_client

    async def list(
        self, *, project: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> 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
        -------
        AgentsListResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.list()


        asyncio.run(main())
        """
        _response = await self._raw_client.list(project=project, request_options=request_options)
        return _response.data

    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,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValue]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItem]] = OMIT,
        tasks: typing.Optional[typing.Sequence[Task]] = 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,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpoint] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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.

        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, CreateAgentRequestTemplateVariablesValue]]
            Variables that can be used in the welcome message and the system prompt.

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

        tasks : typing.Optional[typing.Sequence[Task]]
            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.

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

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpoint]
            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
        -------
        AgentsCreateResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import (
            AsyncPhonic,
            CreateAgentRequestConfigurationEndpoint,
            CreateAgentRequestTemplateVariablesValue,
        )

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.create(
                name="support-agent",
                timezone="America/Los_Angeles",
                voice_id="sarah",
                audio_speed=1.0,
                welcome_message="Hi {{customer_name}}. How can I help you today?",
                system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
                template_variables={
                    "customer_name": CreateAgentRequestTemplateVariablesValue(),
                    "subject": CreateAgentRequestTemplateVariablesValue(
                        default_value="Chess",
                    ),
                },
                tools=[],
                no_input_poke_sec=30,
                no_input_poke_text="Are you still there?",
                boosted_keywords=["Load ID", "dispatch"],
                configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
                    url="https://api.example.com/config",
                    headers={"Authorization": "Bearer token123"},
                    timeout_ms=7000,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name,
            project=project,
            phone_number=phone_number,
            timezone=timezone,
            voice_id=voice_id,
            audio_format=audio_format,
            audio_speed=audio_speed,
            welcome_message=welcome_message,
            system_prompt=system_prompt,
            template_variables=template_variables,
            tools=tools,
            tasks=tasks,
            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,
            boosted_keywords=boosted_keywords,
            configuration_endpoint=configuration_endpoint,
            request_options=request_options,
        )
        return _response.data

    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,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, CreateAgentRequestTemplateVariablesValue]] = OMIT,
        tools: typing.Optional[typing.Sequence[CreateAgentRequestToolsItem]] = OMIT,
        tasks: typing.Optional[typing.Sequence[Task]] = 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,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[CreateAgentRequestConfigurationEndpoint] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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.

        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, CreateAgentRequestTemplateVariablesValue]]
            Variables that can be used in the welcome message and the system prompt.

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

        tasks : typing.Optional[typing.Sequence[Task]]
            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.

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

        configuration_endpoint : typing.Optional[CreateAgentRequestConfigurationEndpoint]
            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
        -------
        AgentsUpsertResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import (
            AsyncPhonic,
            CreateAgentRequestConfigurationEndpoint,
            CreateAgentRequestTemplateVariablesValue,
        )

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.upsert(
                name="support-agent",
                phone_number="assign-automatically",
                timezone="America/Los_Angeles",
                voice_id="sarah",
                audio_speed=1.0,
                welcome_message="Hi {{customer_name}}. How can I help you today?",
                system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
                template_variables={
                    "customer_name": CreateAgentRequestTemplateVariablesValue(),
                    "subject": CreateAgentRequestTemplateVariablesValue(
                        default_value="Chess",
                    ),
                },
                tools=[],
                no_input_poke_sec=30,
                no_input_poke_text="Are you still there?",
                boosted_keywords=["Load ID", "dispatch"],
                configuration_endpoint=CreateAgentRequestConfigurationEndpoint(
                    url="https://api.example.com/config",
                    headers={"Authorization": "Bearer token123"},
                    timeout_ms=7000,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.upsert(
            name=name,
            project=project,
            phone_number=phone_number,
            timezone=timezone,
            voice_id=voice_id,
            audio_format=audio_format,
            audio_speed=audio_speed,
            welcome_message=welcome_message,
            system_prompt=system_prompt,
            template_variables=template_variables,
            tools=tools,
            tasks=tasks,
            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,
            boosted_keywords=boosted_keywords,
            configuration_endpoint=configuration_endpoint,
            request_options=request_options,
        )
        return _response.data

    async def get(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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
        -------
        AgentsGetResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.get(
                name_or_id="nameOrId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get(name_or_id, project=project, request_options=request_options)
        return _response.data

    async def delete(
        self,
        name_or_id: str,
        *,
        project: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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
        -------
        AgentsDeleteResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.delete(
                name_or_id="nameOrId",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete(name_or_id, project=project, request_options=request_options)
        return _response.data

    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,
        welcome_message: typing.Optional[str] = OMIT,
        system_prompt: typing.Optional[str] = OMIT,
        template_variables: typing.Optional[typing.Dict[str, UpdateAgentRequestTemplateVariablesValue]] = OMIT,
        tools: typing.Optional[typing.Sequence[UpdateAgentRequestToolsItem]] = OMIT,
        tasks: typing.Optional[typing.Sequence[Task]] = 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,
        boosted_keywords: typing.Optional[typing.Sequence[str]] = OMIT,
        configuration_endpoint: typing.Optional[UpdateAgentRequestConfigurationEndpoint] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> 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.

        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, UpdateAgentRequestTemplateVariablesValue]]
            Variables that can be used in the welcome message and the system prompt.

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

        tasks : typing.Optional[typing.Sequence[Task]]
            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.

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

        configuration_endpoint : typing.Optional[UpdateAgentRequestConfigurationEndpoint]
            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
        -------
        AgentsUpdateResponse
            Success response

        Examples
        --------
        import asyncio

        from phonic import AsyncPhonic
        from phonic.agents import (
            UpdateAgentRequestConfigurationEndpoint,
            UpdateAgentRequestTemplateVariablesValue,
        )

        client = AsyncPhonic(
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.agents.update(
                name_or_id="nameOrId",
                name="updated-support-agent",
                phone_number="assign-automatically",
                timezone="America/Los_Angeles",
                voice_id="sarah",
                audio_speed=1.0,
                welcome_message="Hi {{customer_name}}. How can I help you today?",
                system_prompt="You are an expert in {{subject}}. Be friendly, helpful and concise.",
                template_variables={
                    "customer_name": UpdateAgentRequestTemplateVariablesValue(),
                    "subject": UpdateAgentRequestTemplateVariablesValue(
                        default_value="Chess",
                    ),
                },
                tools=[],
                no_input_poke_sec=30,
                no_input_poke_text="Are you still there?",
                boosted_keywords=["Load ID", "dispatch"],
                configuration_endpoint=UpdateAgentRequestConfigurationEndpoint(
                    url="https://api.example.com/config",
                    headers={"Authorization": "Bearer token123"},
                    timeout_ms=7000,
                ),
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update(
            name_or_id,
            project=project,
            name=name,
            phone_number=phone_number,
            timezone=timezone,
            voice_id=voice_id,
            audio_format=audio_format,
            audio_speed=audio_speed,
            welcome_message=welcome_message,
            system_prompt=system_prompt,
            template_variables=template_variables,
            tools=tools,
            tasks=tasks,
            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,
            boosted_keywords=boosted_keywords,
            configuration_endpoint=configuration_endpoint,
            request_options=request_options,
        )
        return _response.data
