intentkit 0.8.11__py3-none-any.whl → 0.8.12__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.

Files changed (183) hide show
  1. intentkit/__init__.py +1 -1
  2. intentkit/abstracts/graph.py +4 -0
  3. intentkit/abstracts/skill.py +2 -140
  4. intentkit/clients/twitter.py +35 -28
  5. intentkit/core/agent.py +2 -374
  6. intentkit/core/asset.py +63 -16
  7. intentkit/core/engine.py +16 -7
  8. intentkit/core/scheduler.py +8 -8
  9. intentkit/models/agent.py +109 -94
  10. intentkit/models/agent_schema.json +6 -9
  11. intentkit/models/llm.csv +15 -12
  12. intentkit/models/skill.py +38 -40
  13. intentkit/skills/acolyt/__init__.py +2 -9
  14. intentkit/skills/acolyt/base.py +2 -5
  15. intentkit/skills/aixbt/__init__.py +2 -13
  16. intentkit/skills/aixbt/base.py +0 -4
  17. intentkit/skills/aixbt/projects.py +1 -2
  18. intentkit/skills/allora/__init__.py +2 -9
  19. intentkit/skills/allora/base.py +2 -5
  20. intentkit/skills/base.py +168 -27
  21. intentkit/skills/basename/__init__.py +1 -3
  22. intentkit/skills/carv/__init__.py +116 -121
  23. intentkit/skills/carv/base.py +184 -185
  24. intentkit/skills/casino/__init__.py +4 -15
  25. intentkit/skills/casino/base.py +0 -4
  26. intentkit/skills/casino/deck_draw.py +4 -6
  27. intentkit/skills/casino/deck_shuffle.py +5 -4
  28. intentkit/skills/casino/dice_roll.py +1 -2
  29. intentkit/skills/cdp/__init__.py +0 -5
  30. intentkit/skills/cdp/base.py +0 -4
  31. intentkit/skills/cdp/schema.json +1 -17
  32. intentkit/skills/chainlist/__init__.py +2 -7
  33. intentkit/skills/chainlist/base.py +0 -4
  34. intentkit/skills/common/__init__.py +2 -9
  35. intentkit/skills/common/base.py +0 -4
  36. intentkit/skills/cookiefun/__init__.py +6 -9
  37. intentkit/skills/cookiefun/base.py +0 -4
  38. intentkit/skills/cryptocompare/__init__.py +7 -24
  39. intentkit/skills/cryptocompare/base.py +4 -18
  40. intentkit/skills/cryptocompare/fetch_news.py +1 -1
  41. intentkit/skills/cryptocompare/fetch_price.py +1 -1
  42. intentkit/skills/cryptocompare/fetch_top_exchanges.py +1 -1
  43. intentkit/skills/cryptocompare/fetch_top_market_cap.py +1 -1
  44. intentkit/skills/cryptocompare/fetch_top_volume.py +1 -1
  45. intentkit/skills/cryptocompare/fetch_trading_signals.py +1 -1
  46. intentkit/skills/cryptopanic/__init__.py +3 -6
  47. intentkit/skills/cryptopanic/base.py +53 -55
  48. intentkit/skills/cryptopanic/fetch_crypto_news.py +0 -2
  49. intentkit/skills/cryptopanic/fetch_crypto_sentiment.py +1 -3
  50. intentkit/skills/dapplooker/__init__.py +2 -9
  51. intentkit/skills/dapplooker/base.py +2 -5
  52. intentkit/skills/defillama/__init__.py +24 -74
  53. intentkit/skills/defillama/base.py +3 -13
  54. intentkit/skills/defillama/coins/fetch_batch_historical_prices.py +2 -2
  55. intentkit/skills/defillama/coins/fetch_block.py +2 -2
  56. intentkit/skills/defillama/coins/fetch_current_prices.py +2 -2
  57. intentkit/skills/defillama/coins/fetch_first_price.py +2 -2
  58. intentkit/skills/defillama/coins/fetch_historical_prices.py +2 -2
  59. intentkit/skills/defillama/coins/fetch_price_chart.py +2 -2
  60. intentkit/skills/defillama/coins/fetch_price_percentage.py +2 -2
  61. intentkit/skills/defillama/fees/fetch_fees_overview.py +2 -2
  62. intentkit/skills/defillama/stablecoins/fetch_stablecoin_chains.py +2 -2
  63. intentkit/skills/defillama/stablecoins/fetch_stablecoin_charts.py +2 -2
  64. intentkit/skills/defillama/stablecoins/fetch_stablecoin_prices.py +2 -2
  65. intentkit/skills/defillama/stablecoins/fetch_stablecoins.py +2 -2
  66. intentkit/skills/defillama/tvl/fetch_chain_historical_tvl.py +2 -2
  67. intentkit/skills/defillama/tvl/fetch_chains.py +2 -2
  68. intentkit/skills/defillama/tvl/fetch_historical_tvl.py +2 -2
  69. intentkit/skills/defillama/tvl/fetch_protocol.py +2 -2
  70. intentkit/skills/defillama/tvl/fetch_protocol_current_tvl.py +2 -2
  71. intentkit/skills/defillama/tvl/fetch_protocols.py +2 -2
  72. intentkit/skills/defillama/volumes/fetch_dex_overview.py +2 -2
  73. intentkit/skills/defillama/volumes/fetch_dex_summary.py +2 -2
  74. intentkit/skills/defillama/volumes/fetch_options_overview.py +2 -2
  75. intentkit/skills/defillama/yields/fetch_pool_chart.py +2 -2
  76. intentkit/skills/defillama/yields/fetch_pools.py +2 -2
  77. intentkit/skills/dexscreener/__init__.py +97 -102
  78. intentkit/skills/dexscreener/base.py +125 -130
  79. intentkit/skills/dexscreener/get_pair_info.py +2 -3
  80. intentkit/skills/dexscreener/get_token_pairs.py +2 -3
  81. intentkit/skills/dexscreener/get_tokens_info.py +2 -3
  82. intentkit/skills/dexscreener/search_token.py +2 -4
  83. intentkit/skills/dune_analytics/__init__.py +4 -6
  84. intentkit/skills/dune_analytics/base.py +50 -52
  85. intentkit/skills/dune_analytics/fetch_kol_buys.py +0 -2
  86. intentkit/skills/dune_analytics/fetch_nation_metrics.py +0 -2
  87. intentkit/skills/elfa/__init__.py +5 -18
  88. intentkit/skills/elfa/base.py +8 -10
  89. intentkit/skills/enso/__init__.py +9 -29
  90. intentkit/skills/enso/base.py +3 -6
  91. intentkit/skills/enso/networks.py +1 -6
  92. intentkit/skills/enso/route.py +4 -8
  93. intentkit/skills/enso/tokens.py +2 -12
  94. intentkit/skills/erc20/__init__.py +1 -5
  95. intentkit/skills/erc721/__init__.py +1 -3
  96. intentkit/skills/firecrawl/__init__.py +5 -18
  97. intentkit/skills/firecrawl/base.py +2 -5
  98. intentkit/skills/firecrawl/clear.py +3 -6
  99. intentkit/skills/firecrawl/crawl.py +10 -9
  100. intentkit/skills/firecrawl/query.py +3 -1
  101. intentkit/skills/firecrawl/scrape.py +10 -14
  102. intentkit/skills/firecrawl/utils.py +39 -31
  103. intentkit/skills/github/__init__.py +2 -7
  104. intentkit/skills/github/base.py +0 -4
  105. intentkit/skills/heurist/__init__.py +8 -27
  106. intentkit/skills/heurist/base.py +2 -5
  107. intentkit/skills/heurist/image_generation_animagine_xl.py +5 -5
  108. intentkit/skills/heurist/image_generation_arthemy_comics.py +5 -5
  109. intentkit/skills/heurist/image_generation_arthemy_real.py +5 -5
  110. intentkit/skills/heurist/image_generation_braindance.py +5 -5
  111. intentkit/skills/heurist/image_generation_cyber_realistic_xl.py +5 -5
  112. intentkit/skills/heurist/image_generation_flux_1_dev.py +5 -5
  113. intentkit/skills/heurist/image_generation_sdxl.py +5 -5
  114. intentkit/skills/http/__init__.py +4 -15
  115. intentkit/skills/http/base.py +0 -4
  116. intentkit/skills/lifi/__init__.py +1 -6
  117. intentkit/skills/lifi/base.py +0 -4
  118. intentkit/skills/lifi/token_execute.py +1 -4
  119. intentkit/skills/lifi/token_quote.py +1 -3
  120. intentkit/skills/moralis/__init__.py +3 -7
  121. intentkit/skills/moralis/base.py +2 -5
  122. intentkit/skills/morpho/__init__.py +1 -3
  123. intentkit/skills/nation/__init__.py +2 -7
  124. intentkit/skills/nation/base.py +4 -7
  125. intentkit/skills/openai/__init__.py +5 -18
  126. intentkit/skills/openai/base.py +8 -10
  127. intentkit/skills/openai/dalle_image_generation.py +2 -5
  128. intentkit/skills/openai/gpt_image_generation.py +2 -5
  129. intentkit/skills/openai/gpt_image_to_image.py +2 -5
  130. intentkit/skills/openai/image_to_text.py +2 -5
  131. intentkit/skills/portfolio/__init__.py +11 -35
  132. intentkit/skills/portfolio/base.py +2 -5
  133. intentkit/skills/pyth/__init__.py +1 -5
  134. intentkit/skills/slack/__init__.py +5 -17
  135. intentkit/skills/slack/base.py +0 -4
  136. intentkit/skills/supabase/__init__.py +7 -23
  137. intentkit/skills/supabase/base.py +0 -4
  138. intentkit/skills/superfluid/__init__.py +1 -3
  139. intentkit/skills/system/__init__.py +7 -24
  140. intentkit/skills/system/add_autonomous_task.py +2 -2
  141. intentkit/skills/system/delete_autonomous_task.py +2 -2
  142. intentkit/skills/system/edit_autonomous_task.py +2 -4
  143. intentkit/skills/system/list_autonomous_tasks.py +2 -2
  144. intentkit/skills/system/read_agent_api_key.py +6 -4
  145. intentkit/skills/system/regenerate_agent_api_key.py +6 -4
  146. intentkit/skills/tavily/__init__.py +3 -12
  147. intentkit/skills/tavily/base.py +2 -5
  148. intentkit/skills/tavily/tavily_extract.py +1 -2
  149. intentkit/skills/tavily/tavily_search.py +3 -3
  150. intentkit/skills/token/__init__.py +5 -10
  151. intentkit/skills/token/base.py +2 -6
  152. intentkit/skills/twitter/__init__.py +11 -35
  153. intentkit/skills/twitter/base.py +18 -29
  154. intentkit/skills/twitter/follow_user.py +1 -4
  155. intentkit/skills/twitter/get_mentions.py +2 -8
  156. intentkit/skills/twitter/get_timeline.py +3 -10
  157. intentkit/skills/twitter/get_user_by_username.py +1 -4
  158. intentkit/skills/twitter/get_user_tweets.py +3 -10
  159. intentkit/skills/twitter/like_tweet.py +1 -4
  160. intentkit/skills/twitter/post_tweet.py +3 -5
  161. intentkit/skills/twitter/reply_tweet.py +3 -5
  162. intentkit/skills/twitter/retweet.py +1 -4
  163. intentkit/skills/twitter/search_tweets.py +3 -10
  164. intentkit/skills/unrealspeech/__init__.py +2 -7
  165. intentkit/skills/unrealspeech/base.py +0 -4
  166. intentkit/skills/venice_audio/__init__.py +99 -106
  167. intentkit/skills/venice_audio/base.py +118 -121
  168. intentkit/skills/venice_audio/venice_audio.py +1 -5
  169. intentkit/skills/venice_image/__init__.py +147 -154
  170. intentkit/skills/venice_image/base.py +185 -192
  171. intentkit/skills/web_scraper/__init__.py +5 -18
  172. intentkit/skills/web_scraper/base.py +20 -4
  173. intentkit/skills/web_scraper/document_indexer.py +6 -4
  174. intentkit/skills/web_scraper/scrape_and_index.py +11 -10
  175. intentkit/skills/web_scraper/utils.py +38 -38
  176. intentkit/skills/web_scraper/website_indexer.py +7 -8
  177. intentkit/skills/weth/__init__.py +1 -5
  178. intentkit/skills/wow/__init__.py +1 -5
  179. intentkit/skills/xmtp/__init__.py +4 -15
  180. {intentkit-0.8.11.dist-info → intentkit-0.8.12.dist-info}/METADATA +1 -1
  181. {intentkit-0.8.11.dist-info → intentkit-0.8.12.dist-info}/RECORD +183 -183
  182. {intentkit-0.8.11.dist-info → intentkit-0.8.12.dist-info}/WHEEL +0 -0
  183. {intentkit-0.8.11.dist-info → intentkit-0.8.12.dist-info}/licenses/LICENSE +0 -0
intentkit/core/agent.py CHANGED
@@ -2,21 +2,19 @@ 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, AsyncGenerator, Dict, List, Optional, Tuple
5
+ from typing import AsyncGenerator, Dict, Optional, Tuple
6
6
 
7
7
  from sqlalchemy import func, select, text, update
8
8
 
9
- from intentkit.abstracts.skill import SkillStoreABC
10
9
  from intentkit.clients.cdp import get_wallet_provider
11
10
  from intentkit.config.config import config
12
11
  from intentkit.models.agent import (
13
12
  Agent,
14
- AgentAutonomous,
15
13
  AgentCreate,
16
14
  AgentTable,
17
15
  AgentUpdate,
18
16
  )
19
- from intentkit.models.agent_data import AgentData, AgentQuota, AgentQuotaTable
17
+ from intentkit.models.agent_data import AgentData, AgentQuotaTable
20
18
  from intentkit.models.credit import (
21
19
  CreditAccount,
22
20
  CreditEventTable,
@@ -25,12 +23,6 @@ from intentkit.models.credit import (
25
23
  UpstreamType,
26
24
  )
27
25
  from intentkit.models.db import get_session
28
- from intentkit.models.skill import (
29
- AgentSkillData,
30
- AgentSkillDataCreate,
31
- ThreadSkillData,
32
- ThreadSkillDataCreate,
33
- )
34
26
  from intentkit.utils.error import IntentKitAPIError
35
27
  from intentkit.utils.slack_alert import send_slack_message
36
28
 
@@ -492,182 +484,6 @@ async def agent_action_cost(agent_id: str) -> Dict[str, Decimal]:
492
484
  return result
493
485
 
494
486
 
495
- class AgentStore(SkillStoreABC):
496
- """Implementation of skill data storage operations.
497
-
498
- This class provides concrete implementations for storing and retrieving
499
- skill-related data for both agents and threads.
500
- """
501
-
502
- @staticmethod
503
- def get_system_config(key: str) -> Any:
504
- # TODO: maybe need a whitelist here
505
- if hasattr(config, key):
506
- return getattr(config, key)
507
- return None
508
-
509
- @staticmethod
510
- async def get_agent_config(agent_id: str) -> Optional[Agent]:
511
- return await Agent.get(agent_id)
512
-
513
- @staticmethod
514
- async def get_agent_data(agent_id: str) -> AgentData:
515
- return await AgentData.get(agent_id)
516
-
517
- @staticmethod
518
- async def set_agent_data(agent_id: str, data: Dict) -> AgentData:
519
- return await AgentData.patch(agent_id, data)
520
-
521
- @staticmethod
522
- async def get_agent_quota(agent_id: str) -> AgentQuota:
523
- return await AgentQuota.get(agent_id)
524
-
525
- @staticmethod
526
- async def get_agent_skill_data(
527
- agent_id: str, skill: str, key: str
528
- ) -> Optional[Dict[str, Any]]:
529
- """Get skill data for an agent.
530
-
531
- Args:
532
- agent_id: ID of the agent
533
- skill: Name of the skill
534
- key: Data key
535
-
536
- Returns:
537
- Dictionary containing the skill data if found, None otherwise
538
- """
539
- return await AgentSkillData.get(agent_id, skill, key)
540
-
541
- @staticmethod
542
- async def save_agent_skill_data(
543
- agent_id: str, skill: str, key: str, data: Dict[str, Any]
544
- ) -> None:
545
- """Save or update skill data for an agent.
546
-
547
- Args:
548
- agent_id: ID of the agent
549
- skill: Name of the skill
550
- key: Data key
551
- data: JSON data to store
552
- """
553
- skill_data = AgentSkillDataCreate(
554
- agent_id=agent_id,
555
- skill=skill,
556
- key=key,
557
- data=data,
558
- )
559
- await skill_data.save()
560
-
561
- @staticmethod
562
- async def delete_agent_skill_data(agent_id: str, skill: str, key: str) -> None:
563
- """Delete skill data for an agent.
564
-
565
- Args:
566
- agent_id: ID of the agent
567
- skill: Name of the skill
568
- key: Data key
569
- """
570
- await AgentSkillData.delete(agent_id, skill, key)
571
-
572
- @staticmethod
573
- async def get_thread_skill_data(
574
- thread_id: str, skill: str, key: str
575
- ) -> Optional[Dict[str, Any]]:
576
- """Get skill data for a thread.
577
-
578
- Args:
579
- thread_id: ID of the thread
580
- skill: Name of the skill
581
- key: Data key
582
-
583
- Returns:
584
- Dictionary containing the skill data if found, None otherwise
585
- """
586
- return await ThreadSkillData.get(thread_id, skill, key)
587
-
588
- @staticmethod
589
- async def save_thread_skill_data(
590
- thread_id: str,
591
- agent_id: str,
592
- skill: str,
593
- key: str,
594
- data: Dict[str, Any],
595
- ) -> None:
596
- """Save or update skill data for a thread.
597
-
598
- Args:
599
- thread_id: ID of the thread
600
- agent_id: ID of the agent that owns this thread
601
- skill: Name of the skill
602
- key: Data key
603
- data: JSON data to store
604
- """
605
- skill_data = ThreadSkillDataCreate(
606
- thread_id=thread_id,
607
- agent_id=agent_id,
608
- skill=skill,
609
- key=key,
610
- data=data,
611
- )
612
- await skill_data.save()
613
-
614
- @staticmethod
615
- async def list_autonomous_tasks(agent_id: str) -> List[AgentAutonomous]:
616
- """List all autonomous tasks for an agent.
617
-
618
- Args:
619
- agent_id: ID of the agent
620
-
621
- Returns:
622
- List[AgentAutonomous]: List of autonomous task configurations
623
- """
624
- return await list_autonomous_tasks(agent_id)
625
-
626
- @staticmethod
627
- async def add_autonomous_task(
628
- agent_id: str, task: AgentAutonomous
629
- ) -> AgentAutonomous:
630
- """Add a new autonomous task to an agent.
631
-
632
- Args:
633
- agent_id: ID of the agent
634
- task: Autonomous task configuration
635
-
636
- Returns:
637
- AgentAutonomous: The created task
638
- """
639
- return await add_autonomous_task(agent_id, task)
640
-
641
- @staticmethod
642
- async def delete_autonomous_task(agent_id: str, task_id: str) -> None:
643
- """Delete an autonomous task from an agent.
644
-
645
- Args:
646
- agent_id: ID of the agent
647
- task_id: ID of the task to delete
648
- """
649
- await delete_autonomous_task(agent_id, task_id)
650
-
651
- @staticmethod
652
- async def update_autonomous_task(
653
- agent_id: str, task_id: str, task_updates: dict
654
- ) -> AgentAutonomous:
655
- """Update an autonomous task for an agent.
656
-
657
- Args:
658
- agent_id: ID of the agent
659
- task_id: ID of the task to update
660
- task_updates: Dictionary containing fields to update
661
-
662
- Returns:
663
- AgentAutonomous: The updated task
664
- """
665
- return await update_autonomous_task(agent_id, task_id, task_updates)
666
-
667
-
668
- agent_store = AgentStore()
669
-
670
-
671
487
  async def _iterate_agent_id_batches(
672
488
  batch_size: int = 100,
673
489
  ) -> AsyncGenerator[list[str], None]:
@@ -923,191 +739,3 @@ async def update_agents_statistics(
923
739
  total_updated,
924
740
  total_time,
925
741
  )
926
-
927
-
928
- async def list_autonomous_tasks(agent_id: str) -> List[AgentAutonomous]:
929
- """
930
- List all autonomous tasks for an agent.
931
-
932
- Args:
933
- agent_id: ID of the agent
934
-
935
- Returns:
936
- List[AgentAutonomous]: List of autonomous task configurations
937
-
938
- Raises:
939
- IntentKitAPIError: If agent is not found
940
- """
941
- agent = await Agent.get(agent_id)
942
- if not agent:
943
- raise IntentKitAPIError(
944
- 400, "AgentNotFound", f"Agent with ID {agent_id} does not exist."
945
- )
946
-
947
- if not agent.autonomous:
948
- return []
949
-
950
- return agent.autonomous
951
-
952
-
953
- async def add_autonomous_task(agent_id: str, task: AgentAutonomous) -> AgentAutonomous:
954
- """
955
- Add a new autonomous task to an agent.
956
-
957
- Args:
958
- agent_id: ID of the agent
959
- task: Autonomous task configuration (id will be generated if not provided)
960
-
961
- Returns:
962
- AgentAutonomous: The created task with generated ID
963
-
964
- Raises:
965
- IntentKitAPIError: If agent is not found
966
- """
967
- agent = await Agent.get(agent_id)
968
- if not agent:
969
- raise IntentKitAPIError(
970
- 400, "AgentNotFound", f"Agent with ID {agent_id} does not exist."
971
- )
972
-
973
- # Get current autonomous tasks
974
- current_tasks = agent.autonomous or []
975
- if not isinstance(current_tasks, list):
976
- current_tasks = []
977
-
978
- # Add the new task
979
- current_tasks.append(task)
980
-
981
- # Convert all AgentAutonomous objects to dictionaries for JSON serialization
982
- serializable_tasks = [task_item.model_dump() for task_item in current_tasks]
983
-
984
- # Update the agent in the database
985
- async with get_session() as session:
986
- update_stmt = (
987
- update(AgentTable)
988
- .where(AgentTable.id == agent_id)
989
- .values(autonomous=serializable_tasks)
990
- )
991
- await session.execute(update_stmt)
992
- await session.commit()
993
-
994
- logger.info(f"Added autonomous task {task.id} to agent {agent_id}")
995
- return task
996
-
997
-
998
- async def delete_autonomous_task(agent_id: str, task_id: str) -> None:
999
- """
1000
- Delete an autonomous task from an agent.
1001
-
1002
- Args:
1003
- agent_id: ID of the agent
1004
- task_id: ID of the task to delete
1005
-
1006
- Raises:
1007
- IntentKitAPIError: If agent is not found or task is not found
1008
- """
1009
- agent = await Agent.get(agent_id)
1010
- if not agent:
1011
- raise IntentKitAPIError(
1012
- 400, "AgentNotFound", f"Agent with ID {agent_id} does not exist."
1013
- )
1014
-
1015
- # Get current autonomous tasks
1016
- current_tasks = agent.autonomous or []
1017
- if not isinstance(current_tasks, list):
1018
- current_tasks = []
1019
-
1020
- # Find and remove the task
1021
- task_found = False
1022
- updated_tasks = []
1023
- for task_data in current_tasks:
1024
- if task_data.id == task_id:
1025
- task_found = True
1026
- continue
1027
- updated_tasks.append(task_data)
1028
-
1029
- if not task_found:
1030
- raise IntentKitAPIError(
1031
- 404, "TaskNotFound", f"Autonomous task with ID {task_id} not found."
1032
- )
1033
-
1034
- # Convert remaining AgentAutonomous objects to dictionaries for JSON serialization
1035
- serializable_tasks = [task_item.model_dump() for task_item in updated_tasks]
1036
-
1037
- # Update the agent in the database
1038
- async with get_session() as session:
1039
- update_stmt = (
1040
- update(AgentTable)
1041
- .where(AgentTable.id == agent_id)
1042
- .values(autonomous=serializable_tasks)
1043
- )
1044
- await session.execute(update_stmt)
1045
- await session.commit()
1046
-
1047
- logger.info(f"Deleted autonomous task {task_id} from agent {agent_id}")
1048
-
1049
-
1050
- async def update_autonomous_task(
1051
- agent_id: str, task_id: str, task_updates: dict
1052
- ) -> AgentAutonomous:
1053
- """
1054
- Update an autonomous task for an agent.
1055
-
1056
- Args:
1057
- agent_id: ID of the agent
1058
- task_id: ID of the task to update
1059
- task_updates: Dictionary containing fields to update
1060
-
1061
- Returns:
1062
- AgentAutonomous: The updated task
1063
-
1064
- Raises:
1065
- IntentKitAPIError: If agent is not found or task is not found
1066
- """
1067
- agent = await Agent.get(agent_id)
1068
- if not agent:
1069
- raise IntentKitAPIError(
1070
- 400, "AgentNotFound", f"Agent with ID {agent_id} does not exist."
1071
- )
1072
-
1073
- # Get current autonomous tasks
1074
- current_tasks: List[AgentAutonomous] = agent.autonomous or []
1075
-
1076
- # Find and update the task
1077
- task_found = False
1078
- updated_tasks: List[AgentAutonomous] = []
1079
- updated_task = None
1080
-
1081
- for task_data in current_tasks:
1082
- if task_data.id == task_id:
1083
- task_found = True
1084
- # Create a dictionary with current task data
1085
- task_dict = task_data.model_dump()
1086
- # Update with provided fields
1087
- task_dict.update(task_updates)
1088
- # Create new AgentAutonomous instance
1089
- updated_task = AgentAutonomous.model_validate(task_dict)
1090
- updated_tasks.append(updated_task)
1091
- else:
1092
- updated_tasks.append(task_data)
1093
-
1094
- if not task_found:
1095
- raise IntentKitAPIError(
1096
- 404, "TaskNotFound", f"Autonomous task with ID {task_id} not found."
1097
- )
1098
-
1099
- # Convert all AgentAutonomous objects to dictionaries for JSON serialization
1100
- serializable_tasks = [task_item.model_dump() for task_item in updated_tasks]
1101
-
1102
- # Update the agent in the database
1103
- async with get_session() as session:
1104
- update_stmt = (
1105
- update(AgentTable)
1106
- .where(AgentTable.id == agent_id)
1107
- .values(autonomous=serializable_tasks)
1108
- )
1109
- await session.execute(update_stmt)
1110
- await session.commit()
1111
-
1112
- logger.info(f"Updated autonomous task {task_id} for agent {agent_id}")
1113
- return updated_task
intentkit/core/asset.py CHANGED
@@ -2,18 +2,22 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
+ import json
5
6
  import logging
6
7
  from decimal import Decimal
7
8
  from typing import Optional
8
9
 
9
10
  import httpx
10
11
  from pydantic import BaseModel, Field
12
+ from sqlalchemy import update
11
13
  from web3 import Web3
12
14
 
13
15
  from intentkit.clients.web3 import get_web3_client
14
16
  from intentkit.config.config import config
15
- from intentkit.models.agent import Agent
17
+ from intentkit.models.agent import Agent, AgentTable
16
18
  from intentkit.models.agent_data import AgentData
19
+ from intentkit.models.db import get_session
20
+ from intentkit.models.redis import get_redis
17
21
  from intentkit.utils.error import IntentKitAPIError
18
22
 
19
23
  logger = logging.getLogger(__name__)
@@ -171,29 +175,72 @@ async def _build_assets_list(
171
175
 
172
176
  async def agent_asset(agent_id: str) -> AgentAssets:
173
177
  """Fetch wallet net worth and token balances for an agent."""
178
+
179
+ cache_key = f"intentkit:agent_assets:{agent_id}"
180
+ redis_client = None
181
+
182
+ try:
183
+ redis_client = get_redis()
184
+ except Exception as exc: # pragma: no cover - best effort fallback
185
+ logger.debug("Redis unavailable for agent assets: %s", exc)
186
+
174
187
  agent = await Agent.get(agent_id)
175
188
  if not agent:
176
189
  raise IntentKitAPIError(404, "AgentNotFound", "Agent not found")
177
190
 
191
+ if redis_client:
192
+ try:
193
+ cached_raw = await redis_client.get(cache_key)
194
+ if cached_raw:
195
+ cached_data = json.loads(cached_raw)
196
+ cached_assets = AgentAssets.model_validate(cached_data)
197
+ return cached_assets
198
+ except Exception as exc: # pragma: no cover - cache read path only
199
+ logger.debug("Failed to read agent asset cache for %s: %s", agent_id, exc)
200
+
178
201
  agent_data = await AgentData.get(agent_id)
179
202
  if not agent_data or not agent_data.evm_wallet_address:
180
- return AgentAssets(net_worth="0", tokens=[])
181
-
182
- if not agent.network_id:
183
- return AgentAssets(net_worth="0", tokens=[])
203
+ assets_result = AgentAssets(net_worth="0", tokens=[])
204
+ elif not agent.network_id:
205
+ assets_result = AgentAssets(net_worth="0", tokens=[])
206
+ else:
207
+ try:
208
+ web3_client = get_web3_client(str(agent.network_id))
209
+ tokens = await _build_assets_list(agent, agent_data, web3_client)
210
+ net_worth = await _get_wallet_net_worth(agent_data.evm_wallet_address)
211
+ assets_result = AgentAssets(net_worth=net_worth, tokens=tokens)
212
+ except IntentKitAPIError:
213
+ raise
214
+ except Exception as exc:
215
+ logger.error("Error getting agent assets for %s: %s", agent_id, exc)
216
+ raise IntentKitAPIError(
217
+ 500, "AgentAssetError", "Failed to retrieve agent assets"
218
+ ) from exc
219
+
220
+ assets_payload = assets_result.model_dump(mode="json")
221
+
222
+ if redis_client:
223
+ try:
224
+ await redis_client.set(
225
+ cache_key,
226
+ json.dumps(assets_payload),
227
+ ex=3600,
228
+ )
229
+ except Exception as exc: # pragma: no cover - cache write path only
230
+ logger.debug("Failed to write agent asset cache for %s: %s", agent_id, exc)
184
231
 
185
232
  try:
186
- web3_client = get_web3_client(str(agent.network_id))
187
- tokens = await _build_assets_list(agent, agent_data, web3_client)
188
- net_worth = await _get_wallet_net_worth(agent_data.evm_wallet_address)
189
- return AgentAssets(net_worth=net_worth, tokens=tokens)
190
- except IntentKitAPIError:
191
- raise
192
- except Exception as exc:
193
- logger.error("Error getting agent assets for %s: %s", agent_id, exc)
194
- raise IntentKitAPIError(
195
- 500, "AgentAssetError", "Failed to retrieve agent assets"
196
- ) from exc
233
+ async with get_session() as session:
234
+ await session.execute(
235
+ update(AgentTable)
236
+ .where(AgentTable.id == agent_id)
237
+ .values(assets=assets_payload)
238
+ )
239
+ await session.commit()
240
+ except Exception as exc: # pragma: no cover - db persistence path only
241
+ logger.error("Error updating agent assets cache for %s: %s", agent_id, exc)
242
+
243
+ return assets_result
197
244
 
198
245
 
199
246
  __all__ = [
intentkit/core/engine.py CHANGED
@@ -36,7 +36,6 @@ from sqlalchemy.exc import SQLAlchemyError
36
36
 
37
37
  from intentkit.abstracts.graph import AgentContext, AgentError, AgentState
38
38
  from intentkit.config.config import config
39
- from intentkit.core.agent import agent_store
40
39
  from intentkit.core.chat import clear_thread_memory
41
40
  from intentkit.core.credit import expense_message, expense_skill
42
41
  from intentkit.core.node import PreModelNode, post_model_node
@@ -56,7 +55,7 @@ from intentkit.models.chat import (
56
55
  from intentkit.models.credit import CreditAccount, OwnerType
57
56
  from intentkit.models.db import get_langgraph_checkpointer, get_session
58
57
  from intentkit.models.llm import LLMModelInfo, LLMProvider, create_llm_model
59
- from intentkit.models.skill import AgentSkillData, ThreadSkillData
58
+ from intentkit.models.skill import AgentSkillData, ChatSkillData, Skill
60
59
  from intentkit.models.user import User
61
60
  from intentkit.utils.error import IntentKitAPIError
62
61
 
@@ -70,7 +69,9 @@ _agents: dict[str, CompiledStateGraph] = {}
70
69
  _agents_updated: dict[str, datetime] = {}
71
70
 
72
71
 
73
- async def build_agent(agent: Agent, agent_data: AgentData) -> CompiledStateGraph:
72
+ async def build_agent(
73
+ agent: Agent, agent_data: AgentData, custom_skills: list[BaseTool] = []
74
+ ) -> CompiledStateGraph:
74
75
  """Build an AI agent with specified configuration and tools.
75
76
 
76
77
  This function:
@@ -82,7 +83,8 @@ async def build_agent(agent: Agent, agent_data: AgentData) -> CompiledStateGraph
82
83
  Args:
83
84
  agent (Agent): Agent configuration object
84
85
  agent_data (AgentData): Agent data object
85
- is_private (bool, optional): Flag indicating whether the agent is private. Defaults to False.
86
+ custom_skills (list[BaseTool], optional): Designed for advanced user who directly
87
+ call this function to inject custom skills into the agent tool node.
86
88
 
87
89
  Returns:
88
90
  CompiledStateGraph: Initialized LangChain agent
@@ -112,13 +114,13 @@ async def build_agent(agent: Agent, agent_data: AgentData) -> CompiledStateGraph
112
114
  if hasattr(skill_module, "get_skills"):
113
115
  # all
114
116
  skill_tools = await skill_module.get_skills(
115
- v, False, agent_store, agent_id=agent.id, agent=agent
117
+ v, False, agent_id=agent.id, agent=agent
116
118
  )
117
119
  if skill_tools and len(skill_tools) > 0:
118
120
  tools.extend(skill_tools)
119
121
  # private
120
122
  skill_private_tools = await skill_module.get_skills(
121
- v, True, agent_store, agent_id=agent.id, agent=agent
123
+ v, True, agent_id=agent.id, agent=agent
122
124
  )
123
125
  if skill_private_tools and len(skill_private_tools) > 0:
124
126
  private_tools.extend(skill_private_tools)
@@ -127,6 +129,10 @@ async def build_agent(agent: Agent, agent_data: AgentData) -> CompiledStateGraph
127
129
  except ImportError as e:
128
130
  logger.error(f"Could not import skill module: {k} ({e})")
129
131
 
132
+ # add custom skills to private tools
133
+ if custom_skills and len(custom_skills) > 0:
134
+ private_tools.extend(custom_skills)
135
+
130
136
  # filter the duplicate tools
131
137
  tools = list({tool.name: tool for tool in tools}.values())
132
138
  private_tools = list({tool.name: tool for tool in private_tools}.values())
@@ -696,6 +702,9 @@ async def stream_agent_raw(
696
702
  for skill_call in skill_calls:
697
703
  if not skill_call["success"]:
698
704
  continue
705
+ skill = await Skill.get(skill_call["name"])
706
+ if not skill:
707
+ continue
699
708
  payment_event = await expense_skill(
700
709
  session,
701
710
  payer,
@@ -889,7 +898,7 @@ async def clean_agent_memory(
889
898
 
890
899
  if clean_skill:
891
900
  await AgentSkillData.clean_data(agent_id)
892
- await ThreadSkillData.clean_data(agent_id, chat_id)
901
+ await ChatSkillData.clean_data(agent_id, chat_id)
893
902
 
894
903
  async with get_session() as db:
895
904
  if clean_agent:
@@ -11,7 +11,6 @@ from apscheduler.triggers.cron import CronTrigger
11
11
  from intentkit.core.agent import (
12
12
  update_agent_action_cost,
13
13
  update_agents_account_snapshot,
14
- update_agents_assets,
15
14
  update_agents_statistics,
16
15
  )
17
16
  from intentkit.core.credit import refill_all_free_credits
@@ -63,13 +62,14 @@ def create_scheduler(
63
62
  )
64
63
 
65
64
  # Update agent assets daily at UTC midnight
66
- scheduler.add_job(
67
- update_agents_assets,
68
- trigger=CronTrigger(hour=0, minute=0, timezone="UTC"),
69
- id="update_agent_assets",
70
- name="Update agent assets",
71
- replace_existing=True,
72
- )
65
+ # This is too expensive to run daily, so it will only be triggered when detail page is visited
66
+ # scheduler.add_job(
67
+ # update_agents_assets,
68
+ # trigger=CronTrigger(hour=0, minute=0, timezone="UTC"),
69
+ # id="update_agent_assets",
70
+ # name="Update agent assets",
71
+ # replace_existing=True,
72
+ # )
73
73
 
74
74
  # Update agent action costs hourly at minute 40
75
75
  scheduler.add_job(