Cortex
1.x
Docs/Cortex/Error Handling
Open

Reading1 min
Updated31 Jul 2026
Sourcev1/concepts/errors.mdx

Cortex defines sentinel errors in the root cortex package. All errors are created with errors.New and can be checked with errors.Is.

Store errors01

ErrorDescription
ErrNoStoreNo store was configured on the engine
ErrStoreClosedThe store has been closed
ErrMigrationFailedDatabase migration failed

Not-found errors02

ErrorDescription
ErrAgentNotFoundAgent with the given ID does not exist
ErrRunNotFoundRun with the given ID does not exist
ErrStepNotFoundStep with the given ID does not exist
ErrToolCallNotFoundTool call with the given ID does not exist
ErrSkillNotFoundSkill with the given ID does not exist
ErrTraitNotFoundTrait with the given ID does not exist
ErrBehaviorNotFoundBehavior with the given ID does not exist
ErrPersonaNotFoundPersona with the given ID does not exist
ErrCheckpointNotFoundCheckpoint with the given ID does not exist

Conflict errors03

ErrorDescription
ErrAlreadyExistsA resource with the same name already exists in this app

State errors04

ErrorDescription
ErrInvalidStateInvalid state transition (e.g., completing an already-failed run)
ErrRunCancelledThe run was cancelled
ErrRunAlreadyDoneThe run has already completed
ErrBudgetExhaustedToken or cost budget exhausted
ErrMaxStepsReachedMaximum reasoning steps reached
ErrMaxTokensReachedMaximum output tokens reached

Error wrapping05

Store implementations wrap these sentinel errors with additional context:

return fmt.Errorf("postgres: get agent %s: %w", agentID, cortex.ErrAgentNotFound)

Check errors using errors.Is:

agent, err := eng.GetAgent(ctx, agentID)
if errors.Is(err, cortex.ErrAgentNotFound) {
    // handle not found
}

API error mapping06

The HTTP API maps sentinel errors to HTTP status codes:

Sentinel errorHTTP status
ErrAgentNotFound, ErrRunNotFound, etc.404 Not Found
ErrAlreadyExists409 Conflict
ErrInvalidState, ErrRunCancelled, etc.400 Bad Request
ErrNoStore500 Internal Server Error