|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | 3 | from decimal import Decimal |
4 | | -from typing import TYPE_CHECKING, Annotated, Any |
| 4 | +from typing import Annotated, Any |
5 | 5 |
|
6 | 6 | from pydantic import BaseModel, ConfigDict |
7 | 7 | from pydantic import Field as PydanticField |
8 | | -from sqlalchemy import func, select |
9 | 8 |
|
10 | | -from intentkit.config.db import get_session |
11 | | -from intentkit.models.agent.db import AgentTable |
12 | | -from intentkit.models.agent.example import AgentExample |
13 | | -from intentkit.utils.error import IntentKitAPIError |
14 | 9 |
|
15 | | -if TYPE_CHECKING: |
16 | | - from intentkit.models.agent.agent import Agent |
| 10 | +class AgentExample(BaseModel): |
| 11 | + """Agent example configuration.""" |
| 12 | + |
| 13 | + name: Annotated[ |
| 14 | + str, |
| 15 | + PydanticField( |
| 16 | + description="Name of the example", |
| 17 | + max_length=50, |
| 18 | + json_schema_extra={ |
| 19 | + "x-placeholder": "Add a name for the example", |
| 20 | + }, |
| 21 | + ), |
| 22 | + ] |
| 23 | + description: Annotated[ |
| 24 | + str, |
| 25 | + PydanticField( |
| 26 | + description="Description of the example", |
| 27 | + max_length=200, |
| 28 | + json_schema_extra={ |
| 29 | + "x-placeholder": "Add a short description for the example", |
| 30 | + }, |
| 31 | + ), |
| 32 | + ] |
| 33 | + prompt: Annotated[ |
| 34 | + str, |
| 35 | + PydanticField( |
| 36 | + description="Example prompt", |
| 37 | + max_length=2000, |
| 38 | + json_schema_extra={ |
| 39 | + "x-placeholder": "The prompt will be sent to the agent", |
| 40 | + }, |
| 41 | + ), |
| 42 | + ] |
17 | 43 |
|
18 | 44 |
|
19 | 45 | class AgentPublicInfo(BaseModel): |
@@ -132,72 +158,3 @@ class AgentPublicInfo(BaseModel): |
132 | 158 | description="Public extra data of the agent", |
133 | 159 | ), |
134 | 160 | ] |
135 | | - |
136 | | - async def update(self, agent_id: str) -> "Agent": |
137 | | - """Update agent public info with only the fields that are explicitly provided. |
138 | | -
|
139 | | - This method only updates fields that are explicitly set in this instance, |
140 | | - leaving other fields unchanged. This is more efficient than override as it |
141 | | - reduces context usage and minimizes the risk of accidentally changing fields. |
142 | | -
|
143 | | - Args: |
144 | | - agent_id: The ID of the agent to update |
145 | | -
|
146 | | - Returns: |
147 | | - The updated Agent instance |
148 | | - """ |
149 | | - from intentkit.models.agent.agent import Agent |
150 | | - |
151 | | - async with get_session() as session: |
152 | | - result = await session.execute( |
153 | | - select(AgentTable).where(AgentTable.id == agent_id) |
154 | | - ) |
155 | | - db_agent = result.scalar_one_or_none() |
156 | | - |
157 | | - if not db_agent: |
158 | | - raise IntentKitAPIError(404, "NotFound", f"Agent {agent_id} not found") |
159 | | - |
160 | | - update_data = self.model_dump(exclude_unset=True) |
161 | | - |
162 | | - for key, value in update_data.items(): |
163 | | - if hasattr(db_agent, key): |
164 | | - setattr(db_agent, key, value) |
165 | | - |
166 | | - db_agent.public_info_updated_at = func.now() |
167 | | - |
168 | | - await session.commit() |
169 | | - await session.refresh(db_agent) |
170 | | - |
171 | | - return Agent.model_validate(db_agent) |
172 | | - |
173 | | - async def override(self, agent_id: str) -> "Agent": |
174 | | - """Override agent public info with all fields from this instance. |
175 | | -
|
176 | | - Args: |
177 | | - agent_id: The ID of the agent to override |
178 | | -
|
179 | | - Returns: |
180 | | - The updated Agent instance |
181 | | - """ |
182 | | - from intentkit.models.agent.agent import Agent |
183 | | - |
184 | | - async with get_session() as session: |
185 | | - result = await session.execute( |
186 | | - select(AgentTable).where(AgentTable.id == agent_id) |
187 | | - ) |
188 | | - db_agent = result.scalar_one_or_none() |
189 | | - |
190 | | - if not db_agent: |
191 | | - raise IntentKitAPIError(404, "NotFound", f"Agent {agent_id} not found") |
192 | | - |
193 | | - update_data = self.model_dump() |
194 | | - for key, value in update_data.items(): |
195 | | - if hasattr(db_agent, key): |
196 | | - setattr(db_agent, key, value) |
197 | | - |
198 | | - db_agent.public_info_updated_at = func.now() |
199 | | - |
200 | | - await session.commit() |
201 | | - await session.refresh(db_agent) |
202 | | - |
203 | | - return Agent.model_validate(db_agent) |
0 commit comments