enhanced logs
This commit is contained in:
parent
9df6451048
commit
2e7b467095
3 changed files with 29 additions and 1 deletions
|
|
@ -331,6 +331,10 @@ func (al *AgentLoop) Run(ctx context.Context) error {
|
||||||
maxSearchResults = 5 // Default value
|
maxSearchResults = 5 // Default value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.InfoCF("agent", "Initializing tool discovery", map[string]any{
|
||||||
|
"bm25": useBM25, "regex": useRegex, "ttl": ttl, "max_results": maxSearchResults,
|
||||||
|
})
|
||||||
|
|
||||||
for _, agentID := range agentIDs {
|
for _, agentID := range agentIDs {
|
||||||
agent, ok := al.registry.GetAgent(agentID)
|
agent, ok := al.registry.GetAgent(agentID)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -1306,6 +1310,9 @@ func (al *AgentLoop) runLLMIteration(
|
||||||
// If per-agent concurrency is added, TTL consistency between
|
// If per-agent concurrency is added, TTL consistency between
|
||||||
// ToProviderDefs and Get must be re-evaluated.
|
// ToProviderDefs and Get must be re-evaluated.
|
||||||
agent.Tools.TickTTL()
|
agent.Tools.TickTTL()
|
||||||
|
logger.DebugCF("agent", "TTL tick after tool execution", map[string]any{
|
||||||
|
"agent_id": agent.ID, "iteration": iteration,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return finalContent, iteration, nil
|
return finalContent, iteration, nil
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ func (r *ToolRegistry) Register(tool Tool) {
|
||||||
TTL: 0, // Core tools do not use TTL
|
TTL: 0, // Core tools do not use TTL
|
||||||
}
|
}
|
||||||
r.version.Add(1)
|
r.version.Add(1)
|
||||||
|
logger.DebugCF("tools", "Registered core tool", map[string]any{"name": name})
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterHidden saves hidden tools (visible only via TTL)
|
// RegisterHidden saves hidden tools (visible only via TTL)
|
||||||
|
|
@ -61,6 +62,7 @@ func (r *ToolRegistry) RegisterHidden(tool Tool) {
|
||||||
TTL: 0,
|
TTL: 0,
|
||||||
}
|
}
|
||||||
r.version.Add(1)
|
r.version.Add(1)
|
||||||
|
logger.DebugCF("tools", "Registered hidden tool", map[string]any{"name": name})
|
||||||
}
|
}
|
||||||
|
|
||||||
// PromoteTools atomically sets the TTL for multiple non-core tools.
|
// PromoteTools atomically sets the TTL for multiple non-core tools.
|
||||||
|
|
@ -68,13 +70,20 @@ func (r *ToolRegistry) RegisterHidden(tool Tool) {
|
||||||
func (r *ToolRegistry) PromoteTools(names []string, ttl int) {
|
func (r *ToolRegistry) PromoteTools(names []string, ttl int) {
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
promoted := 0
|
||||||
for _, name := range names {
|
for _, name := range names {
|
||||||
if entry, exists := r.tools[name]; exists {
|
if entry, exists := r.tools[name]; exists {
|
||||||
if !entry.IsCore {
|
if !entry.IsCore {
|
||||||
entry.TTL = ttl
|
entry.TTL = ttl
|
||||||
|
promoted++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger.DebugCF(
|
||||||
|
"tools",
|
||||||
|
"PromoteTools completed",
|
||||||
|
map[string]any{"requested": len(names), "promoted": promoted, "ttl": ttl},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TickTTL decreases TTL only for non-core tools
|
// TickTTL decreases TTL only for non-core tools
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
|
"github.com/sipeed/picoclaw/pkg/logger"
|
||||||
"github.com/sipeed/picoclaw/pkg/utils"
|
"github.com/sipeed/picoclaw/pkg/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -55,15 +56,19 @@ func (t *RegexSearchTool) Execute(ctx context.Context, args map[string]any) *Too
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(pattern) > MaxRegexPatternLength {
|
if len(pattern) > MaxRegexPatternLength {
|
||||||
// Limit on length to avoid catastrophic patterns
|
logger.WarnCF("discovery", "Regex pattern rejected (too long)", map[string]any{"len": len(pattern)})
|
||||||
return ErrorResult(fmt.Sprintf("Pattern too long: max %d characters allowed", MaxRegexPatternLength))
|
return ErrorResult(fmt.Sprintf("Pattern too long: max %d characters allowed", MaxRegexPatternLength))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.DebugCF("discovery", "Regex search", map[string]any{"pattern": pattern})
|
||||||
|
|
||||||
res, err := t.registry.SearchRegex(pattern, t.maxSearchResults)
|
res, err := t.registry.SearchRegex(pattern, t.maxSearchResults)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
logger.WarnCF("discovery", "Invalid regex pattern", map[string]any{"pattern": pattern, "error": err.Error()})
|
||||||
return ErrorResult(fmt.Sprintf("Invalid regex pattern syntax: %v. Please fix your regex and try again.", err))
|
return ErrorResult(fmt.Sprintf("Invalid regex pattern syntax: %v. Please fix your regex and try again.", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.InfoCF("discovery", "Regex search completed", map[string]any{"pattern": pattern, "results": len(res)})
|
||||||
return formatDiscoveryResponse(t.registry, res, t.ttl)
|
return formatDiscoveryResponse(t.registry, res, t.ttl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,13 +116,17 @@ func (t *BM25SearchTool) Execute(ctx context.Context, args map[string]any) *Tool
|
||||||
return ErrorResult("Missing or invalid 'query' argument. Must be a non-empty string.")
|
return ErrorResult("Missing or invalid 'query' argument. Must be a non-empty string.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.DebugCF("discovery", "BM25 search", map[string]any{"query": query})
|
||||||
|
|
||||||
cached := t.getOrBuildEngine()
|
cached := t.getOrBuildEngine()
|
||||||
if cached == nil {
|
if cached == nil {
|
||||||
|
logger.DebugCF("discovery", "BM25 search: no hidden tools available", nil)
|
||||||
return SilentResult("No tools found matching the query.")
|
return SilentResult("No tools found matching the query.")
|
||||||
}
|
}
|
||||||
|
|
||||||
ranked := cached.engine.Search(query, t.maxSearchResults)
|
ranked := cached.engine.Search(query, t.maxSearchResults)
|
||||||
if len(ranked) == 0 {
|
if len(ranked) == 0 {
|
||||||
|
logger.DebugCF("discovery", "BM25 search: no matches", map[string]any{"query": query})
|
||||||
return SilentResult("No tools found matching the query.")
|
return SilentResult("No tools found matching the query.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -129,6 +138,7 @@ func (t *BM25SearchTool) Execute(ctx context.Context, args map[string]any) *Tool
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.InfoCF("discovery", "BM25 search completed", map[string]any{"query": query, "results": len(results)})
|
||||||
return formatDiscoveryResponse(t.registry, results, t.ttl)
|
return formatDiscoveryResponse(t.registry, results, t.ttl)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,6 +198,7 @@ func formatDiscoveryResponse(registry *ToolRegistry, results []ToolSearchResult,
|
||||||
names[i] = r.Name
|
names[i] = r.Name
|
||||||
}
|
}
|
||||||
registry.PromoteTools(names, ttl)
|
registry.PromoteTools(names, ttl)
|
||||||
|
logger.InfoCF("discovery", "Promoted tools", map[string]any{"tools": names, "ttl": ttl})
|
||||||
|
|
||||||
b, err := json.Marshal(results)
|
b, err := json.Marshal(results)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -263,6 +274,7 @@ func (t *BM25SearchTool) getOrBuildEngine() *bm25CachedEngine {
|
||||||
cached := &bm25CachedEngine{engine: buildBM25Engine(docs)}
|
cached := &bm25CachedEngine{engine: buildBM25Engine(docs)}
|
||||||
t.cachedEngine = cached
|
t.cachedEngine = cached
|
||||||
t.cacheVersion = snap.Version
|
t.cacheVersion = snap.Version
|
||||||
|
logger.DebugCF("discovery", "BM25 engine rebuilt", map[string]any{"docs": len(docs), "version": snap.Version})
|
||||||
return cached
|
return cached
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue