escalation
escalation
¶
Escalation protocol for low-confidence sheet execution decisions.
Provides a mechanism for escalating to external decision-makers (human or AI) when sheet confidence is too low to proceed automatically.
Phase 2 of AGI Evolution: Confidence-Based Execution
v21 Evolution: Proactive Checkpoint System - adds pre-execution checkpoints that ask for confirmation BEFORE dangerous operations, complementing the reactive escalation system.
Classes¶
CheckpointTrigger
dataclass
¶
CheckpointTrigger(name, sheet_nums=None, prompt_contains=None, min_retry_count=None, requires_confirmation=True, message='')
Configuration for a proactive checkpoint trigger.
Defines conditions that should trigger a pre-execution checkpoint, asking for confirmation BEFORE the sheet executes.
v21 Evolution: Proactive Checkpoint System - enables pre-action validation.
Attributes¶
sheet_nums
class-attribute
instance-attribute
¶
Specific sheet numbers to checkpoint (None = all sheets).
prompt_contains
class-attribute
instance-attribute
¶
Keywords in prompt that trigger checkpoint (case-insensitive).
min_retry_count
class-attribute
instance-attribute
¶
Trigger if retry count >= this value.
requires_confirmation
class-attribute
instance-attribute
¶
Whether to require explicit confirmation (True) or just warn (False).
message
class-attribute
instance-attribute
¶
Custom message to show when checkpoint triggers.
CheckpointContext
dataclass
¶
Context provided to checkpoint handlers for decision-making.
Contains all relevant information about the sheet that's about to execute, enabling informed pre-execution decisions.
v21 Evolution: Proactive Checkpoint System.
CheckpointResponse
dataclass
¶
Response from a checkpoint handler specifying how to proceed.
v21 Evolution: Proactive Checkpoint System.
Attributes¶
action
instance-attribute
¶
Action to take: - proceed: Continue with execution - abort: Stop the entire job - skip: Skip this sheet and continue to the next - modify_prompt: Proceed with modified prompt
modified_prompt
class-attribute
instance-attribute
¶
Modified prompt to use if action is 'modify_prompt'.
guidance
class-attribute
instance-attribute
¶
Optional guidance or reasoning for the decision.
HistoricalSuggestion
dataclass
¶
A suggestion from historical escalation decisions.
Represents a past escalation decision that was similar to the current situation, providing guidance based on what worked (or didn't) before.
EscalationContext
dataclass
¶
EscalationContext(job_id, sheet_num, validation_results, confidence, retry_count, error_history, prompt_used, output_summary, historical_suggestions=list())
Context provided to escalation handlers for decision-making.
Contains all relevant information about the sheet execution state that led to escalation.
v15 Evolution: Added historical_suggestions field to surface similar past escalation decisions that may inform the current decision.
Attributes¶
validation_results
instance-attribute
¶
Serialized validation results from the sheet.
confidence
instance-attribute
¶
Aggregate confidence score that triggered escalation (0.0-1.0).
historical_suggestions
class-attribute
instance-attribute
¶
Similar past escalation decisions that may inform this decision.
v15 Evolution: Populated from get_similar_escalation() results. Ordered by relevance (successful outcomes first).
EscalationResponse
dataclass
¶
Response from an escalation handler specifying how to proceed.
Determines the next action for a sheet that triggered escalation.
Attributes¶
action
instance-attribute
¶
Action to take: - retry: Retry the sheet with the same or modified prompt - skip: Skip this sheet and continue to the next - abort: Stop the entire job - modify_prompt: Retry with a modified prompt (requires modified_prompt)
modified_prompt
class-attribute
instance-attribute
¶
Modified prompt to use if action is 'modify_prompt'.
guidance
class-attribute
instance-attribute
¶
Optional guidance or reasoning for the decision.
confidence_boost
class-attribute
instance-attribute
¶
Amount to boost confidence threshold for next attempt (0.0-1.0). Allows temporary threshold adjustment based on escalation feedback.
ConsoleEscalationHandler
¶
Console-based escalation handler that prompts the user.
Implements the EscalationHandler protocol for interactive human-in-the-loop decision making.
Initialize the console escalation handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
confidence_threshold
|
float
|
Confidence below which to escalate (0.0-1.0). |
0.6
|
auto_retry_on_first_failure
|
bool
|
If True, auto-retry on first failure without escalating (reduces noise for transient issues). |
True
|
Source code in src/marianne/execution/escalation.py
Functions¶
should_escalate
async
¶
Determine if escalation is needed.
Escalates when: - Confidence is below threshold - AND (not first attempt OR auto_retry_on_first_failure is False)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_state
|
SheetState
|
Current sheet state. |
required |
validation_result
|
SheetValidationResult
|
Validation results. |
required |
confidence
|
float
|
Aggregate confidence score. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if user should be prompted for a decision. |
Source code in src/marianne/execution/escalation.py
escalate
async
¶
Prompt user for escalation decision via console.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
EscalationContext
|
Full escalation context. |
required |
Returns:
| Type | Description |
|---|---|
EscalationResponse
|
EscalationResponse based on user input. |
Source code in src/marianne/execution/escalation.py
ConsoleCheckpointHandler
¶
Console-based checkpoint handler that prompts the user before execution.
Implements the CheckpointHandler protocol for interactive human-in-the-loop decision making BEFORE sheet execution.
v21 Evolution: Proactive Checkpoint System.
Functions¶
should_checkpoint
async
¶
Determine if a checkpoint is needed before sheet execution.
Checks all configured triggers against the current sheet context.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sheet_num
|
int
|
Sheet number about to execute. |
required |
prompt
|
str
|
The prompt to be used. |
required |
retry_count
|
int
|
Number of retry attempts already made. |
required |
triggers
|
list[CheckpointTrigger]
|
List of configured checkpoint triggers. |
required |
Returns:
| Type | Description |
|---|---|
CheckpointTrigger | None
|
The first matching CheckpointTrigger, or None if no checkpoint needed. |
Source code in src/marianne/execution/escalation.py
checkpoint
async
¶
Handle checkpoint and prompt user for decision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
CheckpointContext
|
Full context about the checkpoint trigger. |
required |
Returns:
| Type | Description |
|---|---|
CheckpointResponse
|
CheckpointResponse with the action to take. |