- Added `MCPServers` and `SystemPrompt` to `AgentConfig`. - Configured default out-of-the-box personas (coding, google, communications, financial) with specific MCP assignments. - Added CLI commands `picoclaw agent create`, `assign-mcp`, and `remove-mcp`. - Updated agent MCP tool registration to filter tools per persona based on `MCPServers`. Agents with an empty list will not have any MCP tools registered. Co-authored-by: hobbyistlabs-coder <267281733+hobbyistlabs-coder@users.noreply.github.com>
131 lines
5.5 KiB
Go
131 lines
5.5 KiB
Go
package config
|
|
|
|
import "encoding/json"
|
|
|
|
type AgentsConfig struct {
|
|
Defaults AgentDefaults `json:"defaults"`
|
|
List []AgentConfig `json:"list,omitempty"`
|
|
}
|
|
|
|
// AgentModelConfig supports both string and structured model config.
|
|
// String format: "gpt-4" (just primary, no fallbacks)
|
|
// Object format: {"primary": "gpt-4", "fallbacks": ["claude-haiku"]}
|
|
type AgentModelConfig struct {
|
|
Primary string `json:"primary,omitempty"`
|
|
Fallbacks []string `json:"fallbacks,omitempty"`
|
|
}
|
|
|
|
func (m *AgentModelConfig) UnmarshalJSON(data []byte) error {
|
|
var s string
|
|
if err := json.Unmarshal(data, &s); err == nil {
|
|
m.Primary = s
|
|
m.Fallbacks = nil
|
|
return nil
|
|
}
|
|
type raw struct {
|
|
Primary string `json:"primary"`
|
|
Fallbacks []string `json:"fallbacks"`
|
|
}
|
|
var r raw
|
|
if err := json.Unmarshal(data, &r); err != nil {
|
|
return err
|
|
}
|
|
m.Primary = r.Primary
|
|
m.Fallbacks = r.Fallbacks
|
|
return nil
|
|
}
|
|
|
|
func (m AgentModelConfig) MarshalJSON() ([]byte, error) {
|
|
if len(m.Fallbacks) == 0 && m.Primary != "" {
|
|
return json.Marshal(m.Primary)
|
|
}
|
|
type raw struct {
|
|
Primary string `json:"primary,omitempty"`
|
|
Fallbacks []string `json:"fallbacks,omitempty"`
|
|
}
|
|
return json.Marshal(raw{Primary: m.Primary, Fallbacks: m.Fallbacks})
|
|
}
|
|
|
|
type AgentConfig struct {
|
|
ID string `json:"id"`
|
|
Default bool `json:"default,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
SystemPrompt string `json:"system_prompt,omitempty"`
|
|
Workspace string `json:"workspace,omitempty"`
|
|
Model *AgentModelConfig `json:"model,omitempty"`
|
|
Skills []string `json:"skills,omitempty"`
|
|
MCPServers []string `json:"mcp_servers,omitempty"`
|
|
Subagents *SubagentsConfig `json:"subagents,omitempty"`
|
|
}
|
|
|
|
type SubagentsConfig struct {
|
|
AllowAgents []string `json:"allow_agents,omitempty"`
|
|
Model *AgentModelConfig `json:"model,omitempty"`
|
|
}
|
|
|
|
type PeerMatch struct {
|
|
Kind string `json:"kind"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
type BindingMatch struct {
|
|
Channel string `json:"channel"`
|
|
AccountID string `json:"account_id,omitempty"`
|
|
Peer *PeerMatch `json:"peer,omitempty"`
|
|
GuildID string `json:"guild_id,omitempty"`
|
|
TeamID string `json:"team_id,omitempty"`
|
|
}
|
|
|
|
type AgentBinding struct {
|
|
AgentID string `json:"agent_id"`
|
|
Match BindingMatch `json:"match"`
|
|
}
|
|
|
|
// RoutingConfig controls the intelligent model routing feature.
|
|
// When enabled, each incoming message is scored against structural features
|
|
// (message length, code blocks, tool call history, conversation depth, attachments).
|
|
// Messages scoring below Threshold are sent to LightModel; all others use the
|
|
// agent's primary model. This reduces cost and latency for simple tasks without
|
|
// requiring any keyword matching — all scoring is language-agnostic.
|
|
type RoutingConfig struct {
|
|
Enabled bool `json:"enabled"`
|
|
LightModel string `json:"light_model"` // model_name from model_list to use for simple tasks
|
|
Threshold float64 `json:"threshold"` // complexity score in [0,1]; score >= threshold → primary model
|
|
}
|
|
|
|
type AgentDefaults struct {
|
|
Workspace string `json:"workspace" env:"PICOCLAW_AGENTS_DEFAULTS_WORKSPACE"`
|
|
RestrictToWorkspace bool `json:"restrict_to_workspace" env:"PICOCLAW_AGENTS_DEFAULTS_RESTRICT_TO_WORKSPACE"`
|
|
AllowReadOutsideWorkspace bool `json:"allow_read_outside_workspace" env:"PICOCLAW_AGENTS_DEFAULTS_ALLOW_READ_OUTSIDE_WORKSPACE"`
|
|
Provider string `json:"provider" env:"PICOCLAW_AGENTS_DEFAULTS_PROVIDER"`
|
|
ModelName string `json:"model_name,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_MODEL_NAME"`
|
|
Model string `json:"model" env:"PICOCLAW_AGENTS_DEFAULTS_MODEL"` // Deprecated: use model_name instead
|
|
ModelFallbacks []string `json:"model_fallbacks,omitempty"`
|
|
ImageModel string `json:"image_model,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_IMAGE_MODEL"`
|
|
ImageModelFallbacks []string `json:"image_model_fallbacks,omitempty"`
|
|
MaxTokens int `json:"max_tokens" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOKENS"`
|
|
Temperature *float64 `json:"temperature,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_TEMPERATURE"`
|
|
MaxToolIterations int `json:"max_tool_iterations" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_TOOL_ITERATIONS"`
|
|
SummarizeMessageThreshold int `json:"summarize_message_threshold" env:"PICOCLAW_AGENTS_DEFAULTS_SUMMARIZE_MESSAGE_THRESHOLD"`
|
|
SummarizeTokenPercent int `json:"summarize_token_percent" env:"PICOCLAW_AGENTS_DEFAULTS_SUMMARIZE_TOKEN_PERCENT"`
|
|
MaxMediaSize int `json:"max_media_size,omitempty" env:"PICOCLAW_AGENTS_DEFAULTS_MAX_MEDIA_SIZE"`
|
|
Routing *RoutingConfig `json:"routing,omitempty"`
|
|
}
|
|
|
|
const DefaultMaxMediaSize = 20 * 1024 * 1024 // 20 MB
|
|
|
|
func (d *AgentDefaults) GetMaxMediaSize() int {
|
|
if d.MaxMediaSize > 0 {
|
|
return d.MaxMediaSize
|
|
}
|
|
return DefaultMaxMediaSize
|
|
}
|
|
|
|
// GetModelName returns the effective model name for the agent defaults.
|
|
// It prefers the new "model_name" field but falls back to "model" for backward compatibility.
|
|
func (d *AgentDefaults) GetModelName() string {
|
|
if d.ModelName != "" {
|
|
return d.ModelName
|
|
}
|
|
return d.Model
|
|
}
|