1414from typing import Any , Dict , List , Optional , Tuple , Callable , Awaitable
1515
1616from derisk ._private .pydantic import Field , PrivateAttr
17+ from derisk .configs .model_config import DATA_DIR
18+ import os
1719from derisk .agent import (
1820 ActionOutput ,
1921 Agent ,
@@ -1402,6 +1404,21 @@ async def var_available_knowledges(instance):
14021404 async def var_skills (instance ):
14031405 logger .info ("注入技能资源" )
14041406
1407+ # Sandbox mode: skill_dir comes from the sandbox client
1408+ # (e.g. /mnt/derisk/skills set in [sandbox].skill_dir of the toml).
1409+ # Local mode: default to DATA_DIR/skill (pilot/data/skill).
1410+ sandbox_skill_dir : Optional [str ] = None
1411+ if instance and getattr (instance , "sandbox_manager" , None ):
1412+ sb_client = getattr (instance .sandbox_manager , "client" , None )
1413+ if sb_client :
1414+ sandbox_skill_dir = getattr (sb_client , "skill_dir" , None )
1415+
1416+ local_skill_dir = os .path .join (DATA_DIR , "skill" )
1417+ logger .info (
1418+ f"var_skills: sandbox_skill_dir={ sandbox_skill_dir !r} , "
1419+ f"local_skill_dir={ local_skill_dir !r} "
1420+ )
1421+
14051422 prompts = ""
14061423 for k , v in self .resource_map .items ():
14071424 if isinstance (v [0 ], AgentSkillResource ):
@@ -1414,11 +1431,34 @@ async def var_skills(instance):
14141431 skill_meta = skill_item .skill_meta (mode )
14151432 if not skill_meta :
14161433 continue
1417- skill_path = (
1418- skill_item ._skill .parent_folder
1419- if hasattr (skill_item , "_skill" ) and skill_item ._skill
1420- else skill_meta .path
1421- )
1434+
1435+ # skill_code is the UUID (DeriskSkillResource) or dir name.
1436+ skill_code = getattr (
1437+ skill_item , "_skill_code" , None
1438+ ) or getattr (skill_item , "skill_code" , None )
1439+ if not skill_code and skill_meta .path :
1440+ skill_code = os .path .basename (skill_meta .path )
1441+
1442+ # Use sandbox path only when the skill directory actually
1443+ # exists inside the sandbox; otherwise fall back to local.
1444+ if os .path .isdir (os .path .join (sandbox_skill_dir , skill_code )):
1445+ skill_path = os .path .join (sandbox_skill_dir ,skill_code )
1446+ else :
1447+ skill_path = os .path .join (local_skill_dir ,skill_item ._skill_path )
1448+
1449+
1450+ # if skill_code and sandbox_skill_dir:
1451+ # sandbox_path = os.path.join(sandbox_skill_dir, skill_code)
1452+ # skill_path = (
1453+ # sandbox_path
1454+ # if os.path.exists(sandbox_path)
1455+ # else os.path.join(local_skill_dir, skill_code)
1456+ # )
1457+ # elif skill_code:
1458+ # skill_path = os.path.join(local_skill_dir, skill_code)
1459+ # else:
1460+ # skill_path = skill_meta.path
1461+
14221462 prompts += (
14231463 f"- <skill>"
14241464 f"<name>{ skill_meta .name } </name>"
0 commit comments