Skip to content

API Reference navrules.context

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

navrules.context

View source

Evaluation context: the subject (user/employee) side of a rule evaluation.

Port of nav-rewards EvalContext decoupled from aiohttp and navigator_auth: request is opaque, and session-object extraction is parameterizable. Unifies the three duplicated context builders behind from_user().

Alias Environment

Re-exported from navrules.environment.Environment.

Class EvalContext

Evaluation context built from a subject (user) and session data.

Behaves as a mapping whose missing keys resolve to False (so rules can probe optional attributes safely), with attribute-style access into the underlying store.

Parameter Type Default Description
request Any None
user Any None
session Any None
connection Any None
*args Any ()
session_object_key Optional[str] None
**kwargs Any {}

Method EvalContext.from_user

Build a context from a user object with a synthetic session.

from_user(user: Any, session: Optional[dict] = None, **extra: Any) -> 'EvalContext'

Parameter Type Default Description
user Any The subject being evaluated (dict or model object).
session Optional[dict] None Optional explicit session dict; when omitted a minimal one is synthesized from the user's fields.
**extra Any {} Additional context attributes (e.g. worked_hours=9.5).

Returns: 'EvalContext'

Method EvalContext.update

Write entries into the store (not the underlying dict).

update(*args: Any, **kwargs: Any) -> None

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Method EvalContext.items

items()

Method EvalContext.keys

keys() -> list

Returns: list

Method EvalContext.set

set(key: str, value: Any) -> None

Parameter Type Default Description
key str
value Any

Method EvalContext.get_computed

Calculate and cache a computed value via the function registry.

The function receives (user, env, conn, **kwargs) where conn is acquired from env.connection when available.

get_computed(function_path: str, env: 'Environment', registry: Optional[FunctionRegistry] = None, **kwargs: Any) -> Any

Parameter Type Default Description
function_path str
env 'Environment'
registry Optional[FunctionRegistry] None
**kwargs Any {}

Returns: Any

Method EvalContext.clear_computed_cache

Clear the computed-value cache.

clear_computed_cache() -> None

Method EvalContext.flatten

Produce the flat scalar dict used for declarative matching.

Keys are emitted with explicit prefixes (ctx.<key>/env.<key>) plus bare aliases where ctx wins over env — mirroring the resolution order of the condition DSL. Precedence inside ctx: session scalars < user fields < direct store entries.

flatten(env: Optional['Environment'] = None) -> dict[str, Any]

Parameter Type Default Description
env Optional['Environment'] None

Returns: dict[str, Any]

Alias FunctionRegistry

Re-exported from navrules.registry.FunctionRegistry.

Alias default_registry

Re-exported from navrules.registry.default_registry.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally