1+ # Tencent is pleased to support the open source community by making tRPC-Agent-Python available.
2+ #
3+ # Copyright (C) 2026 Tencent. All rights reserved.
4+ #
5+ # tRPC-Agent-Python is licensed under Apache-2.0.
6+ """CR Skill integration for the code review agent.
7+
8+ Wraps the code-review Skill as a SkillToolSet, allowing the Agent to
9+ load rules on demand and run scripts in an isolated sandbox environment.
10+ """
11+
12+ from __future__ import annotations
13+
14+ import os
15+ from pathlib import Path
16+ from typing import Any , Optional
17+
18+ from trpc_agent_sdk .code_executors import ContainerCodeExecutor , UnsafeLocalCodeExecutor
19+ from trpc_agent_sdk .skills import SkillToolSet
20+
21+
22+ def get_skill_path () -> str :
23+ """Get the absolute path to the code-review skill directory."""
24+ return str (Path (__file__ ).resolve ().parent .parent / "skills" / "code-review" )
25+
26+
27+ def create_skill_toolset (
28+ sandbox_type : str = "local" ,
29+ timeout : int = 30 ,
30+ max_output : int = 1_048_576 ,
31+ ) -> SkillToolSet :
32+ """Create a SkillToolSet for the code-review skill.
33+
34+ Args:
35+ sandbox_type: Sandbox executor type ("local", "container", "cube").
36+ timeout: Max execution time in seconds for each script.
37+ max_output: Max output size in bytes.
38+
39+ Returns:
40+ A configured SkillToolSet instance.
41+ """
42+ skill_path = get_skill_path ()
43+
44+ # Select sandbox executor
45+ if sandbox_type == "container" :
46+ code_executor = ContainerCodeExecutor (
47+ timeout = timeout ,
48+ max_output_size = max_output ,
49+ env_whitelist = ["PATH" , "HOME" , "PYTHONPATH" , "WORKSPACE_DIR" ],
50+ )
51+ else :
52+ code_executor = UnsafeLocalCodeExecutor (
53+ timeout = timeout ,
54+ max_output_size = max_output ,
55+ )
56+
57+ return SkillToolSet (
58+ skill_dir = skill_path ,
59+ code_executor = code_executor ,
60+ )
61+
62+
63+ # Global singleton for easy import
64+ _default_skill_set : Optional [SkillToolSet ] = None
65+
66+
67+ def get_skill_toolset () -> SkillToolSet :
68+ """Get or create the default skill toolset (local sandbox)."""
69+ global _default_skill_set
70+ if _default_skill_set is None :
71+ _default_skill_set = create_skill_toolset ()
72+ return _default_skill_set
0 commit comments