mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-14 17:07:29 +08:00
Refactor runtime around world core
This commit is contained in:
@@ -8,15 +8,15 @@ type NormalizedConfig struct {
|
||||
}
|
||||
|
||||
type NormalizedCoreConfig struct {
|
||||
DefaultProvider string `json:"default_provider,omitempty"`
|
||||
DefaultModel string `json:"default_model,omitempty"`
|
||||
MainAgentID string `json:"main_agent_id,omitempty"`
|
||||
Subagents map[string]NormalizedSubagentConfig `json:"subagents,omitempty"`
|
||||
Tools NormalizedCoreToolsConfig `json:"tools,omitempty"`
|
||||
Gateway NormalizedCoreGatewayConfig `json:"gateway,omitempty"`
|
||||
DefaultProvider string `json:"default_provider,omitempty"`
|
||||
DefaultModel string `json:"default_model,omitempty"`
|
||||
MainAgentID string `json:"main_agent_id,omitempty"`
|
||||
Agents map[string]NormalizedAgentConfig `json:"agents,omitempty"`
|
||||
Tools NormalizedCoreToolsConfig `json:"tools,omitempty"`
|
||||
Gateway NormalizedCoreGatewayConfig `json:"gateway,omitempty"`
|
||||
}
|
||||
|
||||
type NormalizedSubagentConfig struct {
|
||||
type NormalizedAgentConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Role string `json:"role,omitempty"`
|
||||
Prompt string `json:"prompt,omitempty"`
|
||||
@@ -36,21 +36,9 @@ type NormalizedCoreGatewayConfig struct {
|
||||
}
|
||||
|
||||
type NormalizedRuntimeConfig struct {
|
||||
Router NormalizedRuntimeRouterConfig `json:"router,omitempty"`
|
||||
Providers map[string]NormalizedRuntimeProviderConfig `json:"providers,omitempty"`
|
||||
}
|
||||
|
||||
type NormalizedRuntimeRouterConfig struct {
|
||||
Enabled bool `json:"enabled"`
|
||||
Strategy string `json:"strategy,omitempty"`
|
||||
AllowDirectAgentChat bool `json:"allow_direct_agent_chat,omitempty"`
|
||||
MaxHops int `json:"max_hops,omitempty"`
|
||||
DefaultTimeoutSec int `json:"default_timeout_sec,omitempty"`
|
||||
DefaultWaitReply bool `json:"default_wait_reply,omitempty"`
|
||||
StickyThreadOwner bool `json:"sticky_thread_owner,omitempty"`
|
||||
Rules []AgentRouteRule `json:"rules,omitempty"`
|
||||
}
|
||||
|
||||
type NormalizedRuntimeProviderConfig struct {
|
||||
Auth string `json:"auth,omitempty"`
|
||||
APIBase string `json:"api_base,omitempty"`
|
||||
@@ -66,33 +54,23 @@ func (c *Config) Normalize() {
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
if strings.TrimSpace(c.Agents.Router.MainAgentID) == "" {
|
||||
c.Agents.Router.MainAgentID = "main"
|
||||
if c.Agents.Agents == nil {
|
||||
c.Agents.Agents = map[string]AgentConfig{}
|
||||
}
|
||||
if c.Agents.Subagents == nil {
|
||||
c.Agents.Subagents = map[string]SubagentConfig{}
|
||||
main := c.Agents.Agents["main"]
|
||||
if !main.Enabled {
|
||||
main.Enabled = true
|
||||
}
|
||||
if c.Agents.Router.Enabled {
|
||||
mainID := strings.TrimSpace(c.Agents.Router.MainAgentID)
|
||||
if mainID == "" {
|
||||
mainID = "main"
|
||||
c.Agents.Router.MainAgentID = mainID
|
||||
}
|
||||
main := c.Agents.Subagents[mainID]
|
||||
if !main.Enabled {
|
||||
main.Enabled = true
|
||||
}
|
||||
if strings.TrimSpace(main.Role) == "" {
|
||||
main.Role = "orchestrator"
|
||||
}
|
||||
if strings.TrimSpace(main.Type) == "" {
|
||||
main.Type = "router"
|
||||
}
|
||||
if strings.TrimSpace(main.SystemPromptFile) == "" {
|
||||
main.SystemPromptFile = "agents/main/AGENT.md"
|
||||
}
|
||||
c.Agents.Subagents[mainID] = main
|
||||
if strings.TrimSpace(main.Role) == "" {
|
||||
main.Role = "orchestrator"
|
||||
}
|
||||
if strings.TrimSpace(main.Type) == "" {
|
||||
main.Type = "agent"
|
||||
}
|
||||
if strings.TrimSpace(main.PromptFile) == "" {
|
||||
main.PromptFile = "agents/main/AGENT.md"
|
||||
}
|
||||
c.Agents.Agents["main"] = main
|
||||
if provider, model := ParseProviderModelRef(c.Agents.Defaults.Model.Primary); provider != "" && model != "" {
|
||||
c.Agents.Defaults.Model.Primary = provider + "/" + model
|
||||
}
|
||||
@@ -101,8 +79,8 @@ func (c *Config) Normalize() {
|
||||
func (c *Config) NormalizedView() NormalizedConfig {
|
||||
view := NormalizedConfig{
|
||||
Core: NormalizedCoreConfig{
|
||||
MainAgentID: strings.TrimSpace(c.Agents.Router.MainAgentID),
|
||||
Subagents: map[string]NormalizedSubagentConfig{},
|
||||
MainAgentID: "main",
|
||||
Agents: map[string]NormalizedAgentConfig{},
|
||||
Tools: NormalizedCoreToolsConfig{
|
||||
ShellEnabled: c.Tools.Shell.Enabled,
|
||||
MCPEnabled: c.Tools.MCP.Enabled,
|
||||
@@ -113,16 +91,6 @@ func (c *Config) NormalizedView() NormalizedConfig {
|
||||
},
|
||||
},
|
||||
Runtime: NormalizedRuntimeConfig{
|
||||
Router: NormalizedRuntimeRouterConfig{
|
||||
Enabled: c.Agents.Router.Enabled,
|
||||
Strategy: c.Agents.Router.Strategy,
|
||||
AllowDirectAgentChat: c.Agents.Router.AllowDirectAgentChat,
|
||||
MaxHops: c.Agents.Router.MaxHops,
|
||||
DefaultTimeoutSec: c.Agents.Router.DefaultTimeoutSec,
|
||||
DefaultWaitReply: c.Agents.Router.DefaultWaitReply,
|
||||
StickyThreadOwner: c.Agents.Router.StickyThreadOwner,
|
||||
Rules: append([]AgentRouteRule(nil), c.Agents.Router.Rules...),
|
||||
},
|
||||
Providers: map[string]NormalizedRuntimeProviderConfig{},
|
||||
},
|
||||
}
|
||||
@@ -131,11 +99,11 @@ func (c *Config) NormalizedView() NormalizedConfig {
|
||||
view.Core.DefaultProvider = PrimaryProviderName(c)
|
||||
view.Core.DefaultModel = strings.TrimSpace(c.Agents.Defaults.Model.Primary)
|
||||
}
|
||||
for id, subcfg := range c.Agents.Subagents {
|
||||
view.Core.Subagents[id] = NormalizedSubagentConfig{
|
||||
for id, subcfg := range c.Agents.Agents {
|
||||
view.Core.Agents[id] = NormalizedAgentConfig{
|
||||
Enabled: subcfg.Enabled,
|
||||
Role: subcfg.Role,
|
||||
Prompt: subcfg.SystemPromptFile,
|
||||
Prompt: subcfg.PromptFile,
|
||||
Provider: subcfg.Runtime.Provider,
|
||||
ToolAllowlist: append([]string(nil), subcfg.Tools.Allowlist...),
|
||||
RuntimeClass: firstNonEmptyRuntimeClass(subcfg),
|
||||
@@ -156,7 +124,7 @@ func (c *Config) NormalizedView() NormalizedConfig {
|
||||
return view
|
||||
}
|
||||
|
||||
func firstNonEmptyRuntimeClass(subcfg SubagentConfig) string {
|
||||
func firstNonEmptyRuntimeClass(subcfg AgentConfig) string {
|
||||
switch {
|
||||
case strings.TrimSpace(subcfg.Runtime.Provider) != "":
|
||||
return "provider_bound"
|
||||
@@ -176,9 +144,6 @@ func (c *Config) ApplyNormalizedView(view NormalizedConfig) {
|
||||
if defaultProvider != "" && defaultModel != "" {
|
||||
c.Agents.Defaults.Model.Primary = normalizeProviderNameAlias(defaultProvider) + "/" + defaultModel
|
||||
}
|
||||
if strings.TrimSpace(view.Core.MainAgentID) != "" {
|
||||
c.Agents.Router.MainAgentID = strings.TrimSpace(view.Core.MainAgentID)
|
||||
}
|
||||
c.Tools.Shell.Enabled = view.Core.Tools.ShellEnabled
|
||||
c.Tools.MCP.Enabled = view.Core.Tools.MCPEnabled
|
||||
if strings.TrimSpace(view.Core.Gateway.Host) != "" {
|
||||
@@ -188,15 +153,15 @@ func (c *Config) ApplyNormalizedView(view NormalizedConfig) {
|
||||
c.Gateway.Port = view.Core.Gateway.Port
|
||||
}
|
||||
|
||||
nextSubagents := map[string]SubagentConfig{}
|
||||
for id, current := range c.Agents.Subagents {
|
||||
nextSubagents[id] = current
|
||||
nextAgents := map[string]AgentConfig{}
|
||||
for id, current := range c.Agents.Agents {
|
||||
nextAgents[id] = current
|
||||
}
|
||||
for id, item := range view.Core.Subagents {
|
||||
current := c.Agents.Subagents[id]
|
||||
for id, item := range view.Core.Agents {
|
||||
current := c.Agents.Agents[id]
|
||||
current.Enabled = item.Enabled
|
||||
current.Role = strings.TrimSpace(item.Role)
|
||||
current.SystemPromptFile = strings.TrimSpace(item.Prompt)
|
||||
current.PromptFile = strings.TrimSpace(item.Prompt)
|
||||
current.Tools.Allowlist = append([]string(nil), item.ToolAllowlist...)
|
||||
current.Runtime.Provider = strings.TrimSpace(item.Provider)
|
||||
switch strings.TrimSpace(item.RuntimeClass) {
|
||||
@@ -208,24 +173,9 @@ func (c *Config) ApplyNormalizedView(view NormalizedConfig) {
|
||||
default:
|
||||
current.Transport = strings.TrimSpace(item.RuntimeClass)
|
||||
}
|
||||
nextSubagents[id] = current
|
||||
nextAgents[id] = current
|
||||
}
|
||||
c.Agents.Subagents = nextSubagents
|
||||
|
||||
c.Agents.Router.Enabled = view.Runtime.Router.Enabled
|
||||
if strings.TrimSpace(view.Runtime.Router.Strategy) != "" {
|
||||
c.Agents.Router.Strategy = strings.TrimSpace(view.Runtime.Router.Strategy)
|
||||
}
|
||||
c.Agents.Router.AllowDirectAgentChat = view.Runtime.Router.AllowDirectAgentChat
|
||||
if view.Runtime.Router.MaxHops > 0 {
|
||||
c.Agents.Router.MaxHops = view.Runtime.Router.MaxHops
|
||||
}
|
||||
if view.Runtime.Router.DefaultTimeoutSec > 0 {
|
||||
c.Agents.Router.DefaultTimeoutSec = view.Runtime.Router.DefaultTimeoutSec
|
||||
}
|
||||
c.Agents.Router.DefaultWaitReply = view.Runtime.Router.DefaultWaitReply
|
||||
c.Agents.Router.StickyThreadOwner = view.Runtime.Router.StickyThreadOwner
|
||||
c.Agents.Router.Rules = append([]AgentRouteRule(nil), view.Runtime.Router.Rules...)
|
||||
c.Agents.Agents = nextAgents
|
||||
|
||||
nextProviders := map[string]ProviderConfig{}
|
||||
for name, current := range c.Models.Providers {
|
||||
|
||||
Reference in New Issue
Block a user