ActionContext is a dataclass that captures everything Attesta needs to know about a single function invocation. The @gate decorator builds it automatically from the wrapped call, but you can also construct one manually for programmatic use with Attesta.evaluate().
Import
Fields
Construction
Automatic (via @gate)
When you use the@gate decorator, ActionContext is built automatically from the live function call. The decorator populates function_name from __qualname__, extracts the docstring with inspect.getdoc(), and captures the source code with inspect.getsource().
Manual Construction
For framework integrations (LangChain, MCP, etc.) or testing, constructActionContext directly.
description Property
A computed property that returns a human-readable one-liner describing the function call, formatted asfunction_name(arg1, key=val).
description property is used throughout Attesta:
- Audit logs — as the
action_descriptionfield in every audit entry - Terminal UI — displayed to the operator during challenges
- Error messages — included in
AttestaDeniedexception messages - Logging — used in debug and info log lines
How Fields Influence Risk Scoring
TheDefaultRiskScorer analyzes ActionContext fields across five weighted factors:
The
environment field is checked separately from the hint-based scoring. Setting environment="production" adds +0.3 to the base risk score in the default scorer, in addition to any hint contributions.Hints Reference
Thehints dict is a flexible mechanism for caller-supplied risk metadata. The default risk scorer recognizes these patterns:
Serialization
ActionContext is a standard Python dataclass. You can convert it to a dictionary using dataclasses.asdict():
Python
The
timestamp field contains a datetime object. If you need JSON serialization, convert it to an ISO 8601 string first: data["timestamp"] = data["timestamp"].isoformat().