Skip to content

Commit 7c135b0

Browse files
authored
feat: automatically detect changes of skills (#513)
* feat: automatically detect changes of skills * fix: add license header * fix: fix conflict
1 parent 36b93b0 commit 7c135b0

File tree

2 files changed

+391
-8
lines changed

2 files changed

+391
-8
lines changed

veadk/agent.py

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ class Agent(LlmAgent):
8686
skills (list[str]): List of skills that equip the agent with specific capabilities.
8787
example_store (Optional[BaseExampleProvider]): Example store for providing example Q/A.
8888
enable_shadowchar (bool): Whether to enable shadow character for the agent.
89+
enable_dynamic_load_skills (bool): Whether to enable dynamic loading of skills.
8990
"""
9091

9192
model_config = ConfigDict(arbitrary_types_allowed=True, extra="allow")
@@ -156,6 +157,7 @@ class Agent(LlmAgent):
156157

157158
enable_dataset_gen: bool = False
158159

160+
enable_dynamic_load_skills: bool = False
159161
_skills_with_checklist: Dict[str, Any] = {}
160162

161163
def model_post_init(self, __context: Any) -> None:
@@ -364,13 +366,14 @@ def load_skills(self):
364366
from pathlib import Path
365367

366368
from veadk.skills.skill import Skill
369+
from veadk.skills.check_skills_callback import check_skills
367370
from veadk.skills.utils import (
368371
load_skills_from_cloud,
369372
load_skills_from_directory,
370373
)
371374
from veadk.tools.skills_tools.skills_toolset import SkillsToolset
372375

373-
skills: Dict[str, Skill] = {}
376+
self.skills_dict: Dict[str, Skill] = {}
374377

375378
# Determine skills_mode if not set
376379
if not self.skills_mode:
@@ -445,17 +448,17 @@ def load_skills(self):
445448
path = Path(item)
446449
if path.exists() and path.is_dir():
447450
for skill in load_skills_from_directory(path):
448-
skills[skill.name] = skill
451+
self.skills_dict[skill.name] = skill
449452
else:
450453
for skill in load_skills_from_cloud(item):
451-
skills[skill.name] = skill
452-
if skills:
453-
self._skills_with_checklist = skills
454-
454+
self.skills_dict[skill.name] = skill
455+
if self.skills_dict:
455456
self.instruction += "\nYou have the following skills:\n"
456457

458+
self._skills_with_checklist = self.skills_dict
459+
457460
has_checklist = False
458-
for skill in skills.values():
461+
for skill in self.skills_dict.values():
459462
self.instruction += (
460463
f"- name: {skill.name}\n- description: {skill.description}\n\n"
461464
)
@@ -487,10 +490,22 @@ def load_skills(self):
487490
"You can use the skills by calling the `skills_tool` tool.\n\n"
488491
)
489492

490-
self.tools.append(SkillsToolset(skills, self.skills_mode))
493+
self.tools.append(SkillsToolset(self.skills_dict, self.skills_mode))
491494
else:
492495
logger.warning("No skills loaded.")
493496

497+
if self.enable_dynamic_load_skills and self.skills_dict:
498+
if self.before_agent_callback:
499+
if isinstance(self.before_agent_callback, list):
500+
self.before_agent_callback.append(check_skills)
501+
else:
502+
self.before_agent_callback = [
503+
self.before_agent_callback,
504+
check_skills,
505+
]
506+
else:
507+
self.before_agent_callback = check_skills
508+
494509
def _prepare_tracers(self):
495510
enable_apmplus_tracer = os.getenv("ENABLE_APMPLUS", "false").lower() == "true"
496511
enable_cozeloop_tracer = os.getenv("ENABLE_COZELOOP", "false").lower() == "true"

0 commit comments

Comments
 (0)