summaryrefslogtreecommitdiffhomepage
path: root/packages/sdk/python/src/opencode_ai/models/agent.py
blob: 8044d73a09629341bfae7eb0af3c473cdc3edbbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
from collections.abc import Mapping
from typing import TYPE_CHECKING, Any, Literal, TypeVar, Union, cast

from attrs import define as _attrs_define
from attrs import field as _attrs_field

from ..types import UNSET, Unset

if TYPE_CHECKING:
    from ..models.agent_model import AgentModel
    from ..models.agent_options import AgentOptions
    from ..models.agent_permission import AgentPermission
    from ..models.agent_tools import AgentTools


T = TypeVar("T", bound="Agent")


@_attrs_define
class Agent:
    """
    Attributes:
        name (str):
        mode (Union[Literal['all'], Literal['primary'], Literal['subagent']]):
        built_in (bool):
        permission (AgentPermission):
        tools (AgentTools):
        options (AgentOptions):
        description (Union[Unset, str]):
        top_p (Union[Unset, float]):
        temperature (Union[Unset, float]):
        model (Union[Unset, AgentModel]):
        prompt (Union[Unset, str]):
    """

    name: str
    mode: Union[Literal["all"], Literal["primary"], Literal["subagent"]]
    built_in: bool
    permission: "AgentPermission"
    tools: "AgentTools"
    options: "AgentOptions"
    description: Union[Unset, str] = UNSET
    top_p: Union[Unset, float] = UNSET
    temperature: Union[Unset, float] = UNSET
    model: Union[Unset, "AgentModel"] = UNSET
    prompt: Union[Unset, str] = UNSET
    additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)

    def to_dict(self) -> dict[str, Any]:
        name = self.name

        mode: Union[Literal["all"], Literal["primary"], Literal["subagent"]]
        mode = self.mode

        built_in = self.built_in

        permission = self.permission.to_dict()

        tools = self.tools.to_dict()

        options = self.options.to_dict()

        description = self.description

        top_p = self.top_p

        temperature = self.temperature

        model: Union[Unset, dict[str, Any]] = UNSET
        if not isinstance(self.model, Unset):
            model = self.model.to_dict()

        prompt = self.prompt

        field_dict: dict[str, Any] = {}
        field_dict.update(self.additional_properties)
        field_dict.update(
            {
                "name": name,
                "mode": mode,
                "builtIn": built_in,
                "permission": permission,
                "tools": tools,
                "options": options,
            }
        )
        if description is not UNSET:
            field_dict["description"] = description
        if top_p is not UNSET:
            field_dict["topP"] = top_p
        if temperature is not UNSET:
            field_dict["temperature"] = temperature
        if model is not UNSET:
            field_dict["model"] = model
        if prompt is not UNSET:
            field_dict["prompt"] = prompt

        return field_dict

    @classmethod
    def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:
        from ..models.agent_model import AgentModel
        from ..models.agent_options import AgentOptions
        from ..models.agent_permission import AgentPermission
        from ..models.agent_tools import AgentTools

        d = dict(src_dict)
        name = d.pop("name")

        def _parse_mode(data: object) -> Union[Literal["all"], Literal["primary"], Literal["subagent"]]:
            mode_type_0 = cast(Literal["subagent"], data)
            if mode_type_0 != "subagent":
                raise ValueError(f"mode_type_0 must match const 'subagent', got '{mode_type_0}'")
            return mode_type_0
            mode_type_1 = cast(Literal["primary"], data)
            if mode_type_1 != "primary":
                raise ValueError(f"mode_type_1 must match const 'primary', got '{mode_type_1}'")
            return mode_type_1
            mode_type_2 = cast(Literal["all"], data)
            if mode_type_2 != "all":
                raise ValueError(f"mode_type_2 must match const 'all', got '{mode_type_2}'")
            return mode_type_2

        mode = _parse_mode(d.pop("mode"))

        built_in = d.pop("builtIn")

        permission = AgentPermission.from_dict(d.pop("permission"))

        tools = AgentTools.from_dict(d.pop("tools"))

        options = AgentOptions.from_dict(d.pop("options"))

        description = d.pop("description", UNSET)

        top_p = d.pop("topP", UNSET)

        temperature = d.pop("temperature", UNSET)

        _model = d.pop("model", UNSET)
        model: Union[Unset, AgentModel]
        if isinstance(_model, Unset):
            model = UNSET
        else:
            model = AgentModel.from_dict(_model)

        prompt = d.pop("prompt", UNSET)

        agent = cls(
            name=name,
            mode=mode,
            built_in=built_in,
            permission=permission,
            tools=tools,
            options=options,
            description=description,
            top_p=top_p,
            temperature=temperature,
            model=model,
            prompt=prompt,
        )

        agent.additional_properties = d
        return agent

    @property
    def additional_keys(self) -> list[str]:
        return list(self.additional_properties.keys())

    def __getitem__(self, key: str) -> Any:
        return self.additional_properties[key]

    def __setitem__(self, key: str, value: Any) -> None:
        self.additional_properties[key] = value

    def __delitem__(self, key: str) -> None:
        del self.additional_properties[key]

    def __contains__(self, key: str) -> bool:
        return key in self.additional_properties