Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions cmd/picoclaw/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,10 @@ func agentCmd() {
// Print agent startup info (only for interactive mode)
startupInfo := agentLoop.GetStartupInfo()
logger.InfoCF("agent", "Agent initialized",
map[string]interface{}{
"tools_count": startupInfo["tools"].(map[string]interface{})["count"],
"skills_total": startupInfo["skills"].(map[string]interface{})["total"],
"skills_available": startupInfo["skills"].(map[string]interface{})["available"],
map[string]any{
"tools_count": startupInfo["tools"].(map[string]any)["count"],
"skills_total": startupInfo["skills"].(map[string]any)["total"],
"skills_available": startupInfo["skills"].(map[string]any)["available"],
})

if message != "" {
Expand Down Expand Up @@ -544,16 +544,16 @@ func gatewayCmd() {
// Print agent startup info
fmt.Println("\n📦 Agent Status:")
startupInfo := agentLoop.GetStartupInfo()
toolsInfo := startupInfo["tools"].(map[string]interface{})
skillsInfo := startupInfo["skills"].(map[string]interface{})
toolsInfo := startupInfo["tools"].(map[string]any)
skillsInfo := startupInfo["skills"].(map[string]any)
fmt.Printf(" • Tools: %d loaded\n", toolsInfo["count"])
fmt.Printf(" • Skills: %d/%d available\n",
skillsInfo["available"],
skillsInfo["total"])

// Log to file as well
logger.InfoCF("agent", "Agent initialized",
map[string]interface{}{
map[string]any{
"tools_count": toolsInfo["count"],
"skills_total": skillsInfo["total"],
"skills_available": skillsInfo["available"],
Expand Down
12 changes: 6 additions & 6 deletions pkg/agent/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str

// Log system prompt summary for debugging (debug mode only)
logger.DebugCF("agent", "System prompt built",
map[string]interface{}{
map[string]any{
"total_chars": len(systemPrompt),
"total_lines": strings.Count(systemPrompt, "\n") + 1,
"section_count": strings.Count(systemPrompt, "\n\n---\n\n") + 1,
Expand All @@ -181,7 +181,7 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str
preview = preview[:500] + "... (truncated)"
}
logger.DebugCF("agent", "System prompt preview",
map[string]interface{}{
map[string]any{
"preview": preview,
})

Expand All @@ -194,7 +194,7 @@ func (cb *ContextBuilder) BuildMessages(history []providers.Message, summary str
//Diegox-17
for len(history) > 0 && (history[0].Role == "tool") {
logger.DebugCF("agent", "Removing orphaned tool message from history to prevent LLM error",
map[string]interface{}{"role": history[0].Role})
map[string]any{"role": history[0].Role})
history = history[1:]
}
//Diegox-17
Expand Down Expand Up @@ -224,7 +224,7 @@ func (cb *ContextBuilder) AddToolResult(messages []providers.Message, toolCallID
return messages
}

func (cb *ContextBuilder) AddAssistantMessage(messages []providers.Message, content string, toolCalls []map[string]interface{}) []providers.Message {
func (cb *ContextBuilder) AddAssistantMessage(messages []providers.Message, content string, toolCalls []map[string]any) []providers.Message {
msg := providers.Message{
Role: "assistant",
Content: content,
Expand Down Expand Up @@ -254,13 +254,13 @@ func (cb *ContextBuilder) loadSkills() string {
}

// GetSkillsInfo returns information about loaded skills.
func (cb *ContextBuilder) GetSkillsInfo() map[string]interface{} {
func (cb *ContextBuilder) GetSkillsInfo() map[string]any {
allSkills := cb.skillsLoader.ListSkills()
skillNames := make([]string, 0, len(allSkills))
for _, s := range allSkills {
skillNames = append(skillNames, s.Name)
}
return map[string]interface{}{
return map[string]any{
"total": len(allSkills),
"available": len(allSkills),
"names": skillNames,
Expand Down
42 changes: 21 additions & 21 deletions pkg/agent/loop.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func (al *AgentLoop) processMessage(ctx context.Context, msg bus.InboundMessage)
logContent = utils.Truncate(msg.Content, 80)
}
logger.InfoCF("agent", fmt.Sprintf("Processing message from %s:%s: %s", msg.Channel, msg.SenderID, logContent),
map[string]interface{}{
map[string]any{
"channel": msg.Channel,
"chat_id": msg.ChatID,
"sender_id": msg.SenderID,
Expand Down Expand Up @@ -282,7 +282,7 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
}

logger.InfoCF("agent", "Processing system message",
map[string]interface{}{
map[string]any{
"sender_id": msg.SenderID,
"chat_id": msg.ChatID,
})
Expand All @@ -306,7 +306,7 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
// Skip internal channels - only log, don't send to user
if constants.IsInternalChannel(originChannel) {
logger.InfoCF("agent", "Subagent completed (internal channel)",
map[string]interface{}{
map[string]any{
"sender_id": msg.SenderID,
"content_len": len(content),
"channel": originChannel,
Expand All @@ -317,7 +317,7 @@ func (al *AgentLoop) processSystemMessage(ctx context.Context, msg bus.InboundMe
// Agent acts as dispatcher only - subagent handles user interaction via message tool
// Don't forward result here, subagent should use message tool to communicate with user
logger.InfoCF("agent", "Subagent completed",
map[string]interface{}{
map[string]any{
"sender_id": msg.SenderID,
"channel": originChannel,
"content_len": len(content),
Expand All @@ -336,7 +336,7 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, opts processOptions) (str
if !constants.IsInternalChannel(opts.Channel) {
channelKey := fmt.Sprintf("%s:%s", opts.Channel, opts.ChatID)
if err := al.RecordLastChannel(channelKey); err != nil {
logger.WarnCF("agent", "Failed to record last channel: %v", map[string]interface{}{"error": err.Error()})
logger.WarnCF("agent", "Failed to record last channel: %v", map[string]any{"error": err.Error()})
}
}
}
Expand Down Expand Up @@ -398,7 +398,7 @@ func (al *AgentLoop) runAgentLoop(ctx context.Context, opts processOptions) (str
// 9. Log response
responsePreview := utils.Truncate(finalContent, 120)
logger.InfoCF("agent", fmt.Sprintf("Response: %s", responsePreview),
map[string]interface{}{
map[string]any{
"session_key": opts.SessionKey,
"iterations": iteration,
"final_length": len(finalContent),
Expand All @@ -417,7 +417,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
iteration++

logger.DebugCF("agent", "LLM iteration",
map[string]interface{}{
map[string]any{
"iteration": iteration,
"max": al.maxIterations,
})
Expand All @@ -427,7 +427,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M

// Log LLM request details
logger.DebugCF("agent", "LLM request",
map[string]interface{}{
map[string]any{
"iteration": iteration,
"model": al.model,
"messages_count": len(messages),
Expand All @@ -439,21 +439,21 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M

// Log full messages (detailed)
logger.DebugCF("agent", "Full LLM request",
map[string]interface{}{
map[string]any{
"iteration": iteration,
"messages_json": formatMessagesForLog(messages),
"tools_json": formatToolsForLog(providerToolDefs),
})

// Call LLM
response, err := al.provider.Chat(ctx, messages, providerToolDefs, al.model, map[string]interface{}{
response, err := al.provider.Chat(ctx, messages, providerToolDefs, al.model, map[string]any{
"max_tokens": 8192,
"temperature": 0.7,
})

if err != nil {
logger.ErrorCF("agent", "LLM call failed",
map[string]interface{}{
map[string]any{
"iteration": iteration,
"error": err.Error(),
})
Expand All @@ -464,7 +464,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
if len(response.ToolCalls) == 0 {
finalContent = response.Content
logger.InfoCF("agent", "LLM response without tool calls (direct answer)",
map[string]interface{}{
map[string]any{
"iteration": iteration,
"content_chars": len(finalContent),
})
Expand All @@ -477,7 +477,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
toolNames = append(toolNames, tc.Name)
}
logger.InfoCF("agent", "LLM requested tool calls",
map[string]interface{}{
map[string]any{
"tools": toolNames,
"count": len(response.ToolCalls),
"iteration": iteration,
Expand Down Expand Up @@ -510,7 +510,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
argsJSON, _ := json.Marshal(tc.Arguments)
argsPreview := utils.Truncate(string(argsJSON), 200)
logger.InfoCF("agent", fmt.Sprintf("Tool call: %s(%s)", tc.Name, argsPreview),
map[string]interface{}{
map[string]any{
"tool": tc.Name,
"iteration": iteration,
})
Expand All @@ -524,7 +524,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
// The agent will handle user notification via processSystemMessage
if !result.Silent && result.ForUser != "" {
logger.InfoCF("agent", "Async tool completed, agent will handle notification",
map[string]interface{}{
map[string]any{
"tool": tc.Name,
"content_len": len(result.ForUser),
})
Expand All @@ -541,7 +541,7 @@ func (al *AgentLoop) runLLMIteration(ctx context.Context, messages []providers.M
Content: toolResult.ForUser,
})
logger.DebugCF("agent", "Sent tool result to user",
map[string]interface{}{
map[string]any{
"tool": tc.Name,
"content_len": len(toolResult.ForUser),
})
Expand Down Expand Up @@ -605,12 +605,12 @@ func (al *AgentLoop) maybeSummarize(sessionKey string) {
}

// GetStartupInfo returns information about loaded tools and skills for logging.
func (al *AgentLoop) GetStartupInfo() map[string]interface{} {
info := make(map[string]interface{})
func (al *AgentLoop) GetStartupInfo() map[string]any {
info := make(map[string]any)

// Tools info
tools := al.tools.List()
info["tools"] = map[string]interface{}{
info["tools"] = map[string]any{
"count": len(tools),
"names": tools,
}
Expand Down Expand Up @@ -723,7 +723,7 @@ func (al *AgentLoop) summarizeSession(sessionKey string) {

// Merge them
mergePrompt := fmt.Sprintf("Merge these two conversation summaries into one cohesive summary:\n\n1: %s\n\n2: %s", s1, s2)
resp, err := al.provider.Chat(ctx, []providers.Message{{Role: "user", Content: mergePrompt}}, nil, al.model, map[string]interface{}{
resp, err := al.provider.Chat(ctx, []providers.Message{{Role: "user", Content: mergePrompt}}, nil, al.model, map[string]any{
"max_tokens": 1024,
"temperature": 0.3,
})
Expand Down Expand Up @@ -758,7 +758,7 @@ func (al *AgentLoop) summarizeBatch(ctx context.Context, batch []providers.Messa
prompt += fmt.Sprintf("%s: %s\n", m.Role, m.Content)
}

response, err := al.provider.Chat(ctx, []providers.Message{{Role: "user", Content: prompt}}, nil, al.model, map[string]interface{}{
response, err := al.provider.Chat(ctx, []providers.Message{{Role: "user", Content: prompt}}, nil, al.model, map[string]any{
"max_tokens": 1024,
"temperature": 0.3,
})
Expand Down
26 changes: 13 additions & 13 deletions pkg/agent/loop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// mockProvider is a simple mock LLM provider for testing
type mockProvider struct{}

func (m *mockProvider) Chat(ctx context.Context, messages []providers.Message, tools []providers.ToolDefinition, model string, opts map[string]interface{}) (*providers.LLMResponse, error) {
func (m *mockProvider) Chat(ctx context.Context, messages []providers.Message, tools []providers.ToolDefinition, model string, opts map[string]any) (*providers.LLMResponse, error) {
return &providers.LLMResponse{
Content: "Mock response",
ToolCalls: []providers.ToolCall{},
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestToolRegistry_ToolRegistration(t *testing.T) {
// Verify tool is registered by checking it doesn't panic on GetStartupInfo
// (actual tool retrieval is tested in tools package tests)
info := al.GetStartupInfo()
toolsInfo := info["tools"].(map[string]interface{})
toolsInfo := info["tools"].(map[string]any)
toolsList := toolsInfo["names"].([]string)

// Check that our custom tool name is in the list
Expand Down Expand Up @@ -259,7 +259,7 @@ func TestToolRegistry_GetDefinitions(t *testing.T) {
al.RegisterTool(testTool)

info := al.GetStartupInfo()
toolsInfo := info["tools"].(map[string]interface{})
toolsInfo := info["tools"].(map[string]any)
toolsList := toolsInfo["names"].([]string)

// Check that our custom tool name is in the list
Expand Down Expand Up @@ -306,7 +306,7 @@ func TestAgentLoop_GetStartupInfo(t *testing.T) {
t.Fatal("Expected 'tools' key in startup info")
}

toolsMap, ok := toolsInfo.(map[string]interface{})
toolsMap, ok := toolsInfo.(map[string]any)
if !ok {
t.Fatal("Expected 'tools' to be a map")
}
Expand Down Expand Up @@ -362,7 +362,7 @@ type simpleMockProvider struct {
response string
}

func (m *simpleMockProvider) Chat(ctx context.Context, messages []providers.Message, tools []providers.ToolDefinition, model string, opts map[string]interface{}) (*providers.LLMResponse, error) {
func (m *simpleMockProvider) Chat(ctx context.Context, messages []providers.Message, tools []providers.ToolDefinition, model string, opts map[string]any) (*providers.LLMResponse, error) {
return &providers.LLMResponse{
Content: m.response,
ToolCalls: []providers.ToolCall{},
Expand All @@ -384,14 +384,14 @@ func (m *mockCustomTool) Description() string {
return "Mock custom tool for testing"
}

func (m *mockCustomTool) Parameters() map[string]interface{} {
return map[string]interface{}{
func (m *mockCustomTool) Parameters() map[string]any {
return map[string]any{
"type": "object",
"properties": map[string]interface{}{},
"properties": map[string]any{},
}
}

func (m *mockCustomTool) Execute(ctx context.Context, args map[string]interface{}) *tools.ToolResult {
func (m *mockCustomTool) Execute(ctx context.Context, args map[string]any) *tools.ToolResult {
return tools.SilentResult("Custom tool executed")
}

Expand All @@ -409,14 +409,14 @@ func (m *mockContextualTool) Description() string {
return "Mock contextual tool"
}

func (m *mockContextualTool) Parameters() map[string]interface{} {
return map[string]interface{}{
func (m *mockContextualTool) Parameters() map[string]any {
return map[string]any{
"type": "object",
"properties": map[string]interface{}{},
"properties": map[string]any{},
}
}

func (m *mockContextualTool) Execute(ctx context.Context, args map[string]interface{}) *tools.ToolResult {
func (m *mockContextualTool) Execute(ctx context.Context, args map[string]any) *tools.ToolResult {
return tools.SilentResult("Contextual tool executed")
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/auth/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,12 @@ func extractAccountID(accessToken string) string {
return ""
}

var claims map[string]interface{}
var claims map[string]any
if err := json.Unmarshal(decoded, &claims); err != nil {
return ""
}

if authClaim, ok := claims["https://api.openai.com/auth"].(map[string]interface{}); ok {
if authClaim, ok := claims["https://api.openai.com/auth"].(map[string]any); ok {
if accountID, ok := authClaim["chatgpt_account_id"].(string); ok {
return accountID
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/auth/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestBuildAuthorizeURL(t *testing.T) {
}

func TestParseTokenResponse(t *testing.T) {
resp := map[string]interface{}{
resp := map[string]any{
"access_token": "test-access-token",
"refresh_token": "test-refresh-token",
"expires_in": 3600,
Expand Down Expand Up @@ -94,7 +94,7 @@ func TestParseTokenResponseNoAccessToken(t *testing.T) {

func TestParseTokenResponseAccountIDFromIDToken(t *testing.T) {
idToken := makeJWTWithAccountID("acc-from-id")
resp := map[string]interface{}{
resp := map[string]any{
"access_token": "not-a-jwt",
"refresh_token": "test-refresh-token",
"expires_in": 3600,
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestExchangeCodeForTokens(t *testing.T) {
return
}

resp := map[string]interface{}{
resp := map[string]any{
"access_token": "mock-access-token",
"refresh_token": "mock-refresh-token",
"expires_in": 3600,
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestRefreshAccessToken(t *testing.T) {
return
}

resp := map[string]interface{}{
resp := map[string]any{
"access_token": "refreshed-access-token",
"refresh_token": "refreshed-refresh-token",
"expires_in": 3600,
Expand Down
Loading