added proper logging to the mcp agent mode
This commit is contained in:
@@ -25,6 +25,8 @@ func main() {
|
|||||||
log.SetOutput(os.Stderr)
|
log.SetOutput(os.Stderr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sidekick.GlobalLogger = log.Printf
|
||||||
|
|
||||||
tmpl, _ := sidekick.LoadPrompts("prompts.toml")
|
tmpl, _ := sidekick.LoadPrompts("prompts.toml")
|
||||||
|
|
||||||
sidekick.InitMCPServers(cfg.MCPServers)
|
sidekick.InitMCPServers(cfg.MCPServers)
|
||||||
@@ -38,7 +40,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mCfg := cfg.Models[aCfg.ModelID]
|
mCfg := cfg.Models[aCfg.ModelID]
|
||||||
pool[id] = sidekick.NewSidekick(aCfg, mCfg, nil)
|
agent := sidekick.NewSidekick(aCfg, mCfg, nil)
|
||||||
|
if aCfg.LogIntermediate {
|
||||||
|
agentID := id
|
||||||
|
agent.IntermediateHandler = func(msg string) {
|
||||||
|
log.Printf("[Agent %s] %s\n", agentID, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pool[id] = agent
|
||||||
}
|
}
|
||||||
|
|
||||||
entryAgent := "coordinator"
|
entryAgent := "coordinator"
|
||||||
@@ -79,9 +88,12 @@ func main() {
|
|||||||
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
func(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
|
||||||
msg, err := request.RequireString("message")
|
msg, err := request.RequireString("message")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Received invalid 'query' request: missing message argument")
|
||||||
return nil, fmt.Errorf("message argument is required and must be a string: %v", err)
|
return nil, fmt.Errorf("message argument is required and must be a string: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Received 'query' request (message length: %d)", len(msg))
|
||||||
|
|
||||||
var inCtx []sidekick.Message
|
var inCtx []sidekick.Message
|
||||||
|
|
||||||
args := request.GetArguments()
|
args := request.GetArguments()
|
||||||
@@ -113,9 +125,12 @@ func main() {
|
|||||||
|
|
||||||
responseStr, err := agent.Run(ctx, inCtx, pool)
|
responseStr, err := agent.Run(ctx, inCtx, pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Printf("Agent run failed: %v", err)
|
||||||
return nil, fmt.Errorf("agent run failed: %w", err)
|
return nil, fmt.Errorf("agent run failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Printf("Sending response (length: %d)", len(responseStr))
|
||||||
|
|
||||||
// Add the final response to the history structure to be returned
|
// Add the final response to the history structure to be returned
|
||||||
outHistory := append(inCtx, sidekick.Message{
|
outHistory := append(inCtx, sidekick.Message{
|
||||||
Role: sidekick.MessageRole("assistant"),
|
Role: sidekick.MessageRole("assistant"),
|
||||||
|
|||||||
+4
-4
@@ -37,7 +37,7 @@ port = 8080
|
|||||||
model_id = "default"
|
model_id = "default"
|
||||||
enable_shell_exec = true
|
enable_shell_exec = true
|
||||||
streaming = false
|
streaming = false
|
||||||
log_intermediate = false
|
log_intermediate = true
|
||||||
system_prompt = "You are the Lead Architect. You oversee the software development lifecycle, plan features, and delegate implementation to specialized subagents."
|
system_prompt = "You are the Lead Architect. You oversee the software development lifecycle, plan features, and delegate implementation to specialized subagents."
|
||||||
description = "Lead Architect and project coordinator"
|
description = "Lead Architect and project coordinator"
|
||||||
max_iterations = 15
|
max_iterations = 15
|
||||||
@@ -54,7 +54,7 @@ port = 8080
|
|||||||
model_id = "default"
|
model_id = "default"
|
||||||
enable_shell_exec = true
|
enable_shell_exec = true
|
||||||
streaming = false
|
streaming = false
|
||||||
log_intermediate = false
|
log_intermediate = true
|
||||||
system_prompt = "You are a Senior Software Engineer specializing in implementation. Your goal is to write clean, efficient, and well-documented code based on the architect's instructions."
|
system_prompt = "You are a Senior Software Engineer specializing in implementation. Your goal is to write clean, efficient, and well-documented code based on the architect's instructions."
|
||||||
description = "Senior Developer focused on implementation and refactoring"
|
description = "Senior Developer focused on implementation and refactoring"
|
||||||
max_iterations = 10
|
max_iterations = 10
|
||||||
@@ -69,7 +69,7 @@ port = 8080
|
|||||||
role = "SPECIALIST"
|
role = "SPECIALIST"
|
||||||
model_id = "fast"
|
model_id = "fast"
|
||||||
streaming = false
|
streaming = false
|
||||||
log_intermediate = false
|
log_intermediate = true
|
||||||
system_prompt = "You are a Quality Assurance Specialist and Code Reviewer. Your role is to analyze code for potential bugs, security vulnerabilities, and style violations."
|
system_prompt = "You are a Quality Assurance Specialist and Code Reviewer. Your role is to analyze code for potential bugs, security vulnerabilities, and style violations."
|
||||||
description = "Code Reviewer and Quality Assurance specialist"
|
description = "Code Reviewer and Quality Assurance specialist"
|
||||||
max_iterations = 8
|
max_iterations = 8
|
||||||
@@ -85,7 +85,7 @@ port = 8080
|
|||||||
model_id = "fast"
|
model_id = "fast"
|
||||||
enable_shell_exec = true
|
enable_shell_exec = true
|
||||||
streaming = false
|
streaming = false
|
||||||
log_intermediate = false
|
log_intermediate = true
|
||||||
system_prompt = "You are a Test Engineer. Your primary responsibility is to write and execute tests to ensure software reliability and correctness."
|
system_prompt = "You are a Test Engineer. Your primary responsibility is to write and execute tests to ensure software reliability and correctness."
|
||||||
description = "Test Engineer focused on automated testing and verification"
|
description = "Test Engineer focused on automated testing and verification"
|
||||||
max_iterations = 10
|
max_iterations = 10
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ func (w *mcpGoClientWrapper) Close() error {
|
|||||||
// Global server configurations
|
// Global server configurations
|
||||||
var mcpServers map[string]MCPServerConfig
|
var mcpServers map[string]MCPServerConfig
|
||||||
|
|
||||||
|
// GlobalLogger is an optional logger for MCP connections
|
||||||
|
var GlobalLogger func(format string, v ...interface{})
|
||||||
|
|
||||||
// InitMCPServers sets up the global registry for MCP factories
|
// InitMCPServers sets up the global registry for MCP factories
|
||||||
func InitMCPServers(servers map[string]MCPServerConfig) {
|
func InitMCPServers(servers map[string]MCPServerConfig) {
|
||||||
mcpServers = servers
|
mcpServers = servers
|
||||||
@@ -66,6 +69,10 @@ var defaultMCPFactory MCPClientFactory = func(toolset string) (MCPClientInterfac
|
|||||||
return nil, fmt.Errorf("unknown MCP server: %s", toolset)
|
return nil, fmt.Errorf("unknown MCP server: %s", toolset)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if GlobalLogger != nil {
|
||||||
|
GlobalLogger("Initializing MCP connection to %s via %s", toolset, cfg.Transport)
|
||||||
|
}
|
||||||
|
|
||||||
var c *client.Client
|
var c *client.Client
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user