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

Function main

examples/ptc/file-processor/main.go:18–174  ·  view source on GitHub ↗

文件批处理示例 演示如何使用 PTC 进行复杂的文件处理任务

()

Source from the content-addressed store, hash-verified

16// 文件批处理示例
17// 演示如何使用 PTC 进行复杂的文件处理任务
18func main() {
19 // 检查 API Key
20 apiKey := os.Getenv("ANTHROPIC_API_KEY")
21 if apiKey == "" {
22 log.Fatal("请设置环境变量 ANTHROPIC_API_KEY")
23 }
24
25 fmt.Println("=== Aster PTC 文件处理示例 ===")
26
27 // 1. 创建工具生态系统
28 registry := tools.NewRegistry()
29 builtin.RegisterAll(registry)
30
31 toolBridge := bridge.NewToolBridge(registry)
32 codeExecTool := builtin.NewCodeExecuteToolWithBridge(toolBridge)
33
34 // 2. 准备工具列表(启用 PTC)
35 toolSchemas := []provider.ToolSchema{
36 {
37 Name: "CodeExecute",
38 Description: codeExecTool.Description(),
39 InputSchema: codeExecTool.InputSchema(),
40 AllowedCallers: []string{"direct"},
41 },
42 }
43
44 // 添加可在 Python 中调用的工具
45 allowedTools := []string{"Read", "Write", "Glob", "Grep", "Bash"}
46 for _, toolName := range allowedTools {
47 tool, _ := registry.Create(toolName, nil)
48 toolSchemas = append(toolSchemas, provider.ToolSchema{
49 Name: toolName,
50 Description: tool.Description(),
51 InputSchema: tool.InputSchema(),
52 AllowedCallers: []string{"direct", "code_execution_20250825"},
53 })
54 }
55
56 // 3. 创建 Anthropic Provider
57 providerConfig := &types.ModelConfig{
58 Provider: "anthropic",
59 Model: "claude-3-5-sonnet-20241022",
60 APIKey: apiKey,
61 }
62
63 anthropicProvider, err := provider.NewAnthropicProvider(providerConfig)
64 if err != nil {
65 log.Fatalf("创建 Provider 失败: %v", err)
66 }
67
68 // 4. 定义复杂任务
69 task := `请编写 Python 代码完成以下文件处理任务:
70
711. 使用 Glob 查找当前目录下所有 .go 文件
722. 使用 Grep 在这些文件中搜索包含 "TODO""FIXME" 的注释
733. 统计每个文件中待办事项的数量
744. 生成一份 Markdown 格式的报告,包含:
75 - 总待办事项数量

Callers

nothing calls this directly

Calls 12

InputSchemaMethod · 0.95
CreateMethod · 0.95
DescriptionMethod · 0.95
CompleteMethod · 0.95
ExecuteMethod · 0.95
NewRegistryFunction · 0.92
RegisterAllFunction · 0.92
NewToolBridgeFunction · 0.92
NewAnthropicProviderFunction · 0.92
PrintfMethod · 0.80
DescriptionMethod · 0.65

Tested by

no test coverage detected