charmbracelet/crush · error

agent configuration is missing

Error message

agent configuration is missing

What it means

UpdateAgentModel requires app.AgentCoordinator to be non-nil before delegating to UpdateModels. If the App was constructed without an agent coordinator (initialization skipped or failed earlier, or UpdateAgentModel called on a partially-initialized App), this sentinel error is returned.

Source

Thrown at internal/app/app.go:442

				}
				// Ignore initial whitespace-only messages.
				if printed || strings.TrimSpace(part) != "" {
					printed = true
					fmt.Fprint(output, part)
				}
				messageReadBytes[msg.ID] = len(content)
			}

		case <-ctx.Done():
			stopSpinner()
			return ctx.Err()
		}
	}
}

func (app *App) UpdateAgentModel(ctx context.Context) error {
	if app.AgentCoordinator == nil {
		return fmt.Errorf("agent configuration is missing")
	}
	return app.AgentCoordinator.UpdateModels(ctx)
}

// restoreModelFromSession reads the last assistant message in the
// session and, if it used a different provider/model than the current
// config, overrides the preferred model in-memory (non-persistent)
// provided the provider/model is still available. This ensures that
// continuing a session uses the same model that produced the last
// response.
func (app *App) restoreModelFromSession(ctx context.Context, sessionID string) error {
	lastMsg, err := app.Messages.GetLastAssistantMessage(ctx, sessionID)
	if err != nil {
		if errors.Is(err, sql.ErrNoRows) {
			return nil
		}
		return fmt.Errorf("failed to get last assistant message: %w", err)
	}

View on GitHub (pinned to 7944b8e522)

Solutions

  1. Ensure App initialization (agent coordinator wiring) completes before calling UpdateAgentModel
  2. Check and handle errors from earlier init steps instead of ignoring them
  3. Nil-check/validate the App in your integration code before invoking agent methods

Example fix

// before
app.UpdateAgentModel(ctx) // may panic/error if coordinator missing
// after
if app.AgentCoordinator == nil {
	if err := app.InitCoderAgent(ctx); err != nil {
		return err
	}
}
if err := app.UpdateAgentModel(ctx); err != nil {
	return err
}
Defensive patterns

Strategy: type-guard

Validate before calling

if app == nil || app.AgentCoordinator == nil {
	return errors.New("app not fully initialized; run InitCoderAgent first")
}

Type guard

func agentReady(app *app.App) bool {
	return app != nil && app.AgentCoordinator != nil
}

Try / catch

if err := app.UpdateAgentModel(ctx); err != nil {
	if err.Error() == "agent configuration is missing" {
		return fmt.Errorf("call Init/InitCoderAgent before UpdateAgentModel: %w", err)
	}
	return err
}

Prevention

When it happens

Trigger: Calling app.UpdateAgentModel(ctx) on an App whose AgentCoordinator was never initialized — e.g. before InitCoderAgent/agent wiring completed, or after initialization failed and the error was ignored.

Common situations: Embedding crush as a library and calling UpdateAgentModel before app setup finished; initialization error swallowed earlier in startup; tests constructing App directly without a coordinator.

Related errors


AI-assisted analysis of charmbracelet/crush@7944b8e522 (2026-08-29). Data as JSON: /api/errors/a26fc027e566ff5d. Report an issue: GitHub.