on main help sign in
chore(agent): allocate errors once, reuse errors
commita3bfa1975f4a9842e4f52735424145f521e9bab1 authorChristian Rocha <christian@rocha.is> dateWed 4 Mar 2026, 11:49 (7 months ago) parent7d50e8f
1 file changed+23−11
internal/agent/coordinator.go+23−11
internal/agent/coordinator.go+23−11
@@ -43,6 +43,18 @@ import (
4343 "github.com/qjebbs/go-jsons"
4444)
4545
46+// Coordinator errors.
47+var (
48+ errCoderAgentNotConfigured = errors.New("coder agent not configured")
49+ errModelProviderNotConfigured = errors.New("model provider not configured")
50+ errLargeModelNotSelected = errors.New("large model not selected")
51+ errSmallModelNotSelected = errors.New("small model not selected")
52+ errLargeModelProviderNotConfigured = errors.New("large model provider not configured")
53+ errSmallModelProviderNotConfigured = errors.New("small model provider not configured")
54+ errLargeModelNotFound = errors.New("large model not found in provider config")
55+ errSmallModelNotFound = errors.New("small model not found in provider config")
56+)
57+
4658type Coordinator interface {
4759 // INFO: (kujtim) this is not used yet we will use this when we have multiple agents
4860 // SetMainAgent(string)
@@ -97,7 +109,7 @@ func NewCoordinator(
97109
98110 agentCfg, ok := cfg.Agents[config.AgentCoder]
99111 if !ok {
100− return nil, errors.New("coder agent not configured")
112+ return nil, errCoderAgentNotConfigured
101113 }
102114
103115 // TODO: make this dynamic when we support multiple agents
@@ -145,7 +157,7 @@ func (c *coordinator) Run(ctx context.Context, sessionID string, prompt string,
145157
146158 providerCfg, ok := c.cfg.Providers.Get(model.ModelCfg.Provider)
147159 if !ok {
148− return nil, errors.New("model provider not configured")
160+ return nil, errModelProviderNotConfigured
149161 }
150162
151163 mergedOptions, temp, topP, topK, freqPenalty, presPenalty := mergeCallOptions(model, providerCfg)
@@ -497,16 +509,16 @@ func (c *coordinator) buildTools(ctx context.Context, agent config.Agent) ([]fan
497509func (c *coordinator) buildAgentModels(ctx context.Context, isSubAgent bool) (Model, Model, error) {
498510 largeModelCfg, ok := c.cfg.Models[config.SelectedModelTypeLarge]
499511 if !ok {
500− return Model{}, Model{}, errors.New("large model not selected")
512+ return Model{}, Model{}, errLargeModelNotSelected
501513 }
502514 smallModelCfg, ok := c.cfg.Models[config.SelectedModelTypeSmall]
503515 if !ok {
504− return Model{}, Model{}, errors.New("small model not selected")
516+ return Model{}, Model{}, errSmallModelNotSelected
505517 }
506518
507519 largeProviderCfg, ok := c.cfg.Providers.Get(largeModelCfg.Provider)
508520 if !ok {
509− return Model{}, Model{}, errors.New("large model provider not configured")
521+ return Model{}, Model{}, errLargeModelProviderNotConfigured
510522 }
511523
512524 largeProvider, err := c.buildProvider(largeProviderCfg, largeModelCfg, isSubAgent)
@@ -516,7 +528,7 @@ func (c *coordinator) buildAgentModels(ctx context.Context, isSubAgent bool) (Mo
516528
517529 smallProviderCfg, ok := c.cfg.Providers.Get(smallModelCfg.Provider)
518530 if !ok {
519− return Model{}, Model{}, errors.New("small model provider not configured")
531+ return Model{}, Model{}, errSmallModelProviderNotConfigured
520532 }
521533
522534 smallProvider, err := c.buildProvider(smallProviderCfg, smallModelCfg, true)
@@ -539,11 +551,11 @@ func (c *coordinator) buildAgentModels(ctx context.Context, isSubAgent bool) (Mo
539551 }
540552
541553 if largeCatwalkModel == nil {
542− return Model{}, Model{}, errors.New("large model not found in provider config")
554+ return Model{}, Model{}, errLargeModelNotFound
543555 }
544556
545557 if smallCatwalkModel == nil {
546− return Model{}, Model{}, errors.New("small model not found in provider config")
558+ return Model{}, Model{}, errSmallModelNotFound
547559 }
548560
549561 largeModelID := largeModelCfg.Model
@@ -871,7 +883,7 @@ func (c *coordinator) UpdateModels(ctx context.Context) error {
871883
872884 agentCfg, ok := c.cfg.Agents[config.AgentCoder]
873885 if !ok {
874− return errors.New("coder agent not configured")
886+ return errCoderAgentNotConfigured
875887 }
876888
877889 tools, err := c.buildTools(ctx, agentCfg)
@@ -893,7 +905,7 @@ func (c *coordinator) QueuedPromptsList(sessionID string) []string {
893905func (c *coordinator) Summarize(ctx context.Context, sessionID string) error {
894906 providerCfg, ok := c.cfg.Providers.Get(c.currentAgent.Model().ModelCfg.Provider)
895907 if !ok {
896− return errors.New("model provider not configured")
908+ return errModelProviderNotConfigured
897909 }
898910 return c.currentAgent.Summarize(ctx, sessionID, getProviderOptions(c.currentAgent.Model(), providerCfg))
899911}
@@ -968,7 +980,7 @@ func (c *coordinator) runSubAgent(ctx context.Context, params subAgentParams) (f
968980
969981 providerCfg, ok := c.cfg.Providers.Get(model.ModelCfg.Provider)
970982 if !ok {
971− return fantasy.ToolResponse{}, errors.New("model provider not configured")
983+ return fantasy.ToolResponse{}, errModelProviderNotConfigured
972984 }
973985
974986 // Run the agent