Cortex

Behaviors

Define what an agent does — condition-triggered action patterns.

A Behavior is a condition-triggered action pattern — the "habits" and "reflexes" that compose skills and traits into contextual responses. When a trigger condition is met, the behavior fires its actions.

Structure

type Behavior struct {
    cortex.Entity
    ID            id.BehaviorID
    Name          string
    Description   string
    AppID         string
    Triggers      []Trigger
    Actions       []Action
    Priority      int
    RequiresSkill string
    RequiresTrait string
    Metadata      map[string]any
}

Triggers

Triggers define when a behavior activates:

type Trigger struct {
    Type    TriggerType
    Pattern string       // optional pattern for matching
}

Trigger types

TypeDescription
on_inputFires when user input matches a pattern
on_tool_resultFires when a tool returns a specific result
on_errorFires when an error occurs
on_step_countFires when the step count reaches a threshold
on_contextFires based on conversation context
alwaysFires on every step

Actions

Actions define what happens when a behavior triggers:

type Action struct {
    Type   ActionType
    Target string      // action-specific target
    Value  any         // action-specific value
}

Action types

TypeDescription
inject_promptInject text into the system prompt
prefer_skillIncrease preference for a specific skill
require_toolForce usage of a specific tool
modify_paramModify a runtime parameter
switch_cognitiveSwitch to a different cognitive phase
add_guardrailAdd a runtime guardrail check

Priority

When multiple behaviors trigger simultaneously, they execute in priority order (lower number = higher priority):

behavior := &behavior.Behavior{
    Priority: 10, // fires before priority 20
}

Skill and trait requirements

A behavior can require that a specific skill or trait is active:

behavior := &behavior.Behavior{
    Name:          "verify-before-suggest",
    RequiresSkill: "code-review",
    RequiresTrait: "thoroughness",
    Triggers: []behavior.Trigger{
        {Type: behavior.TriggerAlways},
    },
    Actions: []behavior.Action{
        {Type: behavior.ActionInjectPrompt, Value: "Always verify your analysis before suggesting changes."},
    },
}

Store interface

type Store interface {
    CreateBehavior(ctx context.Context, behavior *Behavior) error
    GetBehavior(ctx context.Context, behaviorID id.BehaviorID) (*Behavior, error)
    GetBehaviorByName(ctx context.Context, appID, name string) (*Behavior, error)
    UpdateBehavior(ctx context.Context, behavior *Behavior) error
    DeleteBehavior(ctx context.Context, behaviorID id.BehaviorID) error
    ListBehaviors(ctx context.Context, filter *ListFilter) ([]*Behavior, error)
}

API routes

MethodPathDescription
POST/cortex/behaviorsCreate a behavior
GET/cortex/behaviorsList behaviors
GET/cortex/behaviors/{name}Get a behavior by name
PUT/cortex/behaviors/{name}Update a behavior
DELETE/cortex/behaviors/{id}Delete a behavior

On this page