Agent Governance ToolkitAgent Governance Toolkit 4.1.0 · Python 3.10+
Dashboard
0%

Context that changes at runtime

Runtime context is state that is not part of the request itself, such as the time of day or the budget left, passed to evaluate as a DynamicContext so a rule can read it alongside the call's own fields.

Last updated: 14 Oct, 2026 · Agent Governance Toolkit 4.1.0

The Conditions on a tool's arguments lesson read fields that travel with the call. Some things a rule wants to read are not on the call at all: the clock, the remaining budget, the current load. evaluate takes an optional second argument, a DynamicContext, and merges its fields into the context before the rules run.

Building a DynamicContext

A DynamicContext holds up to four sub-contexts: time, cost, quota and system. Each one you fill adds its fields under a dotted prefix, so a time sub-context contributes context.time.hour, context.time.day_of_week and more. A rule reads them by that exact dotted name.

python
from agent_os.policies.dynamic_context import DynamicContext, TimeContext

# the evaluator never reads the clock itself; you build the hour and hand it in
runtime = DynamicContext(time=TimeContext(hour=22))

A rule that reads the hour

This policy blocks an automated refund from 18:00 onward. Its condition's field is context.time.hour, the name the time sub-context contributes, compared with gte against 18.

python
POLICY = """
version: "1.0"
name: refund-hours
# automated refunds pause outside working hours
rules:

  - name: after-hours-refund-blocked
    condition: {field: context.time.hour, operator: gte, value: 18}
    action: deny
    priority: 10
"""

The same refund at two times of day

Evaluate the identical refund twice, handing in a different hour each time. Nothing about the request changed; the runtime context did, and so did the verdict.

ExampleThe verdict follows the hour, not the request
doc = load(POLICY)
evaluator = PolicyEvaluator(policies=[doc])

# the same refund, evaluated first at 09:00 and then at 22:00
for hour in [9, 22]:
    runtime = DynamicContext(time=TimeContext(hour=hour))
    d = evaluator.evaluate({"tool": "refund", "amount": 40}, dynamic_context=runtime)
    print(f"{hour:02d}:00  allowed={d.allowed}  rule={d.matched_rule}")

What changed between the two calls

  • At 09:00 the refund was allowed by the default action: the hour condition did not hold, no rule matched, so matched_rule is None.
  • At 22:00 the refund was denied by after-hours-refund-blocked, because 22 is at or above 18.
  • The request was byte-for-byte identical. Only the DynamicContext differed, which is what makes this a runtime decision rather than a fixed one.

The sub-contexts and the fields they add

Sub-contextDotted fields it addsA rule that reads it
timecontext.time.hour, .day_of_week, .timestampPause an action outside working hours
costcontext.cost.budget_remaining, .budget_usedDeny once a spend budget runs out
quotacontext.quota.api_calls_remainingThrottle as a rate limit nears
systemcontext.system.load, .error_rateShed load when the system is busy

Where runtime context matters

  • A time window, where an action is allowed in business hours and held otherwise.
  • A spend budget, so a tool that costs money is denied once the period's budget is gone.
  • A load-aware gate, where an expensive action is shed while the system is under strain.
Watch out. The evaluator never reads the clock, the budget or the load on its own: you build the DynamicContext and pass it on every call. A condition whose field is a plain hour instead of context.time.hour never matches, because the merged key carries the dotted prefix. TimeContext.now() fills the real clock for production, at the cost of a value that changes every run.
Try it yourself
  • Fill a cost sub-context and write a rule that denies the refund once context.cost.budget_remaining is under 100.
  • Replace the fixed hour with TimeContext.now() and watch the verdict track the real clock.
  • Change the condition's field to a plain hour and confirm the rule stops matching.

You understood something today that you didn't yesterday.