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

Function createTestAgent

examples/openrouter/testutil_test.go:17–63  ·  view source on GitHub ↗

createTestAgent 创建测试用 Agent

(apiKey string)

Source from the content-addressed store, hash-verified

15
16// createTestAgent 创建测试用 Agent
17func createTestAgent(apiKey string) (*agent.Agent, error) {
18 baseURL := os.Getenv("OPENROUTER_BASE_URL")
19 if baseURL == "" {
20 baseURL = "https://openrouter.ai/api/v1"
21 }
22
23 // 创建依赖
24 toolRegistry := tools.NewRegistry()
25 builtin.RegisterAll(toolRegistry)
26
27 jsonStore, err := store.NewJSONStore(".aster")
28 if err != nil {
29 return nil, err
30 }
31
32 templateRegistry := agent.NewTemplateRegistry()
33 templateRegistry.Register(&types.AgentTemplateDefinition{
34 ID: "test-assistant",
35 SystemPrompt: "你是一个文件操作助手。当用户要求创建、写入或读取文件时,你必须使用 Write 或 Read 工具实际执行操作。当用户要求执行命令时,你必须使用 Bash 工具。不要只用文字回复,必须调用工具完成任务。",
36 Tools: []any{"Read", "Write", "Bash"},
37 })
38
39 deps := &agent.Dependencies{
40 Store: jsonStore,
41 SandboxFactory: sandbox.NewFactory(),
42 ToolRegistry: toolRegistry,
43 ProviderFactory: &provider.OpenRouterFactory{},
44 TemplateRegistry: templateRegistry,
45 }
46
47 config := &types.AgentConfig{
48 TemplateID: "test-assistant",
49 ModelConfig: &types.ModelConfig{
50 Provider: "openrouter",
51 Model: "anthropic/claude-haiku-4.5",
52 APIKey: apiKey,
53 BaseURL: baseURL,
54 ExecutionMode: types.ExecutionModeNonStreaming,
55 },
56 Sandbox: &types.SandboxConfig{
57 Kind: types.SandboxKindLocal,
58 WorkDir: "./workspace",
59 },
60 }
61
62 return agent.Create(context.TODO(), config, deps)
63}

Callers 1

SetupTestMethod · 0.85

Calls 7

RegisterMethod · 0.95
NewRegistryFunction · 0.92
RegisterAllFunction · 0.92
NewJSONStoreFunction · 0.92
NewTemplateRegistryFunction · 0.92
NewFactoryFunction · 0.92
CreateFunction · 0.92

Tested by

no test coverage detected