intentkit 0.6.15__py3-none-any.whl → 0.6.17.dev1__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 +1 -1
- intentkit/core/engine.py +24 -36
- intentkit/core/prompt.py +0 -1
- intentkit/models/agent.py +0 -17
- intentkit/models/agent_schema.json +15 -58
- intentkit/models/app_setting.py +92 -29
- intentkit/models/chat.py +35 -0
- intentkit/skills/base.py +1 -1
- intentkit/skills/cryptocompare/base.py +1 -1
- intentkit/skills/twitter/base.py +1 -1
- intentkit/utils/error.py +11 -1
- {intentkit-0.6.15.dist-info → intentkit-0.6.17.dev1.dist-info}/METADATA +1 -1
- {intentkit-0.6.15.dist-info → intentkit-0.6.17.dev1.dist-info}/RECORD +15 -16
- intentkit/abstracts/exception.py +0 -9
- {intentkit-0.6.15.dist-info → intentkit-0.6.17.dev1.dist-info}/WHEEL +0 -0
- {intentkit-0.6.15.dist-info → intentkit-0.6.17.dev1.dist-info}/licenses/LICENSE +0 -0
intentkit/__init__.py
CHANGED
intentkit/core/engine.py
CHANGED
|
@@ -44,7 +44,7 @@ from intentkit.core.prompt import (
|
|
|
44
44
|
from intentkit.core.skill import skill_store
|
|
45
45
|
from intentkit.models.agent import Agent, AgentTable
|
|
46
46
|
from intentkit.models.agent_data import AgentData, AgentQuota
|
|
47
|
-
from intentkit.models.app_setting import AppSetting
|
|
47
|
+
from intentkit.models.app_setting import AppSetting, SystemMessageType
|
|
48
48
|
from intentkit.models.chat import (
|
|
49
49
|
AuthorType,
|
|
50
50
|
ChatMessage,
|
|
@@ -298,16 +298,14 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
298
298
|
if agent.fee_percentage and agent.fee_percentage > 100:
|
|
299
299
|
owner = await User.get(agent.owner)
|
|
300
300
|
if owner and agent.fee_percentage > 100 + owner.nft_count * 10:
|
|
301
|
-
error_message_create = ChatMessageCreate(
|
|
302
|
-
|
|
301
|
+
error_message_create = await ChatMessageCreate.from_system_message(
|
|
302
|
+
SystemMessageType.SERVICE_FEE_ERROR,
|
|
303
303
|
agent_id=input.agent_id,
|
|
304
304
|
chat_id=input.chat_id,
|
|
305
305
|
user_id=input.user_id,
|
|
306
306
|
author_id=input.agent_id,
|
|
307
|
-
author_type=AuthorType.SYSTEM,
|
|
308
307
|
thread_type=input.author_type,
|
|
309
308
|
reply_to=input.id,
|
|
310
|
-
message="If you are the owner of this agent, please Update the Service Fee % to be in compliance with the Nation guidelines (Max 100% + 10% per Nation Pass NFT held)",
|
|
311
309
|
time_cost=time.perf_counter() - start,
|
|
312
310
|
)
|
|
313
311
|
error_message = await error_message_create.save()
|
|
@@ -336,16 +334,14 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
336
334
|
abuse_check = False
|
|
337
335
|
if abuse_check and payer != agent.owner and user_account.free_credits > 0:
|
|
338
336
|
if quota and quota.free_income_daily > 24000:
|
|
339
|
-
error_message_create = ChatMessageCreate(
|
|
340
|
-
|
|
337
|
+
error_message_create = await ChatMessageCreate.from_system_message(
|
|
338
|
+
SystemMessageType.DAILY_USAGE_LIMIT_EXCEEDED,
|
|
341
339
|
agent_id=input.agent_id,
|
|
342
340
|
chat_id=input.chat_id,
|
|
343
341
|
user_id=input.user_id,
|
|
344
342
|
author_id=input.agent_id,
|
|
345
|
-
author_type=AuthorType.SYSTEM,
|
|
346
343
|
thread_type=input.author_type,
|
|
347
344
|
reply_to=input.id,
|
|
348
|
-
message="This Agent has reached its free CAP income limit for today! Start using paid CAPs or wait until this limit expires in less than 24 hours.",
|
|
349
345
|
time_cost=time.perf_counter() - start,
|
|
350
346
|
)
|
|
351
347
|
error_message = await error_message_create.save()
|
|
@@ -356,16 +352,14 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
356
352
|
if quota and quota.avg_action_cost > 0:
|
|
357
353
|
avg_count = quota.avg_action_cost
|
|
358
354
|
if not user_account.has_sufficient_credits(avg_count):
|
|
359
|
-
error_message_create = ChatMessageCreate(
|
|
360
|
-
|
|
355
|
+
error_message_create = await ChatMessageCreate.from_system_message(
|
|
356
|
+
SystemMessageType.INSUFFICIENT_BALANCE,
|
|
361
357
|
agent_id=input.agent_id,
|
|
362
358
|
chat_id=input.chat_id,
|
|
363
359
|
user_id=input.user_id,
|
|
364
360
|
author_id=input.agent_id,
|
|
365
|
-
author_type=AuthorType.SYSTEM,
|
|
366
361
|
thread_type=input.author_type,
|
|
367
362
|
reply_to=input.id,
|
|
368
|
-
message="Insufficient balance.",
|
|
369
363
|
time_cost=time.perf_counter() - start,
|
|
370
364
|
)
|
|
371
365
|
error_message = await error_message_create.save()
|
|
@@ -723,17 +717,17 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
723
717
|
cold_start_cost = 0
|
|
724
718
|
post_model_message = await post_model_message_create.save()
|
|
725
719
|
yield post_model_message
|
|
726
|
-
error_message_create =
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
720
|
+
error_message_create = (
|
|
721
|
+
await ChatMessageCreate.from_system_message(
|
|
722
|
+
SystemMessageType.INSUFFICIENT_BALANCE,
|
|
723
|
+
agent_id=input.agent_id,
|
|
724
|
+
chat_id=input.chat_id,
|
|
725
|
+
user_id=input.user_id,
|
|
726
|
+
author_id=input.agent_id,
|
|
727
|
+
thread_type=input.author_type,
|
|
728
|
+
reply_to=input.id,
|
|
729
|
+
time_cost=0,
|
|
730
|
+
)
|
|
737
731
|
)
|
|
738
732
|
error_message = await error_message_create.save()
|
|
739
733
|
yield error_message
|
|
@@ -749,16 +743,14 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
749
743
|
f"failed to execute agent: {str(e)}\n{error_traceback}",
|
|
750
744
|
extra={"thread_id": thread_id},
|
|
751
745
|
)
|
|
752
|
-
error_message_create = ChatMessageCreate(
|
|
753
|
-
|
|
746
|
+
error_message_create = await ChatMessageCreate.from_system_message(
|
|
747
|
+
SystemMessageType.AGENT_INTERNAL_ERROR,
|
|
754
748
|
agent_id=input.agent_id,
|
|
755
749
|
chat_id=input.chat_id,
|
|
756
750
|
user_id=input.user_id,
|
|
757
751
|
author_id=input.agent_id,
|
|
758
|
-
author_type=AuthorType.SYSTEM,
|
|
759
752
|
thread_type=input.author_type,
|
|
760
753
|
reply_to=input.id,
|
|
761
|
-
message="Agent Internal Error",
|
|
762
754
|
time_cost=time.perf_counter() - start,
|
|
763
755
|
)
|
|
764
756
|
error_message = await error_message_create.save()
|
|
@@ -770,16 +762,14 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
770
762
|
f"reached recursion limit: {str(e)}\n{error_traceback}",
|
|
771
763
|
extra={"thread_id": thread_id, "agent_id": input.agent_id},
|
|
772
764
|
)
|
|
773
|
-
error_message_create = ChatMessageCreate(
|
|
774
|
-
|
|
765
|
+
error_message_create = await ChatMessageCreate.from_system_message(
|
|
766
|
+
SystemMessageType.STEP_LIMIT_EXCEEDED,
|
|
775
767
|
agent_id=input.agent_id,
|
|
776
768
|
chat_id=input.chat_id,
|
|
777
769
|
user_id=input.user_id,
|
|
778
770
|
author_id=input.agent_id,
|
|
779
|
-
author_type=AuthorType.SYSTEM,
|
|
780
771
|
thread_type=input.author_type,
|
|
781
772
|
reply_to=input.id,
|
|
782
|
-
message="Step Limit Error",
|
|
783
773
|
time_cost=time.perf_counter() - start,
|
|
784
774
|
)
|
|
785
775
|
error_message = await error_message_create.save()
|
|
@@ -791,16 +781,14 @@ async def stream_agent(message: ChatMessageCreate):
|
|
|
791
781
|
f"failed to execute agent: {str(e)}\n{error_traceback}",
|
|
792
782
|
extra={"thread_id": thread_id, "agent_id": input.agent_id},
|
|
793
783
|
)
|
|
794
|
-
error_message_create = ChatMessageCreate(
|
|
795
|
-
|
|
784
|
+
error_message_create = await ChatMessageCreate.from_system_message(
|
|
785
|
+
SystemMessageType.AGENT_INTERNAL_ERROR,
|
|
796
786
|
agent_id=input.agent_id,
|
|
797
787
|
chat_id=input.chat_id,
|
|
798
788
|
user_id=input.user_id,
|
|
799
789
|
author_id=input.agent_id,
|
|
800
|
-
author_type=AuthorType.SYSTEM,
|
|
801
790
|
thread_type=input.author_type,
|
|
802
791
|
reply_to=input.id,
|
|
803
|
-
message="Agent Internal Error",
|
|
804
792
|
time_cost=time.perf_counter() - start,
|
|
805
793
|
)
|
|
806
794
|
error_message = await error_message_create.save()
|
intentkit/core/prompt.py
CHANGED
|
@@ -292,7 +292,6 @@ async def build_entrypoint_prompt(agent: Agent, context: AgentContext) -> Option
|
|
|
292
292
|
Build entrypoint-specific prompt based on context.
|
|
293
293
|
|
|
294
294
|
Supports different entrypoint types:
|
|
295
|
-
- Twitter: Uses agent.twitter_entrypoint_prompt
|
|
296
295
|
- Telegram: Uses agent.telegram_entrypoint_prompt
|
|
297
296
|
- Autonomous tasks: Builds task-specific prompt with scheduling info
|
|
298
297
|
|
intentkit/models/agent.py
CHANGED
|
@@ -369,23 +369,6 @@ class AgentTable(Base):
|
|
|
369
369
|
default="base-mainnet",
|
|
370
370
|
comment="Network identifier for CDP integration",
|
|
371
371
|
)
|
|
372
|
-
# if twitter_enabled, the twitter_entrypoint will be enabled, twitter_config will be checked
|
|
373
|
-
twitter_entrypoint_enabled = Column(
|
|
374
|
-
Boolean,
|
|
375
|
-
nullable=True,
|
|
376
|
-
default=False,
|
|
377
|
-
comment="Dangerous, reply all mentions from x.com",
|
|
378
|
-
)
|
|
379
|
-
twitter_entrypoint_prompt = Column(
|
|
380
|
-
String,
|
|
381
|
-
nullable=True,
|
|
382
|
-
comment="Extra prompt for twitter entrypoint",
|
|
383
|
-
)
|
|
384
|
-
twitter_config = Column(
|
|
385
|
-
JSON().with_variant(JSONB(), "postgresql"),
|
|
386
|
-
nullable=True,
|
|
387
|
-
comment="You must use your own key for twitter entrypoint, it is separated from twitter skills",
|
|
388
|
-
)
|
|
389
372
|
# if telegram_entrypoint_enabled, the telegram_entrypoint_enabled will be enabled, telegram_config will be checked
|
|
390
373
|
telegram_entrypoint_enabled = Column(
|
|
391
374
|
Boolean,
|
|
@@ -15,13 +15,13 @@
|
|
|
15
15
|
"order": 2
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
|
-
"id": "
|
|
19
|
-
"title": "
|
|
18
|
+
"id": "onchain",
|
|
19
|
+
"title": "On-Chain",
|
|
20
20
|
"order": 3
|
|
21
21
|
},
|
|
22
22
|
{
|
|
23
|
-
"id": "
|
|
24
|
-
"title": "
|
|
23
|
+
"id": "examples",
|
|
24
|
+
"title": "Quick Actions",
|
|
25
25
|
"order": 4
|
|
26
26
|
},
|
|
27
27
|
{
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
"description": "Ticker symbol of the agent",
|
|
74
74
|
"maxLength": 10,
|
|
75
75
|
"minLength": 1,
|
|
76
|
-
"x-group": "
|
|
76
|
+
"x-group": "internal",
|
|
77
77
|
"x-placeholder": "Enter agent ticker"
|
|
78
78
|
},
|
|
79
79
|
"token_address": {
|
|
@@ -401,53 +401,6 @@
|
|
|
401
401
|
}
|
|
402
402
|
}
|
|
403
403
|
},
|
|
404
|
-
"twitter_entrypoint_enabled": {
|
|
405
|
-
"title": "Enable X Communication",
|
|
406
|
-
"type": "boolean",
|
|
407
|
-
"description": "Agent replies automatically to all X mentions (use cautiously)",
|
|
408
|
-
"default": false,
|
|
409
|
-
"x-group": "deprecated"
|
|
410
|
-
},
|
|
411
|
-
"twitter_entrypoint_prompt": {
|
|
412
|
-
"title": "X Entry Prompt",
|
|
413
|
-
"type": "string",
|
|
414
|
-
"description": "Extra prompt for X entrypoint",
|
|
415
|
-
"maxLength": 10000,
|
|
416
|
-
"x-str-type": "prompt",
|
|
417
|
-
"x-group": "deprecated"
|
|
418
|
-
},
|
|
419
|
-
"twitter_config": {
|
|
420
|
-
"title": "Enter your X API key",
|
|
421
|
-
"type": "object",
|
|
422
|
-
"description": "You must use your own key for X entrypoint, it is separated from X skills",
|
|
423
|
-
"x-group": "deprecated",
|
|
424
|
-
"properties": {
|
|
425
|
-
"consumer_key": {
|
|
426
|
-
"type": "string",
|
|
427
|
-
"title": "X API consumer key",
|
|
428
|
-
"description": "X API consumer key",
|
|
429
|
-
"maxLength": 100
|
|
430
|
-
},
|
|
431
|
-
"consumer_secret": {
|
|
432
|
-
"type": "string",
|
|
433
|
-
"title": "X API consumer secret",
|
|
434
|
-
"description": "X API consumer secret",
|
|
435
|
-
"maxLength": 100
|
|
436
|
-
},
|
|
437
|
-
"access_token": {
|
|
438
|
-
"type": "string",
|
|
439
|
-
"title": "X API access token",
|
|
440
|
-
"description": "X API access token",
|
|
441
|
-
"maxLength": 100
|
|
442
|
-
},
|
|
443
|
-
"access_token_secret": {
|
|
444
|
-
"type": "string",
|
|
445
|
-
"title": "X API access token secret",
|
|
446
|
-
"description": "X API access token secret",
|
|
447
|
-
"maxLength": 100
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
},
|
|
451
404
|
"skills": {
|
|
452
405
|
"title": "Skills",
|
|
453
406
|
"type": "object",
|
|
@@ -713,18 +666,22 @@
|
|
|
713
666
|
"wallet_provider": {
|
|
714
667
|
"title": "Wallet Provider",
|
|
715
668
|
"type": "string",
|
|
716
|
-
"description": "Provider of the agent's wallet",
|
|
669
|
+
"description": "Provider of the agent's wallet, choose cdp if you want the agent to have it's own wallet.",
|
|
717
670
|
"enum": [
|
|
718
671
|
"cdp",
|
|
719
672
|
"readonly"
|
|
720
673
|
],
|
|
674
|
+
"x-enum-title": [
|
|
675
|
+
"Coinbase Server Wallet V2",
|
|
676
|
+
"Readonly Wallet"
|
|
677
|
+
],
|
|
721
678
|
"default": "cdp",
|
|
722
679
|
"x-group": "onchain"
|
|
723
680
|
},
|
|
724
681
|
"network_id": {
|
|
725
|
-
"title": "Network
|
|
682
|
+
"title": "Default Network",
|
|
726
683
|
"type": "string",
|
|
727
|
-
"description": "Network
|
|
684
|
+
"description": "Default Network",
|
|
728
685
|
"default": "base-mainnet",
|
|
729
686
|
"enum": [
|
|
730
687
|
"ethereum-mainnet",
|
|
@@ -739,10 +696,9 @@
|
|
|
739
696
|
"optimism-sepolia",
|
|
740
697
|
"solana"
|
|
741
698
|
],
|
|
742
|
-
"x-group": "
|
|
699
|
+
"x-group": "onchain"
|
|
743
700
|
}
|
|
744
701
|
},
|
|
745
|
-
"additionalProperties": false,
|
|
746
702
|
"if": {
|
|
747
703
|
"properties": {
|
|
748
704
|
"wallet_provider": {
|
|
@@ -763,5 +719,6 @@
|
|
|
763
719
|
"required": [
|
|
764
720
|
"readonly_wallet_address"
|
|
765
721
|
]
|
|
766
|
-
}
|
|
722
|
+
},
|
|
723
|
+
"additionalProperties": true
|
|
767
724
|
}
|
intentkit/models/app_setting.py
CHANGED
|
@@ -1,16 +1,42 @@
|
|
|
1
|
-
import
|
|
1
|
+
import time
|
|
2
2
|
from datetime import datetime, timezone
|
|
3
3
|
from decimal import ROUND_HALF_UP, Decimal
|
|
4
|
-
from
|
|
4
|
+
from enum import Enum
|
|
5
|
+
from typing import Annotated, Any, Dict, List
|
|
5
6
|
|
|
6
7
|
from intentkit.models.base import Base
|
|
7
8
|
from intentkit.models.db import get_session
|
|
8
|
-
from intentkit.models.redis import get_redis
|
|
9
9
|
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
10
10
|
from sqlalchemy import Column, DateTime, String, func, select
|
|
11
11
|
from sqlalchemy.dialects.postgresql import JSON, JSONB
|
|
12
12
|
|
|
13
13
|
|
|
14
|
+
class SystemMessageType(str, Enum):
|
|
15
|
+
"""Type of system message."""
|
|
16
|
+
|
|
17
|
+
SERVICE_FEE_ERROR = "service_fee_error"
|
|
18
|
+
DAILY_USAGE_LIMIT_EXCEEDED = "daily_usage_limit_exceeded"
|
|
19
|
+
INSUFFICIENT_BALANCE = "insufficient_balance"
|
|
20
|
+
AGENT_INTERNAL_ERROR = "agent_internal_error"
|
|
21
|
+
STEP_LIMIT_EXCEEDED = "step_limit_exceeded"
|
|
22
|
+
SKILL_INTERRUPTED = "skill_interrupted"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
# Default system messages
|
|
26
|
+
DEFAULT_SYSTEM_MESSAGES = {
|
|
27
|
+
"service_fee_error": "Please lower this Agent's service fee to meet the allowed maximum.",
|
|
28
|
+
"daily_usage_limit_exceeded": "This Agent has reached its free daily usage limit. Add credits to continue, or wait until tomorrow.",
|
|
29
|
+
"insufficient_balance": "You don't have enough credits to complete this action.",
|
|
30
|
+
"agent_internal_error": "Something went wrong. Please try again.",
|
|
31
|
+
"step_limit_exceeded": "This Agent tried to process too many steps. Try again with @super for higher step limit.",
|
|
32
|
+
"skill_interrupted": "You were interrupted after executing a skill. Please retry with caution to avoid repeating the skill.",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
# In-memory cache for app settings
|
|
36
|
+
_cache: Dict[str, Dict[str, Any]] = {}
|
|
37
|
+
_cache_ttl = 180 # 3 minutes in seconds
|
|
38
|
+
|
|
39
|
+
|
|
14
40
|
class AppSettingTable(Base):
|
|
15
41
|
"""App settings database table model."""
|
|
16
42
|
|
|
@@ -133,31 +159,23 @@ class AppSetting(BaseModel):
|
|
|
133
159
|
|
|
134
160
|
@staticmethod
|
|
135
161
|
async def payment() -> PaymentSettings:
|
|
136
|
-
"""Get payment settings from the database with
|
|
162
|
+
"""Get payment settings from the database with in-memory caching.
|
|
137
163
|
|
|
138
|
-
The settings are cached in
|
|
164
|
+
The settings are cached in memory for 3 minutes.
|
|
139
165
|
|
|
140
166
|
Returns:
|
|
141
167
|
PaymentSettings: Payment settings
|
|
142
168
|
"""
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
try:
|
|
154
|
-
payment_data = json.loads(cached_data)
|
|
155
|
-
return PaymentSettings(**payment_data)
|
|
156
|
-
except (json.JSONDecodeError, TypeError):
|
|
157
|
-
# If cache is corrupted, invalidate it
|
|
158
|
-
await redis.delete(cache_key)
|
|
159
|
-
|
|
160
|
-
# If not in cache or cache is invalid, get from database
|
|
169
|
+
cache_key = "payment"
|
|
170
|
+
current_time = time.time()
|
|
171
|
+
|
|
172
|
+
# Check if we have cached data and it's still valid
|
|
173
|
+
if cache_key in _cache:
|
|
174
|
+
cache_entry = _cache[cache_key]
|
|
175
|
+
if current_time - cache_entry["timestamp"] < _cache_ttl:
|
|
176
|
+
return PaymentSettings(**cache_entry["data"])
|
|
177
|
+
|
|
178
|
+
# If not in cache or cache is expired, get from database
|
|
161
179
|
async with get_session() as session:
|
|
162
180
|
# Query the database for the payment settings
|
|
163
181
|
stmt = select(AppSettingTable).where(AppSettingTable.key == "payment")
|
|
@@ -170,11 +188,56 @@ class AppSetting(BaseModel):
|
|
|
170
188
|
# Convert the JSON value to PaymentSettings
|
|
171
189
|
payment_settings = PaymentSettings(**setting.value)
|
|
172
190
|
|
|
173
|
-
# Cache the settings in
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
)
|
|
191
|
+
# Cache the settings in memory
|
|
192
|
+
_cache[cache_key] = {
|
|
193
|
+
"data": payment_settings.model_dump(mode="json"),
|
|
194
|
+
"timestamp": current_time,
|
|
195
|
+
}
|
|
179
196
|
|
|
180
197
|
return payment_settings
|
|
198
|
+
|
|
199
|
+
@staticmethod
|
|
200
|
+
async def error_message(message_type: SystemMessageType) -> str:
|
|
201
|
+
"""Get error message from the database with in-memory caching, fallback to default.
|
|
202
|
+
|
|
203
|
+
The settings are cached in memory for 3 minutes.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
message_type: The SystemMessageType enum
|
|
207
|
+
|
|
208
|
+
Returns:
|
|
209
|
+
str: Error message from config or default message
|
|
210
|
+
"""
|
|
211
|
+
cache_key = "errors"
|
|
212
|
+
current_time = time.time()
|
|
213
|
+
message_key = message_type.value
|
|
214
|
+
|
|
215
|
+
# Check if we have cached data and it's still valid
|
|
216
|
+
if cache_key in _cache:
|
|
217
|
+
cache_entry = _cache[cache_key]
|
|
218
|
+
if current_time - cache_entry["timestamp"] < _cache_ttl:
|
|
219
|
+
errors_data = cache_entry["data"]
|
|
220
|
+
if errors_data and message_key in errors_data:
|
|
221
|
+
return errors_data[message_key]
|
|
222
|
+
# Return default message if not found in config
|
|
223
|
+
return DEFAULT_SYSTEM_MESSAGES[message_key]
|
|
224
|
+
|
|
225
|
+
# If not in cache or cache is expired, get from database
|
|
226
|
+
async with get_session() as session:
|
|
227
|
+
# Query the database for the errors settings
|
|
228
|
+
stmt = select(AppSettingTable).where(AppSettingTable.key == "errors")
|
|
229
|
+
setting = await session.scalar(stmt)
|
|
230
|
+
|
|
231
|
+
# If settings don't exist, cache None
|
|
232
|
+
errors_data = setting.value if setting else None
|
|
233
|
+
|
|
234
|
+
# Cache the settings in memory
|
|
235
|
+
_cache[cache_key] = {
|
|
236
|
+
"data": errors_data,
|
|
237
|
+
"timestamp": current_time,
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
# Return configured message if exists, otherwise return default
|
|
241
|
+
if errors_data and message_key in errors_data:
|
|
242
|
+
return errors_data[message_key]
|
|
243
|
+
return DEFAULT_SYSTEM_MESSAGES[message_key]
|
intentkit/models/chat.py
CHANGED
|
@@ -4,6 +4,7 @@ from enum import Enum
|
|
|
4
4
|
from typing import Annotated, List, NotRequired, Optional, TypedDict
|
|
5
5
|
|
|
6
6
|
from epyxid import XID
|
|
7
|
+
from intentkit.models.app_setting import AppSetting, SystemMessageType
|
|
7
8
|
from intentkit.models.base import Base
|
|
8
9
|
from intentkit.models.db import get_session
|
|
9
10
|
from pydantic import BaseModel, ConfigDict, Field
|
|
@@ -385,6 +386,40 @@ class ChatMessageCreate(BaseModel):
|
|
|
385
386
|
await db.commit()
|
|
386
387
|
return resp
|
|
387
388
|
|
|
389
|
+
@classmethod
|
|
390
|
+
async def from_system_message(
|
|
391
|
+
cls,
|
|
392
|
+
message_type: SystemMessageType,
|
|
393
|
+
agent_id: str,
|
|
394
|
+
chat_id: str,
|
|
395
|
+
user_id: str,
|
|
396
|
+
author_id: str,
|
|
397
|
+
thread_type: AuthorType,
|
|
398
|
+
reply_to: str,
|
|
399
|
+
time_cost: float = 0.0,
|
|
400
|
+
) -> "ChatMessageCreate":
|
|
401
|
+
"""Create a system message.
|
|
402
|
+
|
|
403
|
+
Returns:
|
|
404
|
+
ChatMessageCreate: The created system message
|
|
405
|
+
"""
|
|
406
|
+
|
|
407
|
+
# Get error message (configured or default)
|
|
408
|
+
message = await AppSetting.error_message(message_type)
|
|
409
|
+
|
|
410
|
+
return cls(
|
|
411
|
+
id=str(XID()),
|
|
412
|
+
agent_id=agent_id,
|
|
413
|
+
chat_id=chat_id,
|
|
414
|
+
user_id=user_id,
|
|
415
|
+
author_id=author_id,
|
|
416
|
+
author_type=AuthorType.SYSTEM,
|
|
417
|
+
thread_type=thread_type,
|
|
418
|
+
reply_to=reply_to,
|
|
419
|
+
message=message,
|
|
420
|
+
time_cost=time_cost,
|
|
421
|
+
)
|
|
422
|
+
|
|
388
423
|
|
|
389
424
|
class ChatMessage(ChatMessageCreate):
|
|
390
425
|
"""Chat message model with all fields including server-generated ones."""
|
intentkit/skills/base.py
CHANGED
|
@@ -13,11 +13,11 @@ from pydantic import (
|
|
|
13
13
|
from pydantic.v1 import ValidationError as ValidationErrorV1
|
|
14
14
|
from redis.exceptions import RedisError
|
|
15
15
|
|
|
16
|
-
from intentkit.abstracts.exception import RateLimitExceeded
|
|
17
16
|
from intentkit.abstracts.graph import AgentContext
|
|
18
17
|
from intentkit.abstracts.skill import SkillStoreABC
|
|
19
18
|
from intentkit.models.agent import Agent
|
|
20
19
|
from intentkit.models.redis import get_redis
|
|
20
|
+
from intentkit.utils.error import RateLimitExceeded
|
|
21
21
|
|
|
22
22
|
SkillState = Literal["disabled", "public", "private"]
|
|
23
23
|
SkillOwnerState = Literal["disabled", "private"]
|
|
@@ -7,9 +7,9 @@ from typing import Any, Dict, List, Type
|
|
|
7
7
|
import httpx
|
|
8
8
|
from pydantic import BaseModel, Field
|
|
9
9
|
|
|
10
|
-
from intentkit.abstracts.exception import RateLimitExceeded
|
|
11
10
|
from intentkit.abstracts.skill import SkillStoreABC
|
|
12
11
|
from intentkit.skills.base import IntentKitSkill
|
|
12
|
+
from intentkit.utils.error import RateLimitExceeded
|
|
13
13
|
|
|
14
14
|
CRYPTO_COMPARE_BASE_URL = "https://min-api.cryptocompare.com"
|
|
15
15
|
|
intentkit/skills/twitter/base.py
CHANGED
|
@@ -4,9 +4,9 @@ from typing import Type
|
|
|
4
4
|
from langchain.tools.base import ToolException
|
|
5
5
|
from pydantic import BaseModel, Field
|
|
6
6
|
|
|
7
|
-
from intentkit.abstracts.exception import RateLimitExceeded
|
|
8
7
|
from intentkit.abstracts.skill import SkillStoreABC
|
|
9
8
|
from intentkit.skills.base import IntentKitSkill
|
|
9
|
+
from intentkit.utils.error import RateLimitExceeded
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class TwitterBaseTool(IntentKitSkill):
|
intentkit/utils/error.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import logging
|
|
2
|
-
from typing import Sequence
|
|
2
|
+
from typing import Optional, Sequence
|
|
3
3
|
|
|
4
4
|
from fastapi.exceptions import RequestValidationError
|
|
5
5
|
from fastapi.utils import is_body_allowed_for_status_code
|
|
@@ -11,6 +11,16 @@ from starlette.status import HTTP_422_UNPROCESSABLE_ENTITY
|
|
|
11
11
|
|
|
12
12
|
logger = logging.getLogger(__name__)
|
|
13
13
|
|
|
14
|
+
# error messages in agent system message response
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class RateLimitExceeded(Exception):
|
|
18
|
+
"""Rate limit exceeded"""
|
|
19
|
+
|
|
20
|
+
def __init__(self, message: Optional[str] = "Rate limit exceeded"):
|
|
21
|
+
self.message = message
|
|
22
|
+
super().__init__(self.message)
|
|
23
|
+
|
|
14
24
|
|
|
15
25
|
class IntentKitAPIError(Exception):
|
|
16
26
|
def __init__(self, status_code: int, key: str, message: str):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: intentkit
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.17.dev1
|
|
4
4
|
Summary: Intent-based AI Agent Platform - Core Package
|
|
5
5
|
Project-URL: Homepage, https://github.com/crestal-network/intentkit
|
|
6
6
|
Project-URL: Repository, https://github.com/crestal-network/intentkit
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
intentkit/__init__.py,sha256=
|
|
1
|
+
intentkit/__init__.py,sha256=nrVmzsw-FXgMswUDzR-_-97LFjLL1u75kEX-38lWNyo,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
|
|
5
5
|
intentkit/abstracts/engine.py,sha256=C5C9d8vVMePhkKWURKIAbZSDZnmjxj5epL_04E6RpxQ,1449
|
|
6
|
-
intentkit/abstracts/exception.py,sha256=NX7u_eFP0Cowu6fK4QW8LmDqd_Vybm3_6W5UiO6nMYA,239
|
|
7
6
|
intentkit/abstracts/graph.py,sha256=sX5hVemXsODvwIYLHufaf-zSXmW97bXRoZuyxYqaEV4,1128
|
|
8
7
|
intentkit/abstracts/skill.py,sha256=cIJ6BkASD31U1IEkE8rdAawq99w_xsg0lt3oalqa1ZA,5071
|
|
9
8
|
intentkit/abstracts/twitter.py,sha256=cEtP7ygR_b-pHdc9i8kBuyooz1cPoGUGwsBHDpowJyY,1262
|
|
@@ -17,16 +16,16 @@ intentkit/core/agent.py,sha256=GIKDn1dTenIHWMRxe-ud7hd1cQaHzbTDdypy5IAgPfU,16658
|
|
|
17
16
|
intentkit/core/api.py,sha256=WfoaHNquujYJIpNPuTR1dSaaxog0S3X2W4lG9Ehmkm4,3284
|
|
18
17
|
intentkit/core/client.py,sha256=J5K7f08-ucszBKAbn9K3QNOFKIC__7amTbKYii1jFkI,3056
|
|
19
18
|
intentkit/core/credit.py,sha256=Y5cjShFFqGBhz7Uc_ziqejyW-2FP58TYxsSNc4N_6hI,63039
|
|
20
|
-
intentkit/core/engine.py,sha256=
|
|
19
|
+
intentkit/core/engine.py,sha256=H4ew1jhn2coMYJ3zR9isM1Y-XbnXNMg91SeDoeXdQ4U,36562
|
|
21
20
|
intentkit/core/node.py,sha256=7h9zgDSd928bzUi3m3EZnKkhbwqlbRAQUr_uz7gKB5Y,8880
|
|
22
|
-
intentkit/core/prompt.py,sha256=
|
|
21
|
+
intentkit/core/prompt.py,sha256=a6nogIGZuDt2u2EuDd29DAv73OjCBOn-bZnuqYRvY7A,15804
|
|
23
22
|
intentkit/core/skill.py,sha256=vPK37sDRT9kzkMBymPwqZ5uEdxTTRtb_DfREIeyz-Xw,5788
|
|
24
|
-
intentkit/models/agent.py,sha256
|
|
23
|
+
intentkit/models/agent.py,sha256=uC5AErdVucaEajKCXAcF6C3VwYRVIhXTIfOBp-n-Xhg,66310
|
|
25
24
|
intentkit/models/agent_data.py,sha256=mVsiK8TziYa1W1ujU1KwI9osIVIeSM7XJEogGRL1WVU,28263
|
|
26
|
-
intentkit/models/agent_schema.json,sha256=
|
|
27
|
-
intentkit/models/app_setting.py,sha256=
|
|
25
|
+
intentkit/models/agent_schema.json,sha256=_AaLP2fWsmx7psAYvumj1F_v9XzIPfHL7lpBvr1Y1QU,20890
|
|
26
|
+
intentkit/models/app_setting.py,sha256=iYbW63QD91bt4oEYV3wOXHuRFav2b4VXLwb_StgUQtQ,8230
|
|
28
27
|
intentkit/models/base.py,sha256=o-zRjVrak-f5Jokdvj8BjLm8gcC3yYiYMCTLegwT2lA,185
|
|
29
|
-
intentkit/models/chat.py,sha256=
|
|
28
|
+
intentkit/models/chat.py,sha256=TQUwyAjhcSFSDKxwYKWpubOu23U1WP6ejXlc0N53apU,20228
|
|
30
29
|
intentkit/models/conversation.py,sha256=nrbDIw-3GK5BYi_xkI15FLdx4a6SNrFK8wfAGLCsrqk,9032
|
|
31
30
|
intentkit/models/credit.py,sha256=bcasHyrCwforLGrH8ZWEvN6y6ml7NeAFrGl8cfqvqbI,42956
|
|
32
31
|
intentkit/models/db.py,sha256=nuDX6NEtnfD5YLr2iVpAAXsgHbSpG5diqfLC-PkHsA4,4406
|
|
@@ -37,7 +36,7 @@ intentkit/models/redis.py,sha256=UoN8jqLREO1VO9_w6m-JhldpP19iEHj4TiGVCMutQW4,370
|
|
|
37
36
|
intentkit/models/skill.py,sha256=h_2wtKEbYE29TLsMdaSnjfOv6vXY6GwMU_abw-ONX28,16374
|
|
38
37
|
intentkit/models/user.py,sha256=P7l6LOsZmXZ5tDPTczTbqDtDB_MKc_9_ddZkAB2npPk,9288
|
|
39
38
|
intentkit/skills/__init__.py,sha256=WkjmKB4xvy36zyXMroPMf_DTPgQloNS3L73nVnBmuQI,303
|
|
40
|
-
intentkit/skills/base.py,sha256=
|
|
39
|
+
intentkit/skills/base.py,sha256=9WZ7Q6M1mUSFvFO5ak9MEbiAqjMBVqdyEiVQV5YHTzg,6954
|
|
41
40
|
intentkit/skills/skills.toml,sha256=iFMn_UmdFFCk4HTHolpSv6Ve6O-iRckJtxVcZ5EjxQM,2634
|
|
42
41
|
intentkit/skills/acolyt/__init__.py,sha256=qHQXFlqyyx4deRxC0rts_ZEEpDVV-vWXPncqI_ZMOi4,2074
|
|
43
42
|
intentkit/skills/acolyt/acolyt.jpg,sha256=CwrrouzXzYvnHi1rprYruvZqPopG06ppMczEZmZ7D2s,11559
|
|
@@ -93,7 +92,7 @@ intentkit/skills/cookiefun/schema.json,sha256=O3tRvf3IWSMp3yInwXB_6K3CNdjTnf0aOv
|
|
|
93
92
|
intentkit/skills/cookiefun/search_accounts.py,sha256=3tlSSPNlL7DVkuEPr30cvceY99nPEarhTSA5aK3iHic,8722
|
|
94
93
|
intentkit/skills/cryptocompare/__init__.py,sha256=xAsUcZjqNKvKSe5EXe_7DnDaVnm7ykbBXKwI1JlgoCU,3852
|
|
95
94
|
intentkit/skills/cryptocompare/api.py,sha256=6WcnqhxElHaLJXCCNjNBPKS6Fdivpgfg3d8U4Thuk2E,5650
|
|
96
|
-
intentkit/skills/cryptocompare/base.py,sha256=
|
|
95
|
+
intentkit/skills/cryptocompare/base.py,sha256=5J755FcDY3ie_udHBx3PI3ZHag7_P1wgwoZL9ao_gws,10898
|
|
97
96
|
intentkit/skills/cryptocompare/cryptocompare.png,sha256=gyoMlbOO7woL9yfEDSs4OwA8arVIflsRkLASR6PhiDs,27394
|
|
98
97
|
intentkit/skills/cryptocompare/fetch_news.py,sha256=LJOigHx6EgD0_PkORCxaaeoFmT5k2NDAU00ZJ3FefK4,3320
|
|
99
98
|
intentkit/skills/cryptocompare/fetch_price.py,sha256=f2Ht1WDucF-rUpn4ANAU1XM-b_MqiqDeBZydjXO4l7Y,3418
|
|
@@ -320,7 +319,7 @@ intentkit/skills/token/token_analytics.py,sha256=NRlLATnpvchEXg3_phX0Qg_lnQ3Szk4
|
|
|
320
319
|
intentkit/skills/token/token_price.py,sha256=fTvfVtQA5N4QG22C66SzZUn_XlnpDVeojPedfz0crQc,4531
|
|
321
320
|
intentkit/skills/token/token_search.py,sha256=blbtJ-0lQlhrjWLJHB8uMg5offJCbghuaTLRpm8vewE,4205
|
|
322
321
|
intentkit/skills/twitter/__init__.py,sha256=VPww1hJOw3wetWAZp4HfsdPkbpe4zjJ5JbKTkqDz1ME,4484
|
|
323
|
-
intentkit/skills/twitter/base.py,sha256=
|
|
322
|
+
intentkit/skills/twitter/base.py,sha256=D2Ib0SAXMzydPfTW5g55mwZAVDscQ-rRIcrmT_J5ZE0,3932
|
|
324
323
|
intentkit/skills/twitter/follow_user.py,sha256=fb5ferc428o-ykGqoJNRrKmpl8tKRlThZmtMOkN7Gk8,2267
|
|
325
324
|
intentkit/skills/twitter/get_mentions.py,sha256=C-4pOrWiqmuv5IpmUy2sYjNj8sZGeXo_cJdomWuDpN0,4132
|
|
326
325
|
intentkit/skills/twitter/get_timeline.py,sha256=xWWITCGBbj98C14E7E-NC6tbAsfR6zatNni9tJgU-CI,3729
|
|
@@ -397,13 +396,13 @@ intentkit/skills/xmtp/transfer.py,sha256=qmSIsSrWR-S5JFlBP4YjxudsWlKsCpp-JjDQjYU
|
|
|
397
396
|
intentkit/skills/xmtp/xmtp.png,sha256=vQzT-71zIb8aPodg-GkGSQbBnjGAPczWGm3es2ZkJe8,6681
|
|
398
397
|
intentkit/utils/__init__.py,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
399
398
|
intentkit/utils/chain.py,sha256=3GBHuAbXxQr_HlOvkbB2kruYSkweucfxI5u-swXzY40,15135
|
|
400
|
-
intentkit/utils/error.py,sha256=
|
|
399
|
+
intentkit/utils/error.py,sha256=sDMIQPAlE5igzQKCsyN7BLR1otgErcNm0Uak_Rfl8SI,4755
|
|
401
400
|
intentkit/utils/logging.py,sha256=bhwZi5vscjBTd9kaNp_L6ijrfv9Sl3lsr4ARaUB4Iec,2389
|
|
402
401
|
intentkit/utils/random.py,sha256=DymMxu9g0kuQLgJUqalvgksnIeLdS-v0aRk5nQU0mLI,452
|
|
403
402
|
intentkit/utils/s3.py,sha256=9trQNkKQ5VgxWsewVsV8Y0q_pXzGRvsCYP8xauyUYkg,8549
|
|
404
403
|
intentkit/utils/slack_alert.py,sha256=s7UpRgyzLW7Pbmt8cKzTJgMA9bm4EP-1rQ5KXayHu6E,2264
|
|
405
404
|
intentkit/utils/tx.py,sha256=2yLLGuhvfBEY5n_GJ8wmIWLCzn0FsYKv5kRNzw_sLUI,1454
|
|
406
|
-
intentkit-0.6.
|
|
407
|
-
intentkit-0.6.
|
|
408
|
-
intentkit-0.6.
|
|
409
|
-
intentkit-0.6.
|
|
405
|
+
intentkit-0.6.17.dev1.dist-info/METADATA,sha256=bYvIjFL2d5KPcDfJI94L6mSNfYoDMeV4g5I2epVqme8,6414
|
|
406
|
+
intentkit-0.6.17.dev1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
407
|
+
intentkit-0.6.17.dev1.dist-info/licenses/LICENSE,sha256=Bln6DhK-LtcO4aXy-PBcdZv2f24MlJFm_qn222biJtE,1071
|
|
408
|
+
intentkit-0.6.17.dev1.dist-info/RECORD,,
|
intentkit/abstracts/exception.py
DELETED
|
File without changes
|
|
File without changes
|