Automation primitives
Keep's automation primitives are the reusable building blocks that turn workflow data into decisions and side effects. They share one execution context so conditions and expressions can read alert, incident, step, action, and workflow values while steps gather data and actions send results to external systems.
Primitive model
Execution context
The execution context is the shared runtime state for one automation run. It carries the source alert or incident, provider and action definitions, constants, inputs, secrets, loop values, step results, condition results, and aliases. This shared state lets one primitive pass useful data to the next without coupling them to one provider.
The context also exposes the last successful workflow result when a workflow asks for it. That gives time-based or repeated automation a way to compare current work with prior work while keeping the current run separate.
References: keep/…/contextmanager.py• L20-85 keep/…/contextmanager.py• L151-188 keep/…/contextmanager.py• L202-290
Conditions
Conditions are reusable gates that decide whether a step or action can run. They render their comparison inputs from the execution context, evaluate the result, and save the decision so a later expression or operator view can use it.
Keep supports named condition types through a common condition contract. Threshold conditions compare numeric or percentage values above or below a limit. Assert conditions evaluate an assertion expression. A work item uses an explicit if expression when present; otherwise, all named conditions must pass.
References: keep/…/base_condition.py• L11-71 keep/…/condition_factory.py• L7-21 keep/…/threshold_condition.py• L94-134 keep/…/assert_condition.py• L16-55 keep/…/step.py• L162-272
Rules
Rules are event-level decisions that determine whether alert data is relevant to a correlation or automation outcome. The rules engine evaluates CEL expressions against sanitized alert data, tracks which parts of a compound rule match, and uses the result to group alerts and create or update incidents.
This rule layer is separate from a step or action condition. A rule decides how incoming alert events relate to incidents before workflow work runs. A condition decides whether a particular work item runs after the workflow has its context.
See Rule evaluation and expression functions for the detailed rule and expression model.
References: keep/…/rulesengine.py• L52-71 keep/…/rulesengine.py• L73-225 keep/…/rulesengine.py• L460-512
Expression functions
Expression functions are small reusable operations that transform rendered workflow values. They support common math, string, list, dictionary, date, time, JSON, and alert-history needs so workflow definitions can make simple calculations without adding a new provider.
The expression path first renders context values, then finds keep.<function>(...) calls and invokes the matching function. Functions that accept keyword arguments can receive the tenant identity from the execution context. This allows both pure transformations and selected alert-aware checks such as firing duration or first occurrence.
See Rule evaluation and expression functions for the expression input, output, and failure behavior.
References: keep/…/iohandler.py• L74-103 keep/…/iohandler.py• L118-174 keep/…/iohandler.py• L189-291 keep/…/iohandler.py• L293-410 keep/…/__init__.py• L25-93 keep/…/__init__.py• L157-188 keep/…/__init__.py• L404-510
Work primitives
Steps
Steps are data-gathering work items. They call a provider query, place the result in the execution context, and make that result available to later conditions, functions, steps, and actions.
Steps can process a collection with foreach, retry provider failures, continue after an error when allowed, and stop or continue the ordered work. Their output is therefore both a useful result and an input contract for the rest of the automation.
References: keep/…/parser.py• L488-522 keep/…/step.py• L73-160 keep/…/step.py• L342-397 keep/…/base_provider.py• L380-408
Actions
Actions are effect-producing work items. They render provider inputs from the current context and call a provider notification so automation can notify a service, update an external record, enrich an alert or incident, or perform another supported side effect.
Actions use the same work-item contract as steps, but their purpose is to change something outside the workflow. Reusable action definitions can be loaded from a file or tenant storage and merged into a workflow action by its use name. This separates a shared action design from the places that invoke it.
See Action execution and throttling for action dispatch, retry, result, and failure behavior.
References: keep/…/parser.py• L565-586 keep/…/parser.py• L623-702 keep/…/parser.py• L733-741 keep/…/base_provider.py• L183-202
Provider boundary
The provider boundary connects generic automation work to a concrete external system. A parsed step or action selects a provider type and configuration, while the common provider contract turns a step into a query or an action into a notification.
This boundary keeps primitive behavior independent of the destination. Provider results return to the shared context, and provider notification results can also update alert or incident data when the work item requests enrichment.
References: keep/…/parser.py• L524-563 keep/…/parser.py• L639-674 keep/…/base_provider.py• L47-161 keep/…/base_provider.py• L183-202
Side-effect controls
Throttling
Throttling is a guard that suppresses a repeated action when the current event should not create another side effect. A work item checks its throttle after its conditions pass and before it calls the provider, so a suppressed action does not notify or update the external system.
The one_until_resolved policy allows the first action while its related alert is firing and suppresses later actions until that alert is resolved. The decision uses the prior workflow run and its linked alert event, which makes the guard depend on workflow and alert history rather than only the current process.
See Action execution and throttling for the full throttling contract.
References: keep/…/step.py• L95-108 keep/…/step.py• L315-333 keep/…/base_throttle.py• L10-36 keep/…/throttle_factory.py• L6-13 keep/…/one_until_resolved_throttle.py• L18-39
Primitive lifecycle
The primitive lifecycle shows how shared context becomes a guarded provider call. Steps and actions use the same path until the final provider operation, while conditions and throttling can stop that operation before it creates an external effect.
flowchart LR
A[Alert or incident context] --> B[Render values and expressions]
B --> C[Evaluate conditions]
C -->|blocked| X[Skip work item]
C -->|allowed| D[Check throttling]
D -->|throttled| Y[Suppress side effect]
D -->|not throttled| E{Work type}
E -->|step| F[Query provider]
E -->|action| G[Notify provider]
F --> H[Store result in context]
G --> H
H --> I[Expose data to later work]
The parser builds the ordered work items and resolves their providers. At runtime, each work item reads the context, applies its gates, performs its provider operation, and writes its result back for later work. Workflow orchestration decides when this lifecycle starts; the primitives decide how each item behaves inside it.
References: keep/…/parser.py• L146-180 keep/…/step.py• L162-216 keep/…/step.py• L218-397 keep/…/contextmanager.py• L259-290
Primitive relationships
The primitives form two related decision layers. Event rules shape alert-to-incident behavior before workflow execution. Workflow conditions and expressions shape individual work items during execution. Steps then produce data for later decisions, and actions consume that data to create effects.
| Primitive | Main question | Primary output |
|---|---|---|
| Rule | Does this alert match the event-level correlation logic? | Matched sub-rules and incident grouping outcome |
| Condition | Should this step or action run? | Boolean result stored in context |
| Function | How should a context value be checked or transformed? | Rendered scalar, collection, object, or time value |
| Step | What data should later work use? | Provider query result in context |
| Action | What external effect should the automation create? | Provider notification result or enrichment |
| Throttle | Should a repeated effect be suppressed? | Allow or suppress decision |
This separation lets workflow automation reuse the same decision and work behavior across alert and incident flows. Workflow automation explains the larger trigger, scheduling, and execution system. The child pages Rule evaluation and expression functions and Action execution and throttling explain the two detailed primitive groups.
References: keep/…/rulesengine.py• L58-71 keep/…/step.py• L162-216 keep/…/step.py• L342-397 keep/…/base_throttle.py• L26-35
Change checklist
When these files or sections are changed, remember to consider these:
- Changes to context names or result shapes must stay aligned with template rendering, condition aliases, function arguments,
foreachvalues, and provider parameter rendering. - Changes to the shared
Steppath must preserve the distinction between providerqueryfor steps and providernotifyfor actions. - Changes to reusable action
usenames must stay aligned across workflow definitions, file or database loading, deep merge behavior, and tenant uniqueness rules. - Changes to condition types or throttle types must preserve the name-to-module factory contract and the configuration names used by workflow definitions.
- Changes to alert-history functions or
one_until_resolvedthrottling must preserve tenant, workflow, fingerprint, event, and resolved-status links. - Changes to provider result or enrichment behavior must preserve the context data that later conditions and actions read.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A condition type or throttle type does not match its factory naming contract | The work item cannot be created at parse time | Keep the configured type aligned with its registered module and class name |
A condition or if expression references data that is missing or cannot be rendered | The work item fails instead of making a safe run decision | Ensure referenced context exists or use the supported safe rendering helpers |
| A threshold compares incompatible numeric and percentage values | Condition evaluation raises an error and the work item does not run | Use the same value kind for the threshold and the rendered result |
| A provider required by a step or action is not configured | Provider creation fails or the work item runs without the intended integration | Provide a valid provider type and tenant or workflow provider configuration |
A reusable action use name does not resolve | The workflow action lacks the shared provider definition or uses incomplete merged data | Keep use names unique and aligned between the workflow and action store |
| A repeated action has no usable alert history for throttling | The throttle cannot prove prior state and may allow the action | Keep workflow execution and alert-event links available for throttled actions |
| A provider query or notification fails after retries are exhausted | The step or action raises an execution error and later work follows its continuation policy | Set retry and continuation behavior only when the downstream work can safely proceed |
Key files
| File | Why to read it |
|---|---|
| keep/…/step.py | Shows the shared lifecycle for conditions, expressions, throttling, retries, provider calls, and context updates. |
| keep/…/contextmanager.py | Defines the shared data available to every primitive and the result shapes passed between work items. |
| keep/…/iohandler.py | Explains how context templates and keep.* expressions become runtime values. |
| keep/…/condition_factory.py | Shows how named condition types become reusable condition objects. |
| keep/…/threshold_condition.py | Illustrates numeric, percentage, and multi-level condition decisions. |
| keep/…/rulesengine.py | Shows how event rules evaluate alert data and influence incident grouping. |
| keep/…/__init__.py | Defines the reusable transformation and alert-history functions exposed to expressions. |
| keep/…/parser.py | Connects workflow definitions, reusable actions, providers, steps, and actions into runtime work items. |
| keep/…/base_provider.py | Defines the provider query and notification boundary used by steps and actions. |
| keep/…/one_until_resolved_throttle.py | Illustrates history-based suppression until the related alert resolves. |