Security¶
Security subsystem -- rule engine, trust strategies, autonomy levels, output scanning, and timeout policies.
Protocol¶
protocol
¶
SecurityInterceptionStrategy protocol.
Defines the async interface that the ToolInvoker calls for
pre-tool security checks and post-tool output scanning.
SecurityInterceptionStrategy
¶
Bases: Protocol
Protocol for the security interception layer.
The ToolInvoker calls evaluate_pre_tool before execution
and scan_output after execution. Implementations may be
sync-backed (rule engine) or async (future LLM fallback).
evaluate_pre_tool
async
¶
Evaluate a tool invocation before execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
SecurityContext
|
The tool call's security context. |
required |
Returns:
| Type | Description |
|---|---|
SecurityVerdict
|
A verdict: allow, deny, or escalate. |
Source code in src/synthorg/security/protocol.py
scan_output
async
¶
Scan tool output for sensitive data after execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
SecurityContext
|
The tool call's security context. |
required |
output
|
str
|
The tool's output string. |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
An |
Source code in src/synthorg/security/protocol.py
Config¶
config
¶
Security configuration models.
Defines SecurityConfig (the top-level security configuration),
RuleEngineConfig, SecurityPolicyRule, and
OutputScanPolicyType for output scan response policy selection.
SecurityEnforcementMode
¶
Bases: StrEnum
Security enforcement mode for the SecOps service.
Controls whether security verdicts are enforced, logged only (shadow mode for calibration), or fully disabled.
Members
ACTIVE: Full enforcement -- verdicts are applied as-is. SHADOW: Shadow mode -- full evaluation pipeline runs and audit entries are recorded, but blocking verdicts (DENY, ESCALATE) are converted to ALLOW. Used for pre-deployment calibration of risk budgets. DISABLED: Security subsystem is disabled -- no evaluation, always ALLOW.
OutputScanPolicyType
¶
Bases: StrEnum
Declarative output scan policy selection.
Used in SecurityConfig to select the output scan response
policy at config time. Runtime constructor injection is also
supported for full flexibility.
Members
REDACT: Return redacted content (scanner-level redaction).
WITHHOLD: Clear redacted content, forcing fail-closed.
LOG_ONLY: Log findings but pass output through.
AUTONOMY_TIERED: Delegate based on effective autonomy level
(default -- falls back to REDACT when no autonomy
is configured).
VerdictReasonVisibility
¶
Bases: StrEnum
Controls how much of the LLM evaluator's reason is visible to agents.
Attributes:
| Name | Type | Description |
|---|---|---|
FULL |
Return the full LLM reason to the agent. |
|
GENERIC |
Return a generic denial/escalation message. |
|
CATEGORY |
Return verdict type and risk level only. |
ArgumentTruncationStrategy
¶
Bases: StrEnum
How to truncate large tool arguments for the LLM security prompt.
Attributes:
| Name | Type | Description |
|---|---|---|
WHOLE_STRING |
Truncate the serialized JSON at a character limit. |
|
PER_VALUE |
Truncate each argument value individually before serialization, preserving all key names. |
|
KEYS_AND_VALUES |
Include all keys with individually capped values (explicit about key preservation). |
LlmFallbackErrorPolicy
¶
Bases: StrEnum
What to do when the LLM security evaluation fails.
Attributes:
| Name | Type | Description |
|---|---|---|
USE_RULE_VERDICT |
Fall back to the original rule engine verdict. |
|
ESCALATE |
Send the action to the human approval queue. |
|
DENY |
Deny the action (fail-closed). |
LlmFallbackConfig
pydantic-model
¶
Bases: BaseModel
Configuration for LLM-based security evaluation fallback.
When enabled, actions that the rule engine cannot classify (no rule matched, low confidence) are routed to an LLM from a different provider family for cross-validation.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether LLM fallback is active. |
model |
NotBlankStr | None
|
Explicit model ID for security evaluation. When
|
timeout_seconds |
float
|
Maximum time for the LLM call. |
max_input_tokens |
int
|
Token budget cap for security eval prompts. |
on_error |
LlmFallbackErrorPolicy
|
Policy when the LLM call fails. |
reason_visibility |
VerdictReasonVisibility
|
How much of the LLM reason is visible to the evaluated agent. |
argument_truncation |
ArgumentTruncationStrategy
|
Strategy for truncating large tool arguments in the LLM prompt. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
enabled(bool) -
model(NotBlankStr | None) -
timeout_seconds(float) -
max_input_tokens(int) -
on_error(LlmFallbackErrorPolicy) -
reason_visibility(VerdictReasonVisibility) -
argument_truncation(ArgumentTruncationStrategy)
SecurityPolicyRule
pydantic-model
¶
Bases: BaseModel
A single configurable security policy rule.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
NotBlankStr
|
Rule name (used in matched_rules lists). |
description |
str
|
Human-readable description. |
action_types |
tuple[str, ...]
|
Action types this rule applies to ( |
verdict |
SecurityVerdictType
|
Verdict to return when rule matches. |
risk_level |
ApprovalRiskLevel
|
Risk level to assign. |
enabled |
bool
|
Whether this rule is active. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
name(NotBlankStr) -
description(str) -
action_types(tuple[str, ...]) -
verdict(SecurityVerdictType) -
risk_level(ApprovalRiskLevel) -
enabled(bool)
Validators:
-
_check_action_type_format
RuleEngineConfig
pydantic-model
¶
Bases: BaseModel
Configuration for the synchronous rule engine.
Attributes:
| Name | Type | Description |
|---|---|---|
credential_patterns_enabled |
bool
|
Detect credentials in arguments. |
data_leak_detection_enabled |
bool
|
Detect sensitive file paths / PII. |
destructive_op_detection_enabled |
bool
|
Detect destructive operations. |
path_traversal_detection_enabled |
bool
|
Detect path traversal attacks. |
max_argument_length |
int
|
Maximum argument string length for scanning. |
custom_allow_bypasses_detectors |
bool
|
When |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
credential_patterns_enabled(bool) -
data_leak_detection_enabled(bool) -
destructive_op_detection_enabled(bool) -
path_traversal_detection_enabled(bool) -
max_argument_length(int) -
custom_allow_bypasses_detectors(bool)
SecurityConfig
pydantic-model
¶
Bases: BaseModel
Top-level security configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Master switch for the security subsystem. |
enforcement_mode |
SecurityEnforcementMode
|
Security enforcement mode (active/shadow/disabled). |
rule_engine |
RuleEngineConfig
|
Rule engine configuration. |
llm_fallback |
LlmFallbackConfig
|
LLM-based fallback for uncertain evaluations. |
audit_enabled |
bool
|
Whether to record audit entries. |
post_tool_scanning_enabled |
bool
|
Scan tool output for secrets. |
hard_deny_action_types |
tuple[str, ...]
|
Action types always denied. |
auto_approve_action_types |
tuple[str, ...]
|
Action types always approved. |
output_scan_policy_type |
OutputScanPolicyType
|
Output scan response policy
(default: |
custom_policies |
tuple[SecurityPolicyRule, ...]
|
User-defined policy rules. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
enabled(bool) -
enforcement_mode(SecurityEnforcementMode) -
rule_engine(RuleEngineConfig) -
llm_fallback(LlmFallbackConfig) -
audit_enabled(bool) -
post_tool_scanning_enabled(bool) -
hard_deny_action_types(tuple[str, ...]) -
auto_approve_action_types(tuple[str, ...]) -
output_scan_policy_type(OutputScanPolicyType) -
custom_policies(tuple[SecurityPolicyRule, ...])
Validators:
-
_check_disjoint_action_types -
_check_unique_custom_policy_names -
_check_no_allow_or_escalate_bypass
enforcement_mode
pydantic-field
¶
Security enforcement mode (active/shadow/disabled)
Models¶
models
¶
Security domain models.
Defines the value objects used by the SecOps service: security verdicts, evaluation contexts, audit entries, and output scan results.
ScanOutcome
¶
Bases: StrEnum
Outcome of an output scan policy decision.
Tracks what the scanner/policy did with the output so that
downstream consumers (e.g. ToolInvoker) can distinguish
intentional withholding from scanner failure.
Attributes:
| Name | Type | Description |
|---|---|---|
CLEAN |
No sensitive data detected (default). |
|
REDACTED |
Sensitive data found, redacted content available. |
|
WITHHELD |
Content intentionally withheld by policy. |
|
LOG_ONLY |
Findings discarded by policy, original content passed
through. Always emitted with |
EvaluationConfidence
¶
Bases: StrEnum
Confidence level of a security evaluation.
Indicates whether the verdict came from a matched rule (high confidence) or the fallback risk classifier (low confidence). Low-confidence verdicts may trigger LLM-based re-evaluation.
Attributes:
| Name | Type | Description |
|---|---|---|
HIGH |
A specific security rule matched and produced the verdict. |
|
LOW |
No rule matched; verdict came from fallback risk classification. |
SecurityVerdictType
¶
Bases: StrEnum
Security verdict constants.
Three possible outcomes of a security evaluation: the tool call is allowed, denied, or escalated for human approval.
SecurityVerdict
pydantic-model
¶
Bases: BaseModel
Result of a security evaluation.
Attributes:
| Name | Type | Description |
|---|---|---|
verdict |
SecurityVerdictType
|
One of |
reason |
NotBlankStr
|
Human-readable explanation. |
risk_level |
ApprovalRiskLevel
|
Assessed risk level for the action. |
confidence |
EvaluationConfidence
|
Whether a rule matched ( |
matched_rules |
tuple[NotBlankStr, ...]
|
Names of rules that triggered. |
evaluated_at |
AwareDatetime
|
Timestamp of evaluation. |
evaluation_duration_ms |
float
|
How long the evaluation took. |
approval_id |
NotBlankStr | None
|
Set only when verdict is |
agent_visible_reason |
NotBlankStr | None
|
Reason string visible to the evaluated
agent. When |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
verdict(SecurityVerdictType) -
reason(NotBlankStr) -
risk_level(ApprovalRiskLevel) -
confidence(EvaluationConfidence) -
matched_rules(tuple[NotBlankStr, ...]) -
evaluated_at(AwareDatetime) -
evaluation_duration_ms(float) -
approval_id(NotBlankStr | None) -
agent_visible_reason(NotBlankStr | None)
Validators:
-
_check_approval_id
SecurityContext
pydantic-model
¶
Bases: BaseModel
Context passed to the security evaluator before tool execution.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_name |
NotBlankStr
|
Name of the tool being invoked. |
tool_category |
ToolCategory
|
Tool's category for access-level gating. |
action_type |
str
|
Two-level |
arguments |
dict[str, Any]
|
Tool call arguments for inspection. |
agent_id |
NotBlankStr | None
|
ID of the agent requesting the tool. |
task_id |
NotBlankStr | None
|
ID of the task being executed. |
agent_provider_name |
NotBlankStr | None
|
Name of the provider the agent is currently using. Used by the LLM security evaluator for cross-family model selection. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
tool_name(NotBlankStr) -
tool_category(ToolCategory) -
action_type(str) -
arguments(dict[str, Any]) -
agent_id(NotBlankStr | None) -
task_id(NotBlankStr | None) -
agent_provider_name(NotBlankStr | None)
Validators:
-
_check_action_type_format
AuditEntry
pydantic-model
¶
Bases: BaseModel
Immutable record of a security evaluation for the audit log.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
NotBlankStr
|
Unique entry identifier. |
timestamp |
AwareDatetime
|
When the evaluation occurred. |
agent_id |
NotBlankStr | None
|
Agent that requested the tool. |
task_id |
NotBlankStr | None
|
Task being executed. |
tool_name |
NotBlankStr
|
Tool that was evaluated. |
tool_category |
ToolCategory
|
Tool category. |
action_type |
str
|
Action type string. |
arguments_hash |
_HEX_SHA256
|
SHA-256 hex digest of serialized arguments. |
verdict |
AuditVerdictStr
|
One of |
risk_level |
ApprovalRiskLevel
|
Assessed risk level. |
reason |
NotBlankStr
|
Explanation of the verdict. |
matched_rules |
tuple[NotBlankStr, ...]
|
Rules that triggered. |
evaluation_duration_ms |
float
|
Duration of evaluation. |
confidence |
EvaluationConfidence
|
Confidence level of the evaluation source. |
approval_id |
NotBlankStr | None
|
Set when verdict is escalate. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
id(NotBlankStr) -
timestamp(AwareDatetime) -
agent_id(NotBlankStr | None) -
task_id(NotBlankStr | None) -
tool_name(NotBlankStr) -
tool_category(ToolCategory) -
action_type(str) -
arguments_hash(_HEX_SHA256) -
verdict(AuditVerdictStr) -
risk_level(ApprovalRiskLevel) -
reason(NotBlankStr) -
matched_rules(tuple[NotBlankStr, ...]) -
evaluation_duration_ms(float) -
confidence(EvaluationConfidence) -
approval_id(NotBlankStr | None)
OutputScanResult
pydantic-model
¶
Bases: BaseModel
Result of scanning tool output for sensitive data.
Attributes:
| Name | Type | Description |
|---|---|---|
has_sensitive_data |
bool
|
Whether sensitive data was detected. |
findings |
tuple[NotBlankStr, ...]
|
Descriptions of findings. |
redacted_content |
str | None
|
Content with sensitive data replaced, or None. |
outcome |
ScanOutcome
|
What the scanner/policy did with the output. Allows downstream consumers to distinguish intentional withholding from scanner failure. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
has_sensitive_data(bool) -
findings(tuple[NotBlankStr, ...]) -
redacted_content(str | None) -
outcome(ScanOutcome)
Validators:
-
_check_consistency
Service¶
service
¶
SecOps service -- the security meta-agent.
Coordinates the rule engine, audit log, output scanner, output scan
response policy, and approval store into a single
SecurityInterceptionStrategy implementation that the
ToolInvoker calls.
SecOpsService
¶
SecOpsService(
*,
config,
rule_engine,
audit_log,
output_scanner,
approval_store=None,
effective_autonomy=None,
risk_classifier=None,
output_scan_policy=None,
llm_evaluator=None,
)
Implements SecurityInterceptionStrategy.
Coordinates the rule engine, audit log, output scanner, output scan response policy, and optional approval store. Enforces security policies, scans for sensitive data, and records audit entries.
On ESCALATE: creates an ApprovalItem in the ApprovalStore
and returns the verdict with approval_id set.
Initialize the SecOps service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
SecurityConfig
|
Security configuration. |
required |
rule_engine
|
RuleEngine
|
The synchronous rule engine. |
required |
audit_log
|
AuditLog
|
Audit log for recording evaluations. |
required |
output_scanner
|
OutputScanner
|
Post-tool output scanner. |
required |
approval_store
|
ApprovalStore | None
|
Optional store for escalation items. |
None
|
effective_autonomy
|
EffectiveAutonomy | None
|
Resolved autonomy for the current run. When provided, autonomy routing is applied after the rule engine -- never bypassing security detectors. |
None
|
risk_classifier
|
RiskTierClassifier | None
|
Optional classifier for determining action risk levels in autonomy escalations. Defaults to HIGH when absent (fail-safe). |
None
|
output_scan_policy
|
OutputScanResponsePolicy | None
|
Policy applied to scan results before
returning. When |
None
|
llm_evaluator
|
LlmSecurityEvaluator | None
|
Optional LLM-based security evaluator for
uncertain verdicts ( |
None
|
Source code in src/synthorg/security/service.py
evaluate_pre_tool
async
¶
Evaluate a tool invocation before execution.
Steps
- Check disabled/DISABLED enforcement mode.
- Run rule engine.
- LLM fallback for uncertain evaluations.
- Autonomy augmentation (tighten only).
- If ESCALATE, create approval item or convert to DENY.
- Record audit entry.
- Apply shadow mode conversion if applicable.
- Return verdict.
Source code in src/synthorg/security/service.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 | |
scan_output
async
¶
Scan tool output for sensitive data.
Steps
- Delegate to the output scanner.
- Record an audit entry if sensitive data is found.
- Apply the output scan response policy to transform the result before returning.
Source code in src/synthorg/security/service.py
Action Types¶
action_types
¶
Action type taxonomy -- categories, registry, and validation.
Provides ActionTypeCategory for the 11 top-level categories and
ActionTypeRegistry for validating built-in and custom action types,
expanding category shortcuts, and querying the taxonomy.
ActionTypeCategory
¶
Bases: StrEnum
Top-level action type category prefixes.
ActionTypeRegistry
¶
Validates built-in and custom action types.
Supports category expansion (e.g. "code" → all code:* types)
and registration of custom action types at runtime.
Access the full set of registered types via all_types().
Initialize with optional custom types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_types
|
frozenset[str]
|
Additional action type strings to register. |
frozenset()
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any custom type lacks a |
Source code in src/synthorg/security/action_types.py
is_registered
¶
validate
¶
Validate that an action type is registered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_type
|
str
|
The action type string to check. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the action type is not registered. |
Source code in src/synthorg/security/action_types.py
expand_category
¶
Expand a category prefix into all matching action types.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
str
|
A category prefix (e.g. |
required |
Returns:
| Type | Description |
|---|---|
frozenset[str]
|
All action types under that category. Returns an empty |
frozenset[str]
|
frozenset if the category has no built-in types (custom |
frozenset[str]
|
types under unknown categories are included). |
Source code in src/synthorg/security/action_types.py
get_category
staticmethod
¶
Extract the category prefix from an action type string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_type
|
str
|
A |
required |
Returns:
| Type | Description |
|---|---|
str
|
The category prefix before the first |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the string does not contain |
Source code in src/synthorg/security/action_types.py
Audit¶
audit
¶
Append-only in-memory audit log for security evaluations.
AuditLog
¶
Append-only in-memory security audit log.
Thread-safety is not needed because the framework runs on a
single event loop. When max_entries is exceeded, the oldest
entries are evicted with a warning.
Future: backed by PersistenceBackend (see Memory design page).
Initialize the audit log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_entries
|
int
|
Maximum entries before oldest are evicted. |
100000
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If max_entries < 1. |
Source code in src/synthorg/security/audit.py
record
¶
Append an audit entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
AuditEntry
|
The audit entry to record. |
required |
Source code in src/synthorg/security/audit.py
query
¶
Query audit entries with optional filters.
Filters are AND-combined. Results are returned newest-first, up to limit entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str | None
|
Filter by agent ID. |
None
|
tool_name
|
str | None
|
Filter by tool name. |
None
|
verdict
|
str | None
|
Filter by verdict string. |
None
|
risk_level
|
ApprovalRiskLevel | None
|
Filter by risk level. |
None
|
since
|
AwareDatetime | None
|
Entries before this datetime are excluded. |
None
|
limit
|
int
|
Maximum results to return (must be >= 1). |
100
|
Returns:
| Type | Description |
|---|---|
tuple[AuditEntry, ...]
|
Tuple of matching entries, newest first. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If limit < 1. |
Source code in src/synthorg/security/audit.py
Output Scanner¶
output_scanner
¶
Output scanner -- post-tool output scanning for sensitive data.
Reuses credential patterns from credential_detector and PII
patterns from data_leak_detector to scan tool output for
sensitive data. Always logs findings at WARNING.
OutputScanner
¶
Scans tool output for sensitive data and optionally redacts it.
scan
¶
Scan output text for sensitive patterns.
Detection runs on the original output. Redaction builds a separate redacted copy by applying substitutions in order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
str
|
The tool's output string. |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
An |
OutputScanResult
|
redacted content. |
Source code in src/synthorg/security/output_scanner.py
output_scan_policy
¶
Output scan response policies.
Pluggable strategies that transform OutputScanResult after the
output scanner runs. Each policy decides how to handle detected
sensitive data -- redact, withhold, log-only, or delegate based on
autonomy level.
OutputScanResponsePolicy
¶
Bases: Protocol
Protocol for output scan response policies.
Implementations decide how to transform an OutputScanResult
before it is returned to the invoker.
Implementations are expected to be stateless / immutable -- the
AutonomyTieredPolicy stores policy instances by reference
(shallow copy) and wraps the mapping as read-only.
apply
¶
Apply the policy to a scan result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_result
|
OutputScanResult
|
Result from the output scanner. |
required |
context
|
SecurityContext
|
Security context of the tool invocation. |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
Transformed scan result. |
Source code in src/synthorg/security/output_scan_policy.py
RedactPolicy
¶
Return scan result as-is (redacted content preserved).
This is the default policy -- the scanner's redaction stands.
apply
¶
Pass through the scan result unchanged.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_result
|
OutputScanResult
|
Result from the output scanner. |
required |
context
|
SecurityContext
|
Security context (unused). |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
The original scan result. |
Source code in src/synthorg/security/output_scan_policy.py
WithholdPolicy
¶
Clear redacted content when sensitive data is found.
Sets ScanOutcome.WITHHELD so the invoker returns a dedicated
"withheld by policy" error -- no partial data is returned. This
is distinct from the fail-closed path used for scanner errors.
The findings tuple is deliberately preserved so that audit
consumers can categorise what was detected without seeing the
actual content.
apply
¶
Clear redacted content on sensitive results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_result
|
OutputScanResult
|
Result from the output scanner. |
required |
context
|
SecurityContext
|
Security context (unused). |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
Scan result with |
Source code in src/synthorg/security/output_scan_policy.py
LogOnlyPolicy
¶
Discard scan findings, returning a clean result.
The caller should treat the original tool output as unmodified.
Suitable for audit-only mode or high-trust agents where output
scanning is informational rather than enforced. The audit entry
written by SecOpsService.scan_output before this policy runs
preserves the original findings.
apply
¶
Return a clean OutputScanResult regardless of findings.
Suppresses enforcement while preserving the audit log entry
written by SecOpsService.scan_output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_result
|
OutputScanResult
|
Result from the output scanner. |
required |
context
|
SecurityContext
|
Security context of the tool invocation. |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
Clean |
Source code in src/synthorg/security/output_scan_policy.py
AutonomyTieredPolicy
¶
Delegate to sub-policies based on the effective autonomy level.
Uses a configurable mapping from AutonomyLevel to a concrete
policy. Falls back to RedactPolicy when no autonomy is set
or when the autonomy level has no entry in the policy map.
Initialize with autonomy and optional policy map.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effective_autonomy
|
EffectiveAutonomy | None
|
Resolved autonomy for the current run. |
required |
policy_map
|
Mapping[AutonomyLevel, OutputScanResponsePolicy] | None
|
Mapping from autonomy level to policy. Uses
defaults when |
None
|
Source code in src/synthorg/security/output_scan_policy.py
apply
¶
Delegate to the sub-policy for the current autonomy level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scan_result
|
OutputScanResult
|
Result from the output scanner. |
required |
context
|
SecurityContext
|
Security context of the tool invocation. |
required |
Returns:
| Type | Description |
|---|---|
OutputScanResult
|
Transformed scan result from the delegated policy. |
Source code in src/synthorg/security/output_scan_policy.py
Rules Engine¶
protocol
¶
SecurityRule protocol -- interface for synchronous rule evaluators.
SecurityRule
¶
Bases: Protocol
Protocol for a single security rule.
Rules are evaluated synchronously in a chain. Returning a
SecurityVerdict means the rule matched; returning None
passes through to the next rule.
evaluate
¶
Evaluate the rule against a security context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
SecurityContext
|
The tool invocation context. |
required |
Returns:
| Type | Description |
|---|---|
SecurityVerdict | None
|
A verdict if the rule matched, or |
Source code in src/synthorg/security/rules/protocol.py
engine
¶
Rule engine -- evaluates security rules in order.
RuleEngine
¶
Evaluates security rules in a defined order.
Rules are run sequentially. The first DENY or ESCALATE verdict
wins. If no rule triggers, the engine returns ALLOW with a risk
level from the RiskClassifier.
The evaluation order is determined solely by the rules tuple
passed at construction. The recommended (but not enforced) order is:
1. Policy validator (fast path: hard deny / auto approve)
2. Credential detector
3. Path traversal detector
4. Destructive operation detector
5. Data leak detector
An ALLOW from the policy validator (auto-approve) does NOT short-circuit remaining detection rules. Only DENY/ESCALATE from the policy validator is a hard exit. This ensures that auto-approved action types are still scanned for credentials, path traversal, etc.
All rules are synchronous -- the engine itself is synchronous.
Initialize the rule engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rules
|
tuple[SecurityRule, ...]
|
Ordered tuple of rules to evaluate. |
required |
risk_classifier
|
RiskClassifier
|
Fallback risk classifier. |
required |
config
|
RuleEngineConfig
|
Rule engine configuration. |
required |
Source code in src/synthorg/security/rules/engine.py
evaluate
¶
Run all rules in order, returning the final verdict.
Individual rule failures are caught and logged. A failing rule results in DENY (fail-closed) for that rule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
SecurityContext
|
The tool invocation security context. |
required |
Returns:
| Type | Description |
|---|---|
SecurityVerdict
|
A |
SecurityVerdict
|
matching rule, or ALLOW with risk from the classifier. |
Source code in src/synthorg/security/rules/engine.py
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 | |
risk_classifier
¶
Risk classifier -- maps action types to default risk levels.
RiskClassifier
¶
Maps action types to default risk levels.
Used by the rule engine when no specific rule triggers, to assign a baseline risk level based on the action type.
Initialize with optional custom risk overrides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
custom_risk_map
|
dict[str, ApprovalRiskLevel] | None
|
Additional or overriding risk mappings. |
None
|
Source code in src/synthorg/security/rules/risk_classifier.py
classify
¶
Return the risk level for an action type.
Falls back to HIGH for unknown action types (fail-safe per
DESIGN_SPEC D19).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_type
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
ApprovalRiskLevel
|
The assessed risk level. |
Source code in src/synthorg/security/rules/risk_classifier.py
Trust¶
protocol
¶
Trust strategy protocol.
Defines the pluggable interface for progressive trust strategies. All trust strategies must implement this protocol.
TrustStrategy
¶
Bases: Protocol
Protocol for progressive trust evaluation strategies.
Implementations compute trust evaluations from agent performance data and maintain per-agent trust state.
evaluate
async
¶
Evaluate an agent's trust level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent to evaluate. |
required |
current_state
|
TrustState
|
Current trust state. |
required |
snapshot
|
AgentPerformanceSnapshot
|
Agent performance snapshot. |
required |
Returns:
| Type | Description |
|---|---|
TrustEvaluationResult
|
Evaluation result with recommended level. |
Source code in src/synthorg/security/trust/protocol.py
initial_state
¶
Create the initial trust state for a newly registered agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent identifier. |
required |
Returns:
| Type | Description |
|---|---|
TrustState
|
Initial trust state. |
config
¶
Trust configuration models.
Defines TrustConfig and strategy-specific sub-configs for
progressive trust evaluation.
TrustThreshold
pydantic-model
¶
Bases: BaseModel
Threshold for a trust level transition.
Attributes:
| Name | Type | Description |
|---|---|---|
score |
float
|
Minimum score to trigger promotion. |
requires_human_approval |
bool
|
Whether human approval is required. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
score(float) -
requires_human_approval(bool)
WeightedTrustWeights
pydantic-model
¶
Bases: BaseModel
Weights for the weighted trust score computation.
Weights must sum to 1.0.
Attributes:
| Name | Type | Description |
|---|---|---|
task_difficulty |
float
|
Weight for task difficulty factor. |
completion_rate |
float
|
Weight for completion rate factor. |
error_rate |
float
|
Weight for error rate factor (inverse). |
human_feedback |
float
|
Weight for human feedback factor. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
task_difficulty(float) -
completion_rate(float) -
error_rate(float) -
human_feedback(float)
Validators:
-
_validate_weights_sum
CategoryTrustCriteria
pydantic-model
¶
Bases: BaseModel
Promotion criteria for a single tool category.
Attributes:
| Name | Type | Description |
|---|---|---|
tasks_completed |
int
|
Minimum tasks completed in this category. |
quality_score_min |
float
|
Minimum quality score. |
requires_human_approval |
bool
|
Whether human approval is required. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
tasks_completed(int) -
quality_score_min(float) -
requires_human_approval(bool)
MilestoneCriteria
pydantic-model
¶
Bases: BaseModel
Criteria for a milestone-based trust promotion.
Attributes:
| Name | Type | Description |
|---|---|---|
tasks_completed |
int
|
Minimum tasks completed. |
quality_score_min |
float
|
Minimum quality score. |
time_active_days |
int
|
Minimum days active. |
auto_promote |
bool
|
Whether to auto-promote without human approval. |
clean_history_days |
int
|
Days of clean (error-free) history required. |
requires_human_approval |
bool
|
Whether human approval is required. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
tasks_completed(int) -
quality_score_min(float) -
time_active_days(int) -
auto_promote(bool) -
clean_history_days(int) -
requires_human_approval(bool)
Validators:
-
_validate_approval_flags
requires_human_approval
pydantic-field
¶
Whether human approval is required
ReVerificationConfig
pydantic-model
¶
Bases: BaseModel
Configuration for periodic trust re-verification.
Attributes:
| Name | Type | Description |
|---|---|---|
enabled |
bool
|
Whether re-verification is enabled. |
interval_days |
int
|
Days between re-verifications. |
decay_on_idle_days |
int
|
Demote one level after this many idle days. |
decay_on_error_rate |
float
|
Demote if error rate exceeds this threshold. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
enabled(bool) -
interval_days(int) -
decay_on_idle_days(int) -
decay_on_error_rate(float)
TrustConfig
pydantic-model
¶
Bases: BaseModel
Top-level trust configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
strategy |
TrustStrategyType
|
Trust strategy type. |
initial_level |
ToolAccessLevel
|
Default initial trust level for new agents. |
weights |
WeightedTrustWeights
|
Weights for the weighted strategy. |
promotion_thresholds |
dict[str, TrustThreshold]
|
Thresholds for trust level transitions. |
initial_category_levels |
dict[str, ToolAccessLevel]
|
Initial per-category levels (per_category). |
category_criteria |
dict[str, dict[str, CategoryTrustCriteria]]
|
Per-category promotion criteria (per_category). |
milestones |
dict[str, MilestoneCriteria]
|
Milestone criteria (used by milestone strategy). |
re_verification |
ReVerificationConfig
|
Re-verification configuration (used by milestone strategy). |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
strategy(TrustStrategyType) -
initial_level(ToolAccessLevel) -
weights(WeightedTrustWeights) -
promotion_thresholds(dict[str, TrustThreshold]) -
initial_category_levels(dict[str, ToolAccessLevel]) -
category_criteria(dict[str, dict[str, CategoryTrustCriteria]]) -
milestones(dict[str, MilestoneCriteria]) -
re_verification(ReVerificationConfig)
Validators:
-
_validate_elevated_gate -
_validate_strategy_specific_fields -
_validate_category_criteria_coverage
models
¶
Trust domain models.
Frozen Pydantic models for trust state, change records, and evaluation results used by the progressive trust system.
TrustState
pydantic-model
¶
Bases: BaseModel
Current trust state for an agent.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_id |
NotBlankStr
|
The agent this trust state belongs to. |
global_level |
ToolAccessLevel
|
Current global trust/access level. |
created_at |
AwareDatetime | None
|
When trust tracking was initialized for this agent. |
category_levels |
dict[str, ToolAccessLevel]
|
Per-category trust levels (per_category strategy). |
trust_score |
float | None
|
Weighted trust score (weighted strategy). |
last_evaluated_at |
AwareDatetime | None
|
When trust was last evaluated. |
last_promoted_at |
AwareDatetime | None
|
When trust level was last promoted. |
last_decay_check_at |
AwareDatetime | None
|
When decay was last checked. |
milestone_progress |
dict[str, int | float]
|
Milestone tracking data (milestone strategy). |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
agent_id(NotBlankStr) -
global_level(ToolAccessLevel) -
created_at(AwareDatetime | None) -
category_levels(dict[str, ToolAccessLevel]) -
trust_score(float | None) -
last_evaluated_at(AwareDatetime | None) -
last_promoted_at(AwareDatetime | None) -
last_decay_check_at(AwareDatetime | None) -
milestone_progress(dict[str, int | float])
TrustChangeRecord
pydantic-model
¶
Bases: BaseModel
Record of a trust level change for audit purposes.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
NotBlankStr
|
Unique record identifier. |
agent_id |
NotBlankStr
|
Agent whose trust changed. |
old_level |
ToolAccessLevel
|
Previous trust level. |
new_level |
ToolAccessLevel
|
New trust level. |
category |
NotBlankStr | None
|
Tool category (None for global changes). |
reason |
TrustChangeReason
|
Reason for the change. |
timestamp |
AwareDatetime
|
When the change occurred. |
approval_id |
NotBlankStr | None
|
Approval item ID if human-approved. |
details |
str
|
Human-readable details. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
id(NotBlankStr) -
agent_id(NotBlankStr) -
old_level(ToolAccessLevel) -
new_level(ToolAccessLevel) -
category(NotBlankStr | None) -
reason(TrustChangeReason) -
timestamp(AwareDatetime) -
approval_id(NotBlankStr | None) -
details(str)
TrustEvaluationResult
pydantic-model
¶
Bases: BaseModel
Result of a trust evaluation by a strategy.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_id |
NotBlankStr
|
Agent evaluated. |
recommended_level |
ToolAccessLevel
|
Recommended trust level. |
current_level |
ToolAccessLevel
|
Current trust level. |
requires_human_approval |
bool
|
Whether human approval is needed. |
score |
float | None
|
Trust score (strategy-dependent). |
details |
str
|
Human-readable explanation. |
strategy_name |
NotBlankStr
|
Name of the strategy that produced this result. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
agent_id(NotBlankStr) -
recommended_level(ToolAccessLevel) -
current_level(ToolAccessLevel) -
requires_human_approval(bool) -
score(float | None) -
details(str) -
strategy_name(NotBlankStr)
requires_human_approval
pydantic-field
¶
Whether human approval is needed
service
¶
Trust service orchestrator.
Central service for managing progressive trust state, evaluation, and trust level changes for agents.
TrustService
¶
Orchestrates progressive trust evaluation and state management.
Delegates trust evaluation to a pluggable strategy, manages per-agent trust state, and enforces the security invariant that standard-to-elevated always requires human approval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
TrustStrategy
|
Trust evaluation strategy. |
required |
config
|
TrustConfig
|
Trust configuration. |
required |
approval_store
|
ApprovalStore | None
|
Optional approval store for human approval gates. |
None
|
Source code in src/synthorg/security/trust/service.py
initialize_agent
¶
Create initial trust state for a new agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent identifier. |
required |
Returns:
| Type | Description |
|---|---|
TrustState
|
Initial trust state with created_at timestamp. |
Source code in src/synthorg/security/trust/service.py
evaluate_agent
async
¶
Evaluate an agent's trust level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent to evaluate. |
required |
snapshot
|
AgentPerformanceSnapshot
|
Agent performance snapshot. |
required |
Returns:
| Type | Description |
|---|---|
TrustEvaluationResult
|
Evaluation result with recommended level. |
Raises:
| Type | Description |
|---|---|
TrustEvaluationError
|
If agent not initialized or evaluation fails. |
Source code in src/synthorg/security/trust/service.py
apply_trust_change
async
¶
Apply a trust level change based on evaluation result.
If human approval is required, creates an approval item and returns None. The change is applied when the approval is granted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent whose trust to change. |
required |
result
|
TrustEvaluationResult
|
Evaluation result to apply. |
required |
Returns:
| Type | Description |
|---|---|
TrustChangeRecord | None
|
Change record if applied, None if awaiting approval. |
Raises:
| Type | Description |
|---|---|
TrustEvaluationError
|
If agent not initialized. |
Source code in src/synthorg/security/trust/service.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
get_trust_state
¶
Get current trust state for an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent identifier. |
required |
Returns:
| Type | Description |
|---|---|
TrustState | None
|
Trust state, or None if not initialized. |
Source code in src/synthorg/security/trust/service.py
get_change_history
¶
Get trust change history for an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent identifier. |
required |
Returns:
| Type | Description |
|---|---|
tuple[TrustChangeRecord, ...]
|
Tuple of change records. |
Source code in src/synthorg/security/trust/service.py
check_decay
async
¶
Check for trust decay conditions.
Delegates to evaluate_agent first, then updates the decay check timestamp. The ordering ensures that the strategy's decay logic sees the previous last_decay_check_at value, not a freshly-updated one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
Agent to check. |
required |
snapshot
|
AgentPerformanceSnapshot
|
Agent performance snapshot. |
required |
Returns:
| Type | Description |
|---|---|
TrustEvaluationResult
|
Evaluation result (may recommend demotion on decay). |
Source code in src/synthorg/security/trust/service.py
Autonomy¶
protocol
¶
Autonomy change strategy protocol (see Operations design page, D7).
AutonomyChangeStrategy
¶
Bases: Protocol
Strategy for managing runtime autonomy level changes.
Implementations control how promotion requests, automatic downgrades, and recovery requests are handled.
request_promotion
¶
Request a promotion to a higher autonomy level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
The agent requesting promotion. |
required |
target
|
AutonomyLevel
|
The desired autonomy level. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in src/synthorg/security/autonomy/protocol.py
auto_downgrade
¶
Automatically downgrade an agent's autonomy level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
The agent to downgrade. |
required |
reason
|
DowngradeReason
|
Why the downgrade is happening. |
required |
current_level
|
AutonomyLevel | None
|
The agent's current effective autonomy level.
Used as |
None
|
Returns:
| Type | Description |
|---|---|
AutonomyLevel
|
The new (lower) autonomy level. |
Source code in src/synthorg/security/autonomy/protocol.py
request_recovery
¶
Request recovery from a previous downgrade.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
NotBlankStr
|
The agent requesting recovery. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
|
Source code in src/synthorg/security/autonomy/protocol.py
models
¶
Autonomy data models -- presets, config, effective resolution, overrides.
AutonomyPreset
pydantic-model
¶
Bases: BaseModel
A named autonomy preset defining action routing rules.
Actions listed in auto_approve are executed without human
review. Actions in human_approval require a human decision.
The two sets must be disjoint -- an action cannot be both
auto-approved and human-approval.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
AutonomyLevel
|
The autonomy level this preset represents. |
description |
NotBlankStr
|
Human-readable description. |
auto_approve |
tuple[NotBlankStr, ...]
|
Action type patterns that are auto-approved.
The special value |
human_approval |
tuple[NotBlankStr, ...]
|
Action type patterns requiring human approval.
Same expansion rules as |
security_agent |
bool
|
Whether a security agent reviews escalated actions before they reach a human. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
level(AutonomyLevel) -
description(NotBlankStr) -
auto_approve(tuple[NotBlankStr, ...]) -
human_approval(tuple[NotBlankStr, ...]) -
security_agent(bool)
Validators:
-
_validate_disjoint
AutonomyConfig
pydantic-model
¶
Bases: BaseModel
Company-level autonomy configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
AutonomyLevel
|
Default autonomy level for the company. |
presets |
dict[str, AutonomyPreset]
|
Available autonomy presets keyed by level name.
Defaults to |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
level(AutonomyLevel) -
presets(dict[str, AutonomyPreset])
Validators:
-
_validate_level_in_presets
EffectiveAutonomy
pydantic-model
¶
Bases: BaseModel
Resolved, expanded autonomy for an agent's execution run.
Produced by :class:~synthorg.security.autonomy.resolver.AutonomyResolver
by resolving the three-level chain (agent → department → company)
and expanding category shortcuts into concrete action types.
Attributes:
| Name | Type | Description |
|---|---|---|
level |
AutonomyLevel
|
Resolved autonomy level. |
auto_approve_actions |
frozenset[str]
|
Concrete action types that are auto-approved. |
human_approval_actions |
frozenset[str]
|
Concrete action types requiring human approval. |
security_agent |
bool
|
Whether the security agent reviews escalations. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
level(AutonomyLevel) -
auto_approve_actions(frozenset[str]) -
human_approval_actions(frozenset[str]) -
security_agent(bool)
Validators:
-
_validate_disjoint
AutonomyOverride
pydantic-model
¶
Bases: BaseModel
Record of a runtime autonomy downgrade for an agent.
Attributes:
| Name | Type | Description |
|---|---|---|
agent_id |
NotBlankStr
|
The agent whose autonomy was changed. |
original_level |
AutonomyLevel
|
Level before the downgrade. |
current_level |
AutonomyLevel
|
Level after the downgrade. |
reason |
DowngradeReason
|
Why the downgrade occurred. |
downgraded_at |
AwareDatetime
|
When the downgrade happened. |
requires_human_recovery |
bool
|
Whether a human must restore the level. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
agent_id(NotBlankStr) -
original_level(AutonomyLevel) -
current_level(AutonomyLevel) -
reason(DowngradeReason) -
downgraded_at(AwareDatetime) -
requires_human_recovery(bool)
Validators:
-
_validate_downgrade
requires_human_recovery
pydantic-field
¶
Whether human approval is needed to restore level
resolver
¶
Autonomy resolver -- three-level chain and category expansion.
AutonomyResolver
¶
Resolves effective autonomy via a three-level chain.
Resolution order (most specific wins): 1. Agent-level override 2. Department-level override 3. Company-level default
After resolution, category shortcuts (e.g. "code") are expanded
into concrete action types via the ActionTypeRegistry, and the
"all" shortcut is expanded to every registered action type.
Initialize the resolver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
registry
|
ActionTypeRegistry
|
Action type registry for category expansion. |
required |
config
|
AutonomyConfig
|
Company-level autonomy configuration with presets. |
required |
Source code in src/synthorg/security/autonomy/resolver.py
resolve
¶
Resolve effective autonomy from the three-level chain.
When seniority is provided, the JUNIOR/FULL constraint
(D6) is enforced automatically.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_level
|
AutonomyLevel | None
|
Per-agent override (highest priority). |
None
|
department_level
|
AutonomyLevel | None
|
Per-department override. |
None
|
seniority
|
SeniorityLevel | None
|
Agent seniority level for constraint checks. |
None
|
Returns:
| Type | Description |
|---|---|
EffectiveAutonomy
|
Fully expanded :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the resolved level has no matching preset or seniority constraints are violated. |
Source code in src/synthorg/security/autonomy/resolver.py
validate_seniority
¶
Reject JUNIOR agents with FULL autonomy (D6).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seniority
|
SeniorityLevel
|
The agent's seniority level. |
required |
autonomy
|
AutonomyLevel
|
The requested autonomy level. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a JUNIOR agent requests FULL autonomy. |
Source code in src/synthorg/security/autonomy/resolver.py
Timeout Policies¶
protocol
¶
Timeout policy and risk tier classifier protocols.
TimeoutPolicy
¶
Bases: Protocol
Protocol for approval timeout policies (see Operations design page).
Implementations determine what happens when a human does not respond to an approval request within a configured timeframe.
determine_action
async
¶
Determine the timeout action for a pending approval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
ApprovalItem
|
The pending approval item. |
required |
elapsed_seconds
|
float
|
Seconds since the item was created. |
required |
Returns:
| Type | Description |
|---|---|
TimeoutAction
|
The action to take (wait, approve, deny, or escalate). |
Source code in src/synthorg/security/timeout/protocol.py
RiskTierClassifier
¶
Bases: Protocol
Classifies action types into risk tiers for tiered timeouts.
classify
¶
Classify an action type's risk level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_type
|
str
|
The |
required |
Returns:
| Type | Description |
|---|---|
ApprovalRiskLevel
|
The risk tier for timeout policy selection. |
config
¶
Timeout policy configuration models -- discriminated union of 4 policies.
ApprovalTimeoutConfig
module-attribute
¶
ApprovalTimeoutConfig = Annotated[
Annotated[WaitForeverConfig, Tag("wait")]
| Annotated[DenyOnTimeoutConfig, Tag("deny")]
| Annotated[TieredTimeoutConfig, Tag("tiered")]
| Annotated[EscalationChainConfig, Tag("escalation")],
Discriminator(_timeout_discriminator),
]
Discriminated union of the four timeout policy configurations.
WaitForeverConfig
pydantic-model
¶
Bases: BaseModel
Wait indefinitely for human approval -- the default.
Attributes:
| Name | Type | Description |
|---|---|---|
policy |
Literal['wait']
|
Discriminator tag. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
policy(Literal['wait'])
DenyOnTimeoutConfig
pydantic-model
¶
Bases: BaseModel
Deny the action after a fixed timeout.
Attributes:
| Name | Type | Description |
|---|---|---|
policy |
Literal['deny']
|
Discriminator tag. |
timeout_minutes |
float
|
Minutes before auto-deny. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
policy(Literal['deny']) -
timeout_minutes(float)
TierConfig
pydantic-model
¶
Bases: BaseModel
Per-risk-tier timeout configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
timeout_minutes |
float
|
Minutes before the on_timeout action. |
on_timeout |
TimeoutActionType
|
What to do when the tier times out. |
actions |
tuple[str, ...]
|
Optional set of specific action types in this tier (if empty, the tier is matched by risk level). |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
timeout_minutes(float) -
on_timeout(TimeoutActionType) -
actions(tuple[str, ...])
Validators:
-
_validate_no_escalate
TieredTimeoutConfig
pydantic-model
¶
Bases: BaseModel
Per-risk-tier timeout policy.
Each tier defines its own timeout and action. Unknown action types
are classified as HIGH risk by the RiskTierClassifier (D19). If
a risk level has no tier configuration entry, the policy defaults to
WAIT (safe fallback).
Attributes:
| Name | Type | Description |
|---|---|---|
policy |
Literal['tiered']
|
Discriminator tag. |
tiers |
dict[str, TierConfig]
|
Tier configurations keyed by risk level name. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
policy(Literal['tiered']) -
tiers(dict[str, TierConfig])
Validators:
-
_validate_tier_keys
EscalationStep
pydantic-model
¶
Bases: BaseModel
A single step in an escalation chain.
Attributes:
| Name | Type | Description |
|---|---|---|
role |
NotBlankStr
|
The role to escalate to at this step. |
timeout_minutes |
float
|
Minutes to wait at this step before moving to the next. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
role(NotBlankStr) -
timeout_minutes(float)
EscalationChainConfig
pydantic-model
¶
Bases: BaseModel
Escalation chain timeout policy.
Approval is escalated through a chain of roles, each with its
own timeout. If the entire chain is exhausted, the
on_chain_exhausted action is taken.
Attributes:
| Name | Type | Description |
|---|---|---|
policy |
Literal['escalation']
|
Discriminator tag. |
chain |
tuple[EscalationStep, ...]
|
Ordered escalation steps. |
on_chain_exhausted |
TimeoutActionType
|
Action when all steps exhaust. |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
policy(Literal['escalation']) -
chain(tuple[EscalationStep, ...]) -
on_chain_exhausted(TimeoutActionType)
Validators:
-
_validate_chain
models
¶
Timeout action model -- the result of evaluating a timeout policy.
TimeoutAction
pydantic-model
¶
Bases: BaseModel
Action to take when an approval item times out.
Attributes:
| Name | Type | Description |
|---|---|---|
action |
TimeoutActionType
|
The timeout action type (wait, approve, deny, escalate). |
reason |
NotBlankStr
|
Human-readable explanation for the action. |
escalate_to |
NotBlankStr | None
|
Target role/agent for escalation (only when action is ESCALATE). |
Config:
frozen:Trueallow_inf_nan:False
Fields:
-
action(TimeoutActionType) -
reason(NotBlankStr) -
escalate_to(NotBlankStr | None)
Validators:
-
_validate_escalate_to
policies
¶
Timeout policy implementations -- wait, deny, tiered, escalation chain.
WaitForeverPolicy
¶
Always returns WAIT -- no automatic timeout action.
This is the safest default: approvals remain pending until a human responds.
determine_action
async
¶
Always wait.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
ApprovalItem
|
The pending approval item. |
required |
elapsed_seconds
|
float
|
Seconds since creation. |
required |
Returns:
| Type | Description |
|---|---|
TimeoutAction
|
WAIT action. |
Source code in src/synthorg/security/timeout/policies.py
DenyOnTimeoutPolicy
¶
Deny the action after a fixed timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_seconds
|
float
|
Seconds before auto-deny. |
required |
Source code in src/synthorg/security/timeout/policies.py
determine_action
async
¶
WAIT if under timeout, DENY if over.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
ApprovalItem
|
The pending approval item. |
required |
elapsed_seconds
|
float
|
Seconds since creation. |
required |
Returns:
| Type | Description |
|---|---|
TimeoutAction
|
WAIT or DENY action. |
Source code in src/synthorg/security/timeout/policies.py
TieredTimeoutPolicy
¶
Per-risk-tier timeout with configurable actions.
Uses a :class:RiskTierClassifier to determine the risk tier
of each approval item, then applies the corresponding tier
configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tiers
|
dict[str, TierConfig]
|
Tier configurations keyed by risk level name. |
required |
classifier
|
RiskTierClassifier
|
Risk tier classifier for action types. |
required |
Source code in src/synthorg/security/timeout/policies.py
determine_action
async
¶
Apply the tier-specific timeout policy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
ApprovalItem
|
The pending approval item. |
required |
elapsed_seconds
|
float
|
Seconds since creation. |
required |
Returns:
| Type | Description |
|---|---|
TimeoutAction
|
WAIT, DENY, APPROVE, or ESCALATE based on tier config. |
Source code in src/synthorg/security/timeout/policies.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
EscalationChainPolicy
¶
Escalate through a chain of roles, each with its own timeout.
When the entire chain is exhausted, applies the
on_chain_exhausted action.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chain
|
tuple[EscalationStep, ...]
|
Ordered escalation steps. |
required |
on_chain_exhausted
|
TimeoutActionType
|
Action when all steps exhaust. |
required |
Source code in src/synthorg/security/timeout/policies.py
determine_action
async
¶
Determine the current escalation step.
Calculates cumulative timeouts to find which step the approval is currently at.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
item
|
ApprovalItem
|
The pending approval item. |
required |
elapsed_seconds
|
float
|
Seconds since creation. |
required |
Returns:
| Type | Description |
|---|---|
TimeoutAction
|
ESCALATE (to the current step's role) or the |
TimeoutAction
|
chain-exhausted action. |
Source code in src/synthorg/security/timeout/policies.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 | |