MCPcopy Create free account
hub / github.com/astercloud/aster / buildToolContext

Method buildToolContext

pkg/agent/agent.go:1232–1275  ·  view source on GitHub ↗

buildToolContext 构造工具执行上下文, 注入必要的服务。 当前会注入: - tool_manuals: 工具手册映射,供 ToolHelp 等工具使用 - skills_runtime: *skills.Runtime, 供 skill_call 工具使用 (仅当 Agent 配置了 SkillsPackage 时) - plan_mode_manager: *PlanModeManager, 供 EnterPlanMode/ExitPlanMode 工具使用

(ctx context.Context)

Source from the content-addressed store, hash-verified

1230// - skills_runtime: *skills.Runtime, 供 skill_call 工具使用 (仅当 Agent 配置了 SkillsPackage 时)
1231// - plan_mode_manager: *PlanModeManager, 供 EnterPlanMode/ExitPlanMode 工具使用
1232func (a *Agent) buildToolContext(ctx context.Context) *tools.ToolContext {
1233 tc := &tools.ToolContext{
1234 AgentID: a.id,
1235 Sandbox: a.sandbox,
1236 Signal: ctx,
1237 Services: make(map[string]any),
1238 }
1239
1240 // 为 ToolHelp 等工具注入当前可用工具的手册信息, 支持按需查询。
1241 if len(a.toolMap) > 0 {
1242 manuals := make(map[string]string, len(a.toolMap))
1243 for name, tool := range a.toolMap {
1244 if prompt := tool.Prompt(); prompt != "" {
1245 manuals[name] = prompt
1246 }
1247 }
1248 if len(manuals) > 0 {
1249 tc.Services["tool_manuals"] = manuals
1250 }
1251 }
1252
1253 // 如果 Agent 启用了 SkillsPackage, 为工具注入 Skills Runtime
1254 if a.config != nil && a.config.SkillsPackage != nil {
1255 basePath := a.config.SkillsPackage.Path
1256 if basePath == "" {
1257 basePath = "." // 相对于 sandbox.WorkDir
1258 }
1259 skillsDir := a.config.SkillsPackage.SkillsDir
1260 if skillsDir == "" {
1261 skillsDir = "skills"
1262 }
1263 fullSkillsDir := filepath.Join(basePath, skillsDir)
1264 loader := skills.NewLoader(fullSkillsDir, a.sandbox.FS())
1265 rt := skills.NewRuntime(loader, a.sandbox)
1266 tc.Services["skills_runtime"] = rt
1267 }
1268
1269 // 注入 PlanModeManager,供 EnterPlanMode/ExitPlanMode 工具使用
1270 if a.planMode != nil {
1271 tc.Services["plan_mode_manager"] = a.planMode
1272 }
1273
1274 return tc
1275}
1276
1277// handleSlashCommand 处理 slash command
1278func (a *Agent) handleSlashCommand(ctx context.Context, text string) error {

Callers 3

executeToolCallsMethod · 0.95
executeSingleToolMethod · 0.95
ExecuteToolDirectMethod · 0.95

Calls 5

NewLoaderFunction · 0.92
NewRuntimeFunction · 0.92
PromptMethod · 0.65
FSMethod · 0.65
JoinMethod · 0.45

Tested by

no test coverage detected