feat: add skills for specific tools (#366)
Co-authored-by: 0xallam <ahmed39652003@gmail.com>
This commit is contained in:
4
strix/tools/load_skill/__init__.py
Normal file
4
strix/tools/load_skill/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from .load_skill_actions import load_skill
|
||||
|
||||
|
||||
__all__ = ["load_skill"]
|
||||
71
strix/tools/load_skill/load_skill_actions.py
Normal file
71
strix/tools/load_skill/load_skill_actions.py
Normal file
@@ -0,0 +1,71 @@
|
||||
from typing import Any
|
||||
|
||||
from strix.tools.registry import register_tool
|
||||
|
||||
|
||||
@register_tool(sandbox_execution=False)
|
||||
def load_skill(agent_state: Any, skills: str) -> dict[str, Any]:
|
||||
try:
|
||||
from strix.skills import parse_skill_list, validate_requested_skills
|
||||
|
||||
requested_skills = parse_skill_list(skills)
|
||||
if not requested_skills:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "No skills provided. Pass one or more comma-separated skill names.",
|
||||
"requested_skills": [],
|
||||
}
|
||||
|
||||
validation_error = validate_requested_skills(requested_skills)
|
||||
if validation_error:
|
||||
return {
|
||||
"success": False,
|
||||
"error": validation_error,
|
||||
"requested_skills": requested_skills,
|
||||
"loaded_skills": [],
|
||||
}
|
||||
|
||||
from strix.tools.agents_graph.agents_graph_actions import _agent_instances
|
||||
|
||||
current_agent = _agent_instances.get(agent_state.agent_id)
|
||||
if current_agent is None or not hasattr(current_agent, "llm"):
|
||||
return {
|
||||
"success": False,
|
||||
"error": (
|
||||
"Could not find running agent instance for runtime skill loading. "
|
||||
"Try again in the current active agent."
|
||||
),
|
||||
"requested_skills": requested_skills,
|
||||
"loaded_skills": [],
|
||||
}
|
||||
|
||||
newly_loaded = current_agent.llm.add_skills(requested_skills)
|
||||
already_loaded = [skill for skill in requested_skills if skill not in newly_loaded]
|
||||
|
||||
prior = agent_state.context.get("loaded_skills", [])
|
||||
if not isinstance(prior, list):
|
||||
prior = []
|
||||
merged_skills = sorted(set(prior).union(requested_skills))
|
||||
agent_state.update_context("loaded_skills", merged_skills)
|
||||
|
||||
except Exception as e: # noqa: BLE001
|
||||
fallback_requested_skills = (
|
||||
requested_skills
|
||||
if "requested_skills" in locals()
|
||||
else [s.strip() for s in skills.split(",") if s.strip()]
|
||||
)
|
||||
return {
|
||||
"success": False,
|
||||
"error": f"Failed to load skill(s): {e!s}",
|
||||
"requested_skills": fallback_requested_skills,
|
||||
"loaded_skills": [],
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"success": True,
|
||||
"requested_skills": requested_skills,
|
||||
"loaded_skills": requested_skills,
|
||||
"newly_loaded_skills": newly_loaded,
|
||||
"already_loaded_skills": already_loaded,
|
||||
"message": "Skills loaded into this agent prompt context.",
|
||||
}
|
||||
33
strix/tools/load_skill/load_skill_actions_schema.xml
Normal file
33
strix/tools/load_skill/load_skill_actions_schema.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<tools>
|
||||
<tool name="load_skill">
|
||||
<description>Dynamically load one or more skills into the current agent at runtime.
|
||||
|
||||
Use this when you need exact guidance right before acting (tool syntax, exploit workflow, or protocol details).
|
||||
This updates the current agent's prompt context immediately.</description>
|
||||
<details>Accepts one skill or a comma-separated skill bundle. Works for root agents and subagents.
|
||||
Examples:
|
||||
- Single skill: `xss`
|
||||
- Bundle: `sql_injection,business_logic`</details>
|
||||
<parameters>
|
||||
<parameter name="skills" type="string" required="true">
|
||||
<description>Comma-separated list of skills to use for the agent (MAXIMUM 5 skills allowed). Most agents should have at least one skill in order to be useful. Agents should be highly specialized - use 1-3 related skills; up to 5 for complex contexts. {{DYNAMIC_SKILLS_DESCRIPTION}}</description>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<returns type="Dict[str, Any]">
|
||||
<description>Response containing: - success: Whether runtime loading succeeded - requested_skills: Skills requested - loaded_skills: Skills validated and applied - newly_loaded_skills: Skills newly injected into prompt - already_loaded_skills: Skills already present in prompt context</description>
|
||||
</returns>
|
||||
<examples>
|
||||
<function=load_skill>
|
||||
<parameter=skills>xss</parameter>
|
||||
</function>
|
||||
|
||||
<function=load_skill>
|
||||
<parameter=skills>sql_injection,business_logic</parameter>
|
||||
</function>
|
||||
|
||||
<function=load_skill>
|
||||
<parameter=skills>nmap,httpx</parameter>
|
||||
</function>
|
||||
</examples>
|
||||
</tool>
|
||||
</tools>
|
||||
Reference in New Issue
Block a user