-
Notifications
You must be signed in to change notification settings - Fork 672
/
Copy pathskill.py
123 lines (102 loc) · 3.34 KB
/
skill.py
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
from typing import Any, Dict, Optional
from abstracts.skill import SkillStoreABC
from app.config.config import config
from models.agent import Agent, AgentData, AgentQuota
from models.skill import (
AgentSkillData,
AgentSkillDataCreate,
ThreadSkillData,
ThreadSkillDataCreate,
)
class SkillStore(SkillStoreABC):
"""Implementation of skill data storage operations.
This class provides concrete implementations for storing and retrieving
skill-related data for both agents and threads.
"""
@staticmethod
def get_system_config(key: str) -> Any:
# TODO: maybe need a whitelist here
if hasattr(config, key):
return getattr(config, key)
return None
@staticmethod
async def get_agent_config(agent_id: str) -> Optional[Agent]:
return await Agent.get(agent_id)
@staticmethod
async def get_agent_data(agent_id: str) -> Optional[AgentData]:
return await AgentData.get(agent_id)
@staticmethod
async def set_agent_data(agent_id: str, data: Dict) -> None:
return await AgentData.patch(agent_id, data)
@staticmethod
async def get_agent_quota(agent_id: str) -> Optional[AgentQuota]:
return await AgentQuota.get(agent_id)
@staticmethod
async def get_agent_skill_data(
agent_id: str, skill: str, key: str
) -> Optional[Dict[str, Any]]:
"""Get skill data for an agent.
Args:
agent_id: ID of the agent
skill: Name of the skill
key: Data key
Returns:
Dictionary containing the skill data if found, None otherwise
"""
return await AgentSkillData.get(agent_id, skill, key)
@staticmethod
async def save_agent_skill_data(
agent_id: str, skill: str, key: str, data: Dict[str, Any]
) -> None:
"""Save or update skill data for an agent.
Args:
agent_id: ID of the agent
skill: Name of the skill
key: Data key
data: JSON data to store
"""
skill_data = AgentSkillDataCreate(
agent_id=agent_id,
skill=skill,
key=key,
data=data,
)
await skill_data.save()
@staticmethod
async def get_thread_skill_data(
thread_id: str, skill: str, key: str
) -> Optional[Dict[str, Any]]:
"""Get skill data for a thread.
Args:
thread_id: ID of the thread
skill: Name of the skill
key: Data key
Returns:
Dictionary containing the skill data if found, None otherwise
"""
return await ThreadSkillData.get(thread_id, skill, key)
@staticmethod
async def save_thread_skill_data(
thread_id: str,
agent_id: str,
skill: str,
key: str,
data: Dict[str, Any],
) -> None:
"""Save or update skill data for a thread.
Args:
thread_id: ID of the thread
agent_id: ID of the agent that owns this thread
skill: Name of the skill
key: Data key
data: JSON data to store
"""
skill_data = ThreadSkillDataCreate(
thread_id=thread_id,
agent_id=agent_id,
skill=skill,
key=key,
data=data,
)
await skill_data.save()
skill_store = SkillStore()