# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# pyformat: disable

"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""

from __future__ import annotations
from .. import BaseModel, UNSET_SENTINEL
from ..interactions import environment as interactions_environment
from .agenttool import AgentTool, AgentToolParam
from pydantic import model_serializer
from typing import List, Optional, Union
from typing_extensions import NotRequired, TypeAliasType, TypedDict


BaseEnvironmentParam = TypeAliasType(
    "BaseEnvironmentParam", Union[interactions_environment.EnvironmentParam, str]
)
r"""The environment configuration for the agent."""


BaseEnvironment = TypeAliasType(
    "BaseEnvironment", Union[interactions_environment.Environment, str]
)
r"""The environment configuration for the agent."""


class AgentParam(TypedDict):
    r"""An agent definition for the CreateAgent API.
    This message is the target for annotation-parser-based JSON parsing.
    New format:
    {
    \"id\": \"customer-sentinel\",
    \"base_agent\": \"\",
    \"system_instruction\": \"...\",
    \"base_environment\": { \"type\": \"remote\", \"sources\": [...] },
    \"tools\": [ {\"type\": \"code_execution\"} ]
    }
    """

    base_agent: NotRequired[str]
    r"""The base agent to extend."""
    base_environment: NotRequired[BaseEnvironmentParam]
    r"""The environment configuration for the agent."""
    description: NotRequired[str]
    r"""Agent description for developers to quickly read and understand."""
    id: NotRequired[str]
    r"""The unique identifier for the agent."""
    system_instruction: NotRequired[str]
    r"""System instruction for the agent."""
    tools: NotRequired[List[AgentToolParam]]
    r"""The tools available to the agent."""


class Agent(BaseModel):
    r"""An agent definition for the CreateAgent API.
    This message is the target for annotation-parser-based JSON parsing.
    New format:
    {
    \"id\": \"customer-sentinel\",
    \"base_agent\": \"\",
    \"system_instruction\": \"...\",
    \"base_environment\": { \"type\": \"remote\", \"sources\": [...] },
    \"tools\": [ {\"type\": \"code_execution\"} ]
    }
    """

    base_agent: Optional[str] = None
    r"""The base agent to extend."""

    base_environment: Optional[BaseEnvironment] = None
    r"""The environment configuration for the agent."""

    description: Optional[str] = None
    r"""Agent description for developers to quickly read and understand."""

    id: Optional[str] = None
    r"""The unique identifier for the agent."""

    system_instruction: Optional[str] = None
    r"""System instruction for the agent."""

    tools: Optional[List[AgentTool]] = None
    r"""The tools available to the agent."""

    @model_serializer(mode="wrap")
    def serialize_model(self, handler):
        optional_fields = set(
            [
                "base_agent",
                "base_environment",
                "description",
                "id",
                "system_instruction",
                "tools",
            ]
        )
        serialized = handler(self)
        m = {}

        for n, f in type(self).model_fields.items():
            k = f.alias or n
            val = serialized.get(k, serialized.get(n))

            if val != UNSET_SENTINEL:
                if val is not None or k not in optional_fields:
                    m[k] = val

        return m
