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

import typing

import pydantic
from ...core.pydantic_utilities import IS_PYDANTIC_V2
from ...core.unchecked_base_model import UncheckedBaseModel
from .start_agents_request_properties_llm_greeting_configs import StartAgentsRequestPropertiesLlmGreetingConfigs
from .start_agents_request_properties_llm_mcp_servers_item import StartAgentsRequestPropertiesLlmMcpServersItem
from .start_agents_request_properties_llm_style import StartAgentsRequestPropertiesLlmStyle


class StartAgentsRequestPropertiesLlm(UncheckedBaseModel):
    """
    Large language model (LLM) configuration.
    """

    url: str = pydantic.Field()
    """
    The LLM callback address.
    """

    api_key: typing.Optional[str] = pydantic.Field(default=None)
    """
    The LLM verification API key. The default value is an empty string. Ensure that you enable the API key in a production environment.
    """

    system_messages: typing.Optional[typing.List[typing.Dict[str, typing.Any]]] = pydantic.Field(default=None)
    """
    A set of predefined information used as input to the LLM, including prompt words and examples.
    """

    params: typing.Optional[typing.Dict[str, typing.Any]] = pydantic.Field(default=None)
    """
    Additional LLM configuration parameters, such as the `model` used, and the maximum token limit. For details about each supported LLM, refer to [Supported LLMs](https://docs.agora.io/en/conversational-ai/models/llm/overview#supported-llms).
    """

    max_history: typing.Optional[int] = pydantic.Field(default=None)
    """
    The number of conversation history messages cached in the custom LLM. History includes user and agent dialog messages, tool call information, and timestamps. Agent and user messages are recorded separately.
    """

    input_modalities: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    LLM input modalities:
    - `["text"]`: Text only
    - `["text", "image"]`: Text plus image; requires the selected LLM to support visual input
    """

    output_modalities: typing.Optional[typing.List[str]] = pydantic.Field(default=None)
    """
    LLM output modalities:
    - `["text"]`: The output text is converted to speech by the TTS module and then published to the RTC channel.
    - `["audio"]`: Voice only. Voice is published directly to the RTC channel.
    - `["text", "audio"]`: Text plus voice. Write your own logic to process the output of LLM as needed.
    """

    greeting_message: typing.Optional[str] = pydantic.Field(default=None)
    """
    Agent greeting. If provided, the first user in the channel is automatically greeted with the message upon joining.
    """

    failure_message: typing.Optional[str] = pydantic.Field(default=None)
    """
    Prompt for agent activation failure. If provided, it is returned through TTS when the custom LLM call fails.
    """

    vendor: typing.Optional[str] = pydantic.Field(default=None)
    """
    LLM provider, supports the following settings:
    - `custom`: Custom LLM. When you set this option, the agent includes the following fields, in addition to `role` and `content` when making requests to the custom LLM:
      - `turn_id`: A unique identifier for each conversation turn. It starts from `0` and increments with each turn. One user-agent interaction corresponds to one `turn_id`.
      - `timestamp`: The request timestamp, in milliseconds.
    - `azure`: Use this value for Azure OpenAI
    """

    style: typing.Optional[StartAgentsRequestPropertiesLlmStyle] = pydantic.Field(default=None)
    """
    The request style for chat completion:
    - `openai`: For OpenAI and OpenAI-compatible APIs
    - `gemini`: For Google Gemini and Google Vertex API format
    - `anthropic`: For Anthropic Claude API format
    - `dify`: For Dify API format
    """

    greeting_configs: typing.Optional[StartAgentsRequestPropertiesLlmGreetingConfigs] = pydantic.Field(default=None)
    """
    Agent greeting broadcast configuration.
    """

    template_variables: typing.Optional[typing.Dict[str, str]] = pydantic.Field(default=None)
    """
    Template parameter configuration used to insert variables into the agent's `system_messages`, `greeting_message`, `failure_message`, and `parameters.silence_config.content` text. Uses key-value pairs, where the key is the variable name and the value is the variable's value. To insert defined variables in the prompt text, use the syntax `{{variable_name}}`. The system automatically replaces each variable with the corresponding value defined in `template_variables`. Variable values cannot reference other variables.
    """

    mcp_servers: typing.Optional[typing.List[StartAgentsRequestPropertiesLlmMcpServersItem]] = pydantic.Field(
        default=None
    )
    """
    MCP (Model Context Protocol) server configuration. By configuring MCP servers, agents can call tools provided by external services to implement advanced functionality.
    """

    if IS_PYDANTIC_V2:
        model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True)  # type: ignore # Pydantic v2
    else:

        class Config:
            frozen = True
            smart_union = True
            extra = pydantic.Extra.allow
