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

Function main

examples/agent-working-memory/main.go:29–142  ·  view source on GitHub ↗

使用场景: - 记住用户偏好和设置 - 跟踪任务进度 - 维护会话状态

()

Source from the content-addressed store, hash-verified

27// - 维护会话状态
28
29func main() {
30 // 检查 API Key
31 apiKey := os.Getenv("ANTHROPIC_API_KEY")
32 if apiKey == "" {
33 log.Fatal("ANTHROPIC_API_KEY environment variable is required")
34 }
35
36 ctx := context.Background()
37
38 // 1. 工具注册表
39 toolRegistry := tools.NewRegistry()
40 builtin.RegisterAll(toolRegistry)
41
42 // 2. Sandbox 工厂
43 sandboxFactory := sandbox.NewFactory()
44
45 // 3. Provider 工厂
46 providerFactory := &provider.AnthropicFactory{}
47
48 // 4. Store
49 jsonStore, err := store.NewJSONStore(".aster-working-memory")
50 if err != nil {
51 log.Fatalf("create store failed: %v", err)
52 }
53
54 // 5. 模板注册表
55 templateRegistry := agent.NewTemplateRegistry()
56 templateRegistry.Register(&types.AgentTemplateDefinition{
57 ID: "task-assistant",
58 SystemPrompt: `You are a helpful task assistant with Working Memory.
59
60Your capabilities:
61- Remember user information and preferences
62- Track task progress across multiple conversations
63- Maintain context between sessions
64
65When you learn something important about the user or their tasks, use the update_working_memory tool to store it.
66
67Remember: Working Memory is automatically loaded at the start of each conversation, so you always have access to it.`,
68 Model: "claude-sonnet-4-5",
69 // 基础工具,working memory 工具由中间件自动注入
70 Tools: []any{"Read", "Write", "Bash"},
71 })
72
73 deps := &agent.Dependencies{
74 Store: jsonStore,
75 SandboxFactory: sandboxFactory,
76 ToolRegistry: toolRegistry,
77 ProviderFactory: providerFactory,
78 TemplateRegistry: templateRegistry,
79 }
80
81 // 6. 工作目录
82 workDir := "./workspace"
83 if err := os.MkdirAll(workDir, 0o755); err != nil {
84 log.Fatalf("create workspace dir failed: %v", err)
85 }
86

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
NewRegistryFunction · 0.92
RegisterAllFunction · 0.92
NewFactoryFunction · 0.92
NewJSONStoreFunction · 0.92
NewTemplateRegistryFunction · 0.92
CreateFunction · 0.92
PrintfMethod · 0.80
runDemoFunction · 0.70
CloseMethod · 0.65
IDMethod · 0.65
SubscribeMethod · 0.65

Tested by

no test coverage detected