Skip to content

Commit eb1e2f3

Browse files
committed
feat(agent): add provider inference, memory persistence and DeepSeek support
- Infer provider from tool name when not explicitly provided (e.g., "expert.researcher" → "expert") - Append tools to existing list instead of overwriting in UTC provider registration - Add memory flush to PostgreSQL in example CLI for session persistence - Add DeepSeek LLM provider support
1 parent 45ea1b4 commit eb1e2f3

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

.gitignore

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Environment variables (contains secrets)
2+
.env
3+
.env.local
4+
.env.*.local
5+
6+
# Build artifacts
7+
/bin/
8+
/dist/
9+
/validator
10+
11+
# IDE
12+
.idea/
13+
.vscode/
14+
*.swp
15+
*.swo
16+
17+
# OS
18+
.DS_Store
19+
Thumbs.db
20+
21+
# Logs
22+
*.log
23+
logs/
24+
25+
# Cache
26+
.agent_cache.json
27+
*.cache
28+
29+
# Test coverage
30+
coverage.out
31+
coverage.html
32+
33+
# Demo examples (experimental/test code)
34+
cmd/example/5ways_demo/
35+
cmd/example/hybrid_memory_test/
36+
cmd/example/shared_session_test/
37+
cmd/example/multi_agent_memory/
38+
39+
# Orchestration and validator tools
40+
cmd/orchestrate/
41+
cmd/validator/
42+
43+
# Documentation (external guides)
44+
docs/
45+
46+
# Multi-agent memory (legacy test at root level - binary or directory)
47+
/multi_agent_memory
48+
/multi_agent_memory/
49+
50+
# DeepSeek model helper (external - not part of core go-agent)
51+
# Note: src/models/deepseek.go should be committed separately if needed
52+
src/models/deepseek.go
53+
54+
# Ignore all untracked files except core modifications
55+
# Core modifications to keep:
56+
# - agent_tool.go (UTCP tool registration fix)
57+
# - cmd/example/main.go (memory flush fix)
58+
# - src/models/helper.go (DeepSeek provider support)

agent_tool.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,26 @@ func (t *agentCLITransport) DeregisterToolProvider(ctx context.Context, prov bas
103103
}
104104

105105
func (t *agentCLITransport) CallTool(ctx context.Context, toolName string, args map[string]any, prov base.Provider, _ *string) (any, error) {
106+
// 如果 prov 为空,尝试从 toolName 推断 provider(如 "expert.researcher" → "expert")
107+
if prov == nil {
108+
if parts := strings.Split(toolName, "."); len(parts) > 1 {
109+
providerName := parts[0]
110+
if list, ok := t.tools[providerName]; ok {
111+
for _, tool := range list {
112+
if tool.Name == toolName {
113+
if tool.Handler == nil {
114+
return nil, fmt.Errorf("tool %s has no handler", toolName)
115+
}
116+
return tool.Handler(ctx, args)
117+
}
118+
}
119+
return nil, fmt.Errorf("tool %s not found in provider %s", toolName, providerName)
120+
}
121+
}
122+
return nil, fmt.Errorf("tool %s not found (no provider specified)", toolName)
123+
}
124+
125+
// 原有逻辑:使用提供的 Provider
106126
if p, ok := prov.(*cli.CliProvider); ok {
107127
if list, ok := t.tools[p.Name]; ok {
108128
for _, tool := range list {
@@ -289,7 +309,8 @@ func (a *Agent) RegisterAsUTCPProvider(ctx context.Context, client utcp.UtcpClie
289309
if shim.tools == nil {
290310
shim.tools = make(map[string][]tools.Tool)
291311
}
292-
shim.tools[tp.Name] = []tools.Tool{tool}
312+
// 追加工具到现有列表,而不是覆盖
313+
shim.tools[tp.Name] = append(shim.tools[tp.Name], tool)
293314

294315
_, err := client.RegisterToolProvider(ctx, tp)
295316
return err

cmd/example/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ func main() {
128128
fail(err)
129129
}
130130

131+
// Flush memories to PostgreSQL (persist short-term memory to long-term storage)
132+
if err := ag.Flush(ctx, *flagSession); err != nil {
133+
fmt.Fprintf(os.Stderr, "warning: failed to flush memories: %v\n", err)
134+
}
135+
131136
// 6) Print
132137
if *flagJSON {
133138
enc := json.NewEncoder(os.Stdout)

src/models/helper.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ func NewLLMProvider(ctx context.Context, provider string, model string, promptPr
5454
switch provider {
5555
case "openai":
5656
agent = NewOpenAILLM(model, promptPrefix)
57+
case "deepseek":
58+
agent = NewDeepSeekLLM(model, promptPrefix)
5759
case "gemini", "google":
5860
agent, err = NewGeminiLLM(ctx, model, promptPrefix)
5961
case "ollama":

0 commit comments

Comments
 (0)