Cortex

Go Packages

Quick reference for all Cortex Go packages and their public APIs.

All Cortex packages are importable from github.com/xraph/cortex.

Core packages

github.com/xraph/cortex

Root package. Exports context helpers, error constants, configuration, and shared types.

ExportDescription
WithTenant(ctx, id)Inject tenant ID into context
WithApp(ctx, id)Inject app ID into context
TenantFromContext(ctx)Read tenant ID from context
AppFromContext(ctx)Read app ID from context
ConfigEngine configuration struct
DefaultConfig()Returns default Config values
EntityBase entity with common fields
ErrNoStore, ErrAgentNotFound, ErrAlreadyExists, ...20+ sentinel errors

github.com/xraph/cortex/engine

The central Engine coordinator and all CRUD passthroughs.

ExportDescription
New(...Option) (*Engine, error)Create an engine
Engine.Start(ctx)Initialize the engine
Engine.Stop(ctx)Graceful shutdown (emits OnShutdown)
Engine.Store()Access the composite store
Engine.Extensions()Access the plugin registry
Engine.Config()Access the configuration
Engine.CreateAgent, GetAgent, ListAgents, ...Agent CRUD (6 methods)
Engine.CreateSkill, GetSkillByName, ListSkills, ...Skill CRUD (5 methods)
Engine.CreateTrait, GetTraitByName, ListTraits, ...Trait CRUD (5 methods)
Engine.CreateBehavior, GetBehaviorByName, ...Behavior CRUD (5 methods)
Engine.CreatePersona, GetPersonaByName, ...Persona CRUD (5 methods)
Engine.GetRun, ListRunsRun reads (2 methods)
Engine.LoadConversation, ClearConversationMemory (2 methods)
Engine.ListPendingCheckpoints, ResolveCheckpointCheckpoint (2 methods)
Option, WithStore, WithExtension, WithLogger, WithConfigEngine options

Domain packages

github.com/xraph/cortex/agent

Agent configuration and store interface.

type Config struct {
    cortex.Entity
    ID, AppID, Name, Description, SystemPrompt, Model string
    Tools []string                    // flat mode
    PersonaRef string                 // persona mode
    MaxSteps, MaxTokens int
    Temperature float64
    ReasoningLoop string
    InlineSkills, InlineTraits, InlineBehaviors []string
    Guardrails, Metadata map[string]any
}

type Store interface {  // 6 methods
    Create, Get, GetByName, Update, Delete, List
}

github.com/xraph/cortex/skill

Skills, tool bindings, knowledge references, and proficiency levels.

type Skill struct {
    cortex.Entity
    ID, AppID, Name, Description string
    Tools []ToolBinding
    Knowledge []KnowledgeRef
    SystemPromptFragment, DefaultProficiency string
    Dependencies []string
}

// Proficiency levels: Novice (0.2), Beginner (0.4),
// Competent (0.6), Proficient (0.8), Expert (1.0)

type Store interface {  // 6 methods
    CreateSkill, GetSkill, GetSkillByName, UpdateSkill, DeleteSkill, ListSkills
}

github.com/xraph/cortex/trait

Personality traits with bipolar dimensions and influences.

type Trait struct {
    cortex.Entity
    ID, AppID, Name, Description string
    Dimensions []Dimension    // bipolar axes (e.g. detached - empathetic)
    Influences []Influence    // 5 targets: tone, vocabulary, reasoning, etc.
    Category TraitCategory    // cognitive, emotional, social, behavioral
}

type Store interface {  // 6 methods
    CreateTrait, GetTrait, GetTraitByName, UpdateTrait, DeleteTrait, ListTraits
}

github.com/xraph/cortex/behavior

Reactive behaviors with triggers and actions.

type Behavior struct {
    cortex.Entity
    ID, AppID, Name, Description string
    Triggers []Trigger      // 6 types: keyword_match, sentiment_below, etc.
    Actions  []Action       // 6 types: inject_prompt, modify_tone, etc.
    Priority int
    RequiresSkill, RequiresTrait string
}

type Store interface {  // 6 methods
    CreateBehavior, GetBehavior, GetBehaviorByName, UpdateBehavior, DeleteBehavior, ListBehaviors
}

github.com/xraph/cortex/persona

Persona composition — skills, traits, behaviors, and styles.

type Persona struct {
    cortex.Entity
    ID, AppID, Name, Description, Identity string
    Skills []SkillAssignment
    Traits []TraitAssignment
    Behaviors []string
    CognitiveStyle *cognitive.Style
    CommunicationStyle *communication.Style
    Perception *perception.Model
}

type Store interface {  // 6 methods
    CreatePersona, GetPersona, GetPersonaByName, UpdatePersona, DeletePersona, ListPersonas
}

github.com/xraph/cortex/cognitive

Cognitive processing styles.

type Style struct {
    Phases []Phase
}
type Phase struct {
    Name, Prompt string
    Strategy Strategy      // analytical, creative, methodical, intuitive, critical, collaborative
    TransitionCondition    // on_complete, on_confidence, on_timeout, on_external
}

github.com/xraph/cortex/communication

Communication style configuration.

type Style struct {
    Tone, Formality, Verbosity string
    TechnicalLevel, EmojiUsage, PreferredFormat string
    AdaptToUser bool
}

github.com/xraph/cortex/perception

Perception and attention models.

type Model struct {
    AttentionFilter AttentionFilter
    ContextWindow, DetailOrientation string
}
type AttentionFilter struct {
    Name string
    Keywords, Patterns []string
    Prompt string
}

Execution packages

github.com/xraph/cortex/run

Run tracking — runs, steps, and tool calls.

type Run struct {
    ID id.AgentRunID
    AgentID, TenantID, State, Input, Output, Error string
    StepCount, TokensUsed int
    StartedAt, CompletedAt *time.Time
}
// RunStates: created, running, completed, failed, cancelled, paused

type Step struct { ID, RunID, Index, Type, Input, Output, TokensUsed, ... }
type ToolCall struct { ID, StepID, RunID, ToolName, Arguments, Result, Error, ... }

type Store interface {  // 8 methods
    CreateRun, GetRun, UpdateRun, ListRuns,
    CreateStep, ListSteps,
    CreateToolCall, ListToolCalls
}

github.com/xraph/cortex/memory

Conversation, working memory, and summaries.

type Message struct {
    Role, Content string
    ToolCalls []ToolCallRef
    Metadata map[string]any
    Timestamp time.Time
}

type Store interface {  // 8 methods
    SaveConversation, LoadConversation, ClearConversation,
    SaveWorking, LoadWorking, ClearWorking,
    SaveSummary, LoadSummaries
}

github.com/xraph/cortex/checkpoint

Human-in-the-loop checkpoints.

type Checkpoint struct {
    ID id.CheckpointID
    RunID, AgentID, TenantID string
    Reason, State string
    Decision *Decision
}
type Decision struct {
    Approved bool
    DecidedBy, Reason string
    DecidedAt time.Time
}

type Store interface {  // 4 methods
    CreateCheckpoint, GetCheckpoint, Resolve, ListPending
}

Identity package

github.com/xraph/cortex/id

TypeID-based identifiers (UUIDv7, K-sortable).

// 12 type aliases
type AgentID, SkillID, TraitID, BehaviorID, PersonaID string
type AgentRunID, StepID, ToolCallID, CheckpointID string
type MemoryID, OrchestrationID, HandoffID string

// Constructors: NewAgentID(), NewSkillID(), ...
// Parsers: ParseAgentID(s), ParseSkillID(s), ...

// Prefixes: agt_, skl_, trt_, bhv_, prs_, arun_, astp_, tcall_, cp_, mem_, orch_, hoff_

Infrastructure packages

github.com/xraph/cortex/store

Composite store interface embedding all 8 domain stores.

type Store interface {
    agent.Store      // 6 methods
    skill.Store      // 6 methods
    trait.Store      // 6 methods
    behavior.Store   // 6 methods
    persona.Store    // 6 methods
    run.Store        // 8 methods
    memory.Store     // 8 methods
    checkpoint.Store // 4 methods
    Migrate(ctx) error
    Ping(ctx) error
    Close() error
}

github.com/xraph/cortex/store/postgres

Production PostgreSQL store using bun ORM with embedded migrations.

func New(db *bun.DB) *Store

github.com/xraph/cortex/store/memory

In-memory store for testing.

func New() *Store

github.com/xraph/cortex/plugin

Plugin system — base interface, 16 lifecycle hook interfaces, and the Registry.

type Extension interface { Name() string }

// 16 hook interfaces: RunStarted, RunCompleted, RunFailed,
// StepStarted, StepCompleted, ToolCalled, ToolCompleted, ToolFailed,
// PersonaResolved, BehaviorTriggered, CognitivePhaseChanged,
// CheckpointCreated, CheckpointResolved,
// OrchestrationStarted, OrchestrationCompleted, AgentHandoff,
// Shutdown

type Registry struct { ... }
func NewRegistry(logger) *Registry
func (r *Registry) Register(Extension)
func (r *Registry) Extensions() []Extension
// 16 Emit methods: EmitRunStarted, EmitRunCompleted, ...

github.com/xraph/cortex/observability

Prometheus-compatible metrics plugin (11 counters).

func NewMetricsExtension() *MetricsExtension
func NewMetricsExtensionWithFactory(factory gu.MetricFactory) *MetricsExtension

github.com/xraph/cortex/audit_hook

Structured audit trail plugin.

func New(recorder Recorder, opts ...Option) *Extension
type Recorder interface { Record(ctx, AuditEvent) error }
type RecorderFunc func(ctx, AuditEvent) error   // adapter
// Options: WithActions(...), WithLogger(...)
// 18 action constants, 8 resource constants

github.com/xraph/cortex/api

HTTP API handlers for all 36 routes.

func New(eng *engine.Engine, router forge.Router) *API
func (a *API) Handler() http.Handler
func (a *API) RegisterRoutes(router forge.Router)

github.com/xraph/cortex/extension

Forge integration extension.

func New(opts ...ExtOption) *Extension
func (e *Extension) Engine() *engine.Engine
func (e *Extension) API() *api.API
// Implements forge.Extension: Name, Description, Version, Dependencies,
// Register, Start, Stop, Health, RegisterRoutes, Handler
// Options: WithStore, WithExtension, WithEngineOption, WithConfig,
// WithDisableRoutes, WithDisableMigrate, WithBasePath, WithLogger

Package index

PackageTypeDescription
cortexCoreRoot — context helpers, errors, config
engineCoreCentral coordinator
agentDomainAgent configuration
skillDomainSkills and tool bindings
traitDomainPersonality traits
behaviorDomainReactive behaviors
personaDomainPersona composition
cognitiveDomainCognitive styles
communicationDomainCommunication styles
perceptionDomainPerception models
runExecutionRun tracking
memoryExecutionConversation memory
checkpointExecutionHuman-in-the-loop
idIdentityTypeID identifiers
storeInfrastructureComposite store interface
store/postgresInfrastructurePostgreSQL implementation
store/memoryInfrastructureIn-memory implementation
pluginInfrastructurePlugin system
observabilityInfrastructureMetrics plugin
audit_hookInfrastructureAudit plugin
apiAPIHTTP handlers
extensionIntegrationForge extension

On this page