1717import os
1818import frontmatter
1919
20+ from google .adk .tools import BaseTool , ToolContext
21+ from typing import Any , Dict , Optional , Callable
22+
2023from veadk .skills .skill import Skill
2124from veadk .utils .logger import get_logger
2225from veadk .utils .volcengine_sign import ve_request
2326
2427logger = get_logger (__name__ )
2528
2629
30+ def update_check_list (
31+ tool_context : ToolContext , skill_name : str , check_item : str , state : bool
32+ ):
33+ """
34+ Update the checklist item state for a specific skill.
35+ Use this tool to mark checklist items as completed during skill execution.
36+
37+ eg:
38+ update_check_list(skill_name="skill-creator", check_item="analyze_content", state=True)
39+ """
40+ agent_name = tool_context .agent_name
41+ if agent_name not in tool_context .state :
42+ tool_context .state [agent_name ] = {}
43+ if skill_name not in tool_context .state [agent_name ]:
44+ tool_context .state [agent_name ][skill_name ] = {}
45+ if "check_list" not in tool_context .state [agent_name ][skill_name ]:
46+ tool_context .state [agent_name ][skill_name ]["check_list" ] = {}
47+ tool_context .state [agent_name ][skill_name ]["check_list" ][check_item ] = state
48+ logger .info (f"Updated agent[{ agent_name } ] state: { tool_context .state [agent_name ]} " )
49+
50+
51+ def create_init_skill_check_list_callback (
52+ skills_with_checklist : Dict [str , Skill ],
53+ ) -> Callable [[BaseTool , Dict [str , Any ], ToolContext ], Optional [Dict ]]:
54+ """
55+ Create a callback function to initialize checklist when a skill is invoked.
56+
57+ Args:
58+ skills_with_checklist: Dictionary mapping skill names to Skill objects
59+
60+ Returns:
61+ A callback function for before_tool_callback
62+ """
63+
64+ def init_skill_check_list (
65+ tool : BaseTool , args : Dict [str , Any ], tool_context : ToolContext
66+ ) -> Optional [Dict ]:
67+ """Callback to initialize checklist when a skill is invoked."""
68+ if tool .name == "skills_tool" :
69+ skill_name = args .get ("command" )
70+ agent_name = tool_context .agent_name
71+ if skill_name in skills_with_checklist :
72+ skill = skills_with_checklist [skill_name ]
73+ check_list_items = skill .get_checklist_items ()
74+ check_list_state = {item : False for item in check_list_items }
75+ if agent_name not in tool_context .state :
76+ tool_context .state [agent_name ] = {}
77+ tool_context .state [agent_name ][skill_name ] = {
78+ "check_list" : check_list_state
79+ }
80+ logger .info (
81+ f"Initialized agent[{ agent_name } ] skill[{ skill_name } ] check_list: { check_list_state } "
82+ )
83+ return None
84+
85+ return init_skill_check_list
86+
87+
2788def load_skill_from_directory (skill_directory : Path ) -> Skill :
2889 logger .info (f"Load skill from { skill_directory } " )
2990 skill_readme = skill_directory / "SKILL.md"
@@ -35,6 +96,7 @@ def load_skill_from_directory(skill_directory: Path) -> Skill:
3596
3697 skill_name = skill .get ("name" , "" )
3798 skill_description = skill .get ("description" , "" )
99+ checklist = skill .get ("checklist" , [])
38100
39101 if not skill_name or not skill_description :
40102 logger .error (
@@ -47,10 +109,14 @@ def load_skill_from_directory(skill_directory: Path) -> Skill:
47109 logger .info (
48110 f"Successfully loaded skill { skill_name } locally from { skill_readme } , name={ skill_name } , description={ skill_description } "
49111 )
112+ if checklist :
113+ logger .info (f"Skill { skill_name } checklist: { checklist } " )
114+
50115 return Skill (
51116 name = skill_name , # type: ignore
52117 description = skill_description , # type: ignore
53118 path = str (skill_directory ),
119+ checklist = checklist ,
54120 )
55121
56122
0 commit comments