Agent Auto-Execution Plan
Context
The AI agent currently pre-computes recommendations during email processing (hardcoded DPD-only) and saves them to AICommsTool_AgentResponse for manual approval in the EmailSimulator UI. This plan adds:
- Per-courier DB flags to control agent analysis (replaces DPD hardcode) and auto-execution (new)
- Automatic execution of agent-recommended actions in the Temporal workflow, with a 30-minute safety delay from email received time
- History visibility — auto-executed actions appear in the AI Agent History tab with clear "Temporal (auto-executed)" attribution
Both flags default OFF. Deploying the code has zero impact until explicitly enabled per courier.
Architecture Overview
flowchart TD
subgraph Workflow["ProcessEmailWorkflow"]
A["ClassifyAndProcessEmailActivity"] --> B{"EnableAgentAnalysis?"}
B -->|No| Z["Continue to outcome handling"]
B -->|Yes| C["RunAgentAnalysisActivity"]
C --> D{"EnableAgentAutoExecution\n&& !IsDryRun\n&& HasActions?"}
D -->|No| Z
D -->|Yes| E["Workflow.DelayAsync\n(30 min from email received)"]
E --> F["Execute each action via\nExecuteMacroActionActivity"]
F --> G["UpdateAgentExecutionResultsActivity\n(persist Success/Failed to ActionsJson)"]
G --> H["LogAgentAutoExecutionActivity\n(write to AICommsTool_ActionLog)"]
H --> Z
end
style A fill:#e1f5fe
style C fill:#e1f5fe
style E fill:#fff9c4
style F fill:#fff3e0
style G fill:#e8f5e9
style H fill:#e8f5e9
style Z fill:#f3e5f5Database Config Flags
Two new boolean columns on AICommsTool_CourierStatusConfig, both defaulting to false:
| Flag | Purpose | Dependency |
|---|---|---|
EnableAgentAnalysis |
Pre-compute agent recommendations during email processing | Requires EnableMonitoring |
EnableAgentAutoExecution |
Auto-execute recommendations after 30-min delay | Requires EnableAgentAnalysis |
These sit alongside existing flags like EnableCredit, EnableRejection, etc. — same versioned config pattern, same 30-second cache in the Temporal worker.
erDiagram
AICommsTool_CourierStatusConfig {
guid Id PK
guid AICommsClientId FK
bool EnableMonitoring
bool EnableCredit
bool EnableRejection
bool EnableAgentAnalysis "NEW"
bool EnableAgentAutoExecution "NEW"
int Version
bool IsActive
}
AICommsClients {
guid Id PK
string Name
}
AICommsTool_CourierStatusConfig }o--|| AICommsClients : "belongs to"Implementation Steps
Step 1: Database Entity + Migration
Files:
SDK/Objects/AI/AICommsTool_CourierStatusConfig.cs— add two bool propertiesSDK/Services/IAICommsClientConfigService.cs— addGetAgentConfigAsync()methodSDK/Services/AICommsClientConfigService.cs— implement (followsGetLLMConfigAsyncpattern)- EF migration
Step 2: New Models
New file: EmailProcessing.Common/Models/Agent/AgentAutoExecutionModels.cs
AgentConfigResult— carries flags + AICommsClientId from config activityUpdateExecutionResultsRequest— for persisting execution resultsLogAgentAutoExecutionRequest— for writing to action log
Step 3: Extend RunAgentAnalysisResult
Add List<RecommendedAction>? Actions to RunAgentAnalysisResult so the workflow can auto-execute without re-reading from DB. Populate in both the success and cached-hit paths.
Step 4: Three New Activities
graph LR
subgraph Activities["New Activities"]
GA["GetAgentConfigActivity"]
UA["UpdateAgentExecutionResultsActivity"]
LA["LogAgentAutoExecutionActivity"]
end
GA -->|reads| CS[("AICommsClientConfigService\n(30s cache)")]
UA -->|calls| ARS["AgentResponseService\n.UpdateExecutionResultsAsync()"]
LA -->|writes| AL[("AICommsTool_ActionLog")]
style GA fill:#e1f5fe
style UA fill:#e8f5e9
style LA fill:#e8f5e9| Activity | Purpose | Injection |
|---|---|---|
GetAgentConfigActivity |
Read config flags + AICommsClientId | IAICommsClientConfigService |
UpdateAgentExecutionResultsActivity |
Persist Success/Failed to ActionsJson, set CreatedBy | IAgentResponseService |
LogAgentAutoExecutionActivity |
Write to AICommsTool_ActionLog | SdkDbContext directly |
All registered in EmailProcessing.Worker/Program.cs.
Step 5: Core Workflow Changes
The most critical step — modifying ProcessEmailWorkflow.cs:
5a: Replace DPD-only guard with config check
// Before (hardcoded)
if (request.CourierName.StartsWith("DPD") && hasClaimOrTracking)
// After (config-driven)
var agentConfig = await GetAgentConfigActivity(courierName);
if (agentConfig?.EnableAgentAnalysis == true && hasClaimOrTracking)5b: Add auto-execution after analysis
if (agentConfig?.EnableAgentAutoExecution == true
&& !request.IsDryRun
&& agentResult?.Success == true
&& agentResult.Actions?.Count > 0
&& processResult.ClaimId.HasValue)
{
await AutoExecuteAgentActionsAsync(...);
}5c: AutoExecuteAgentActionsAsync method
sequenceDiagram
participant W as ProcessEmailWorkflow
participant D as Workflow.DelayAsync
participant E as ExecuteMacroActionActivity
participant U as UpdateExecutionResultsActivity
participant L as LogAutoExecutionActivity
Note over W: Email received at T
W->>D: Wait until T + 30 minutes
D-->>W: Delay complete
loop For each RecommendedAction
W->>E: Execute action (MarkAsRead, UpdateStatus, etc.)
E-->>W: Success / Failed
end
W->>U: Persist execution results to AgentResponse
Note over U: Sets CreatedBy = "Temporal (auto-executed)"
W->>L: Log to AICommsTool_ActionLog
Note over L: PerformedBy = "Temporal (auto-execute)"Step 6: Settings UI
Add "AI Agent" section to CourierStatusConfigPanel.razor with two toggles:
| Toggle | Requires | Description |
|---|---|---|
| Enable Agent Analysis | Monitoring ON | Pre-compute AI recommendations during email processing |
| Enable Auto-Execution | Analysis ON | Execute recommendations automatically after 30-min delay |
Step 7: History UI Attribution
The existing AgentHistoryPane.razor already renders CreatedBy. After auto-execution, the UpdateAgentExecutionResultsActivity sets:
CreatedBy = "Temporal (auto-executed)"This displays naturally in the History tab — no template changes needed.
| Scenario | Source Badge | CreatedBy Text |
|---|---|---|
| Pre-computed only (no execution) | TEMPORAL | Temporal |
| Auto-executed by workflow | TEMPORAL | Temporal (auto-executed) |
| Manually approved in UI | USER | safemode@claimit.ai |
Safety Guarantees
| Safety Measure | Implementation |
|---|---|
| 30-minute delay | Workflow.DelayAsync(receivedAt + 30min - now) — never acts on fresh emails |
| DryRun guard | Auto-execution completely skipped when IsDryRun = true |
| Non-critical | All agent/auto-execute code wrapped in try/catch — failures never break the workflow |
| Action isolation | Each action executes independently — one failure doesn't block others |
| Flags default OFF | Zero impact on deploy — must be explicitly enabled per courier |
| Dual flag requirement | EnableAgentAutoExecution requires EnableAgentAnalysis — can't auto-execute without analysis |
Key Files
| What | File |
|---|---|
| Entity + flags | SDK/Objects/AI/AICommsTool_CourierStatusConfig.cs |
| Config service (worker) | SDK/Services/AICommsClientConfigService.cs |
| Config service (UI) | AI.EmailSimulator/Services/AICommsClientStatusConfigService.cs |
| Settings panel | AI.EmailSimulator/Components/CourierStatusConfigPanel.razor |
| Workflow (core) | EmailProcessing.Workflows/EmailPoller/ProcessEmailWorkflow.cs |
| Agent analysis activity | EmailProcessing.Activities/EmailPoller/RunAgentAnalysisActivity.cs |
| Macro action activity | EmailProcessing.Activities/EmailPoller/ExecuteMacroActionActivity.cs |
| Agent response service | EmailProcessing.Common/Services/Agent/AgentResponseService.cs |
| Result models | EmailProcessing.Common/Models/Agent/RunAgentAnalysisModels.cs |
| Worker registration | EmailProcessing.Worker/Program.cs |