intentkit 0.7.5.dev9__py3-none-any.whl → 0.7.5.dev11__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of intentkit might be problematic. Click here for more details.

intentkit/__init__.py CHANGED
@@ -3,7 +3,7 @@
3
3
  A powerful platform for building AI agents with blockchain and cryptocurrency capabilities.
4
4
  """
5
5
 
6
- __version__ = "0.7.5-dev9"
6
+ __version__ = "0.7.5-dev11"
7
7
  __author__ = "hyacinthus"
8
8
  __email__ = "hyacinthus@gmail.com"
9
9
 
intentkit/core/agent.py CHANGED
@@ -2,7 +2,7 @@ import logging
2
2
  import time
3
3
  from datetime import datetime, timedelta, timezone
4
4
  from decimal import Decimal
5
- from typing import Any, Dict, List, Optional
5
+ from typing import Any, Dict, List, Optional, Tuple
6
6
 
7
7
  from sqlalchemy import func, select, text, update
8
8
 
@@ -193,53 +193,35 @@ def send_agent_notification(agent: Agent, agent_data: AgentData, message: str) -
193
193
  )
194
194
 
195
195
 
196
- async def deploy_agent(
196
+ async def override_agent(
197
197
  agent_id: str, agent: AgentUpdate, owner: Optional[str] = None
198
- ) -> Agent:
199
- """Override an existing agent.
198
+ ) -> Tuple[Agent, AgentData]:
199
+ """Override an existing agent with new configuration.
200
200
 
201
- Use input to override agent configuration. If some fields are not provided, they will be reset to default values.
201
+ This function updates an existing agent with the provided configuration.
202
+ If some fields are not provided, they will be reset to default values.
202
203
 
203
204
  Args:
204
- agent_id: ID of the agent to update
205
- agent: Agent update configuration
206
- owner: Optional owner for the agent
205
+ agent_id: ID of the agent to override
206
+ agent: Agent update configuration containing the new settings
207
+ owner: Optional owner for permission validation
207
208
 
208
209
  Returns:
209
210
  tuple[Agent, AgentData]: Updated agent configuration and processed agent data
210
211
 
211
212
  Raises:
212
- HTTPException:
213
- - 400: Invalid agent ID format
213
+ IntentKitAPIError:
214
214
  - 404: Agent not found
215
215
  - 403: Permission denied (if owner mismatch)
216
- - 500: Database error
216
+ - 400: Invalid configuration or wallet provider change
217
217
  """
218
218
  existing_agent = await Agent.get(agent_id)
219
-
220
219
  if not existing_agent:
221
- new_agent = AgentCreate.model_validate(agent)
222
- new_agent.id = agent_id
223
- if owner:
224
- new_agent.owner = owner
225
- else:
226
- new_agent.owner = "system"
227
- # Check for existing agent by upstream_id, forward compatibility, raise error after 3.0
228
- existing = await new_agent.get_by_upstream_id()
229
- if existing:
230
- raise IntentKitAPIError(
231
- status_code=400,
232
- key="BadRequest",
233
- message="Agent with this upstream ID already exists",
234
- )
235
-
236
- # Create new agent
237
- latest_agent = await new_agent.create()
238
- agent_data = await process_agent_wallet(latest_agent)
239
- send_agent_notification(latest_agent, agent_data, "Agent Deployed")
240
-
241
- return latest_agent, agent_data
242
-
220
+ raise IntentKitAPIError(
221
+ status_code=404,
222
+ key="AgentNotFound",
223
+ message=f"Agent with ID '{agent_id}' not found",
224
+ )
243
225
  if owner and owner != existing_agent.owner:
244
226
  raise IntentKitAPIError(403, "Forbidden", "forbidden")
245
227
 
@@ -253,6 +235,79 @@ async def deploy_agent(
253
235
  return latest_agent, agent_data
254
236
 
255
237
 
238
+ async def create_agent(agent: AgentCreate) -> Tuple[Agent, AgentData]:
239
+ """Create a new agent with the provided configuration.
240
+
241
+ This function creates a new agent instance with the given configuration,
242
+ initializes its wallet, and sends a notification about the creation.
243
+
244
+ Args:
245
+ agent: Agent creation configuration containing all necessary settings
246
+
247
+ Returns:
248
+ tuple[Agent, AgentData]: Created agent configuration and processed agent data
249
+
250
+ Raises:
251
+ IntentKitAPIError:
252
+ - 400: Agent with upstream ID already exists or invalid configuration
253
+ - 500: Database error or wallet initialization failure
254
+ """
255
+ if not agent.owner:
256
+ agent.owner = "system"
257
+ # Check for existing agent by upstream_id, forward compatibility, raise error after 3.0
258
+ existing = await agent.get_by_upstream_id()
259
+ if existing:
260
+ raise IntentKitAPIError(
261
+ status_code=400,
262
+ key="BadRequest",
263
+ message="Agent with this upstream ID already exists",
264
+ )
265
+
266
+ # Create new agent
267
+ latest_agent = await agent.create()
268
+ agent_data = await process_agent_wallet(latest_agent)
269
+ send_agent_notification(latest_agent, agent_data, "Agent Deployed")
270
+
271
+ return latest_agent, agent_data
272
+
273
+
274
+ async def deploy_agent(
275
+ agent_id: str, agent: AgentUpdate, owner: Optional[str] = None
276
+ ) -> Tuple[Agent, AgentData]:
277
+ """Deploy an agent by first attempting to override, then creating if not found.
278
+
279
+ This function first tries to override an existing agent. If the agent is not found
280
+ (404 error), it will create a new agent instead.
281
+
282
+ Args:
283
+ agent_id: ID of the agent to deploy
284
+ agent: Agent configuration data
285
+ owner: Optional owner for the agent
286
+
287
+ Returns:
288
+ tuple[Agent, AgentData]: Deployed agent configuration and processed agent data
289
+
290
+ Raises:
291
+ IntentKitAPIError:
292
+ - 400: Invalid agent configuration or upstream ID conflict
293
+ - 403: Permission denied (if owner mismatch)
294
+ - 500: Database error
295
+ """
296
+ try:
297
+ # First try to override the existing agent
298
+ return await override_agent(agent_id, agent, owner)
299
+ except IntentKitAPIError as e:
300
+ # If agent not found (404), create a new one
301
+ if e.status_code == 404:
302
+ new_agent = AgentCreate.model_validate(agent)
303
+ new_agent.id = agent_id
304
+ new_agent.owner = owner
305
+ return await create_agent(new_agent)
306
+ else:
307
+ # Re-raise other errors
308
+ raise
309
+
310
+
256
311
  async def agent_action_cost(agent_id: str) -> Dict[str, Decimal]:
257
312
  """
258
313
  Calculate various action cost metrics for an agent based on past three days of credit events.
intentkit/core/engine.py CHANGED
@@ -17,7 +17,7 @@ import textwrap
17
17
  import time
18
18
  import traceback
19
19
  from datetime import datetime
20
- from typing import Optional
20
+ from typing import Optional, Tuple
21
21
 
22
22
  import sqlalchemy
23
23
  from epyxid import XID
@@ -211,7 +211,7 @@ async def initialize_agent(aid, is_private=False):
211
211
 
212
212
  async def agent_executor(
213
213
  agent_id: str, is_private: bool
214
- ) -> (CompiledStateGraph, float):
214
+ ) -> Tuple[CompiledStateGraph, float]:
215
215
  start = time.perf_counter()
216
216
  agent = await Agent.get(agent_id)
217
217
  if not agent:
intentkit/models/agent.py CHANGED
@@ -34,6 +34,7 @@ from sqlalchemy import (
34
34
  select,
35
35
  )
36
36
  from sqlalchemy.dialects.postgresql import JSON, JSONB
37
+ from sqlalchemy.exc import IntegrityError
37
38
  from sqlalchemy.ext.asyncio import AsyncSession
38
39
 
39
40
  logger = logging.getLogger(__name__)
@@ -960,12 +961,20 @@ class AgentCreate(AgentUpdate):
960
961
  self.validate_autonomous_schedule()
961
962
 
962
963
  async with get_session() as db:
963
- db_agent = AgentTable(**self.model_dump())
964
- db_agent.version = self.hash()
965
- db.add(db_agent)
966
- await db.commit()
967
- await db.refresh(db_agent)
968
- return Agent.model_validate(db_agent)
964
+ try:
965
+ db_agent = AgentTable(**self.model_dump())
966
+ db_agent.version = self.hash()
967
+ db.add(db_agent)
968
+ await db.commit()
969
+ await db.refresh(db_agent)
970
+ return Agent.model_validate(db_agent)
971
+ except IntegrityError:
972
+ await db.rollback()
973
+ raise IntentKitAPIError(
974
+ status_code=400,
975
+ key="AgentExists",
976
+ message=f"Agent with ID '{self.id}' already exists",
977
+ )
969
978
 
970
979
 
971
980
  class AgentPublicInfo(BaseModel):
@@ -1509,16 +1518,16 @@ class AgentResponse(Agent):
1509
1518
  )
1510
1519
 
1511
1520
  # Override privacy fields to exclude them from JSON schema
1512
- purpose: Annotated[Optional[str], SkipJsonSchema] = None
1513
- personality: Annotated[Optional[str], SkipJsonSchema] = None
1514
- principles: Annotated[Optional[str], SkipJsonSchema] = None
1515
- prompt: Annotated[Optional[str], SkipJsonSchema] = None
1516
- prompt_append: Annotated[Optional[str], SkipJsonSchema] = None
1517
- temperature: Annotated[Optional[float], SkipJsonSchema] = None
1518
- frequency_penalty: Annotated[Optional[float], SkipJsonSchema] = None
1519
- telegram_entrypoint_prompt: Annotated[Optional[str], SkipJsonSchema] = None
1520
- telegram_config: Annotated[Optional[dict], SkipJsonSchema] = None
1521
- xmtp_entrypoint_prompt: Annotated[Optional[str], SkipJsonSchema] = None
1521
+ purpose: SkipJsonSchema[Optional[str]] = None
1522
+ personality: SkipJsonSchema[Optional[str]] = None
1523
+ principles: SkipJsonSchema[Optional[str]] = None
1524
+ prompt: SkipJsonSchema[Optional[str]] = None
1525
+ prompt_append: SkipJsonSchema[Optional[str]] = None
1526
+ temperature: SkipJsonSchema[Optional[float]] = None
1527
+ frequency_penalty: SkipJsonSchema[Optional[float]] = None
1528
+ telegram_entrypoint_prompt: SkipJsonSchema[Optional[str]] = None
1529
+ telegram_config: SkipJsonSchema[Optional[dict]] = None
1530
+ xmtp_entrypoint_prompt: SkipJsonSchema[Optional[str]] = None
1522
1531
 
1523
1532
  # Additional fields specific to AgentResponse
1524
1533
  cdp_wallet_address: Annotated[
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: intentkit
3
- Version: 0.7.5.dev9
3
+ Version: 0.7.5.dev11
4
4
  Summary: Intent-based AI Agent Platform - Core Package
5
5
  Project-URL: Homepage, https://github.com/crestalnetwork/intentkit
6
6
  Project-URL: Repository, https://github.com/crestalnetwork/intentkit
@@ -1,4 +1,4 @@
1
- intentkit/__init__.py,sha256=46rAmnU-MtPUs_PFUOeb2d-ZfnXhp7RJIABBbN6sLgE,383
1
+ intentkit/__init__.py,sha256=EYPVd8Rl-a6Z7xAISRwBQt7ZOsItVNtwbK-ykpuZSZM,384
2
2
  intentkit/abstracts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  intentkit/abstracts/agent.py,sha256=108gb5W8Q1Sy4G55F2_ZFv2-_CnY76qrBtpIr0Oxxqk,1489
4
4
  intentkit/abstracts/api.py,sha256=ZUc24vaQvQVbbjznx7bV0lbbQxdQPfEV8ZxM2R6wZWo,166
@@ -13,15 +13,15 @@ intentkit/clients/web3.py,sha256=A-w4vBPXHpDh8svsEFj_LkmvRgoDTZw4E-84S-UC9ws,102
13
13
  intentkit/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
14
  intentkit/config/config.py,sha256=xDbm5KSXt4rZh2Nak0bmrYv5Rf__mJz8aJ9PHzar-Lk,8941
15
15
  intentkit/core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
- intentkit/core/agent.py,sha256=BMCcBdxbewSJFk3VfJwEWbQks5k0Fg7LsnqRTsCEExY,30006
16
+ intentkit/core/agent.py,sha256=d7P116dG4rmBu0zUF_WuHhcUgUOnaOhhYVzgKymOKZI,32047
17
17
  intentkit/core/api.py,sha256=WfoaHNquujYJIpNPuTR1dSaaxog0S3X2W4lG9Ehmkm4,3284
18
18
  intentkit/core/chat.py,sha256=YN20CnDazWLjiOZFOHgV6uHmA2DKkvPCsD5Q5sfNcZg,1685
19
19
  intentkit/core/client.py,sha256=J5K7f08-ucszBKAbn9K3QNOFKIC__7amTbKYii1jFkI,3056
20
20
  intentkit/core/credit.py,sha256=b4f4T6G6eeBTMe0L_r8awWtXgUnqiog4IUaymDPYym0,75587
21
- intentkit/core/engine.py,sha256=mnsaQqRz1NBgg5Tc0vynDCLwn4G_fbpvCbuVv-7Q15g,36165
21
+ intentkit/core/engine.py,sha256=DoGqfhNK35sFeqMlFLyKR_NUDf1YXf4yihSfw7kufmU,36177
22
22
  intentkit/core/node.py,sha256=7h9zgDSd928bzUi3m3EZnKkhbwqlbRAQUr_uz7gKB5Y,8880
23
23
  intentkit/core/prompt.py,sha256=ssiyKHDNIjQOLU0KwUlIFX3jy51TqgeKOxrwnW4HBkw,15875
24
- intentkit/models/agent.py,sha256=PgNNa9QqmqAEOqvJoIZxGWE-JrgFAe3VEdD0EUgaZSM,67182
24
+ intentkit/models/agent.py,sha256=JGQcDvqQFaIbCKqGTHNFkBLFAFCHpeJU4WRlDGG6830,67434
25
25
  intentkit/models/agent_data.py,sha256=5zq3EPKnygT2P1OHc2IfEmL8hXkjeBND6sJ0JJsvQJg,28370
26
26
  intentkit/models/agent_public.json,sha256=0X8Bd2WOobDJLsok8avWNzmzu4uvKSGEyy6Myn53eT4,2802
27
27
  intentkit/models/agent_schema.json,sha256=hFGUE57JIiN8V4olgLf2LBXPejA2QLiQoFc6riM1UFo,17139
@@ -418,7 +418,7 @@ intentkit/utils/random.py,sha256=DymMxu9g0kuQLgJUqalvgksnIeLdS-v0aRk5nQU0mLI,452
418
418
  intentkit/utils/s3.py,sha256=9trQNkKQ5VgxWsewVsV8Y0q_pXzGRvsCYP8xauyUYkg,8549
419
419
  intentkit/utils/slack_alert.py,sha256=s7UpRgyzLW7Pbmt8cKzTJgMA9bm4EP-1rQ5KXayHu6E,2264
420
420
  intentkit/utils/tx.py,sha256=2yLLGuhvfBEY5n_GJ8wmIWLCzn0FsYKv5kRNzw_sLUI,1454
421
- intentkit-0.7.5.dev9.dist-info/METADATA,sha256=98yN0Ivapq5xqDvUIkUdtkTqQLMGjX3NqyBtL6RNBJs,6409
422
- intentkit-0.7.5.dev9.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
423
- intentkit-0.7.5.dev9.dist-info/licenses/LICENSE,sha256=Bln6DhK-LtcO4aXy-PBcdZv2f24MlJFm_qn222biJtE,1071
424
- intentkit-0.7.5.dev9.dist-info/RECORD,,
421
+ intentkit-0.7.5.dev11.dist-info/METADATA,sha256=BU2Ep_Nz6XTx27neRFSFT8k48caRCA2qJI4ryttgJcY,6410
422
+ intentkit-0.7.5.dev11.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
423
+ intentkit-0.7.5.dev11.dist-info/licenses/LICENSE,sha256=Bln6DhK-LtcO4aXy-PBcdZv2f24MlJFm_qn222biJtE,1071
424
+ intentkit-0.7.5.dev11.dist-info/RECORD,,