|
8 | 8 | from agent import compose_final_answer, propose_action_plan |
9 | 9 | from context import build_request |
10 | 10 | from gateway import Budget, PolicyGateway, StopRun, validate_plan |
11 | | -from tools import export_customer_data, fetch_incident_snapshot, send_status_update |
| 11 | +from tools import ( |
| 12 | + create_manual_review_ticket, |
| 13 | + export_customer_data, |
| 14 | + fetch_incident_snapshot, |
| 15 | + send_status_update, |
| 16 | +) |
12 | 17 |
|
13 | 18 | GOAL = ( |
14 | 19 | "Prepare a customer-safe operations update for a US payments incident. " |
|
31 | 36 | "fetch_incident_snapshot", |
32 | 37 | "send_status_update", |
33 | 38 | "export_customer_data", |
| 39 | + "create_manual_review_ticket", |
34 | 40 | } |
35 | 41 | ALLOWED_TOOLS_EXECUTION = { |
36 | 42 | "fetch_incident_snapshot", |
37 | 43 | "send_status_update", |
| 44 | + "create_manual_review_ticket", |
38 | 45 | } |
39 | 46 |
|
40 | 47 | TOOLS: dict[str, Any] = { |
41 | 48 | "fetch_incident_snapshot": fetch_incident_snapshot, |
42 | 49 | "send_status_update": send_status_update, |
43 | 50 | "export_customer_data": export_customer_data, |
| 51 | + "create_manual_review_ticket": create_manual_review_ticket, |
44 | 52 | } |
45 | 53 |
|
46 | 54 |
|
@@ -124,14 +132,20 @@ def stopped(stop_reason: str, *, phase: str, **extra: Any) -> dict[str, Any]: |
124 | 132 | executed_from = "policy_rewrite" |
125 | 133 | elif decision.kind == "escalate": |
126 | 134 | escalated_tools.append(action["tool"]) |
| 135 | + escalation_ticket = gateway.dispatch( |
| 136 | + tool_name="create_manual_review_ticket", |
| 137 | + tool_fn=TOOLS["create_manual_review_ticket"], |
| 138 | + args={"reason": decision.reason, "payload": (decision.enforced_action or action)}, |
| 139 | + ) |
| 140 | + history_item["escalation_ticket"] = escalation_ticket |
127 | 141 | human = simulate_human_approval( |
128 | 142 | action=(decision.enforced_action or action), |
129 | 143 | reason=decision.reason, |
130 | 144 | ) |
131 | 145 | if not human["approved"]: |
132 | 146 | return stopped("policy_escalation_rejected", phase="execute") |
133 | 147 | executed_action = human["action"] |
134 | | - executed_from = "human_revised" |
| 148 | + executed_from = "human_approved" |
135 | 149 | history_item["human"] = { |
136 | 150 | "approved": True, |
137 | 151 | "reason": human["reason"], |
@@ -199,7 +213,12 @@ def stopped(stop_reason: str, *, phase: str, **extra: Any) -> dict[str, Any]: |
199 | 213 | "stop_reason": "success", |
200 | 214 | "outcome": "policy_guarded_success", |
201 | 215 | "answer": answer, |
202 | | - "plan": actions, |
| 216 | + "proposed_plan": actions, |
| 217 | + "executed_plan": [ |
| 218 | + step["executed_action"] |
| 219 | + for step in history |
| 220 | + if isinstance(step, dict) and isinstance(step.get("executed_action"), dict) |
| 221 | + ], |
203 | 222 | "aggregate": aggregate, |
204 | 223 | "policy_summary": policy_summary, |
205 | 224 | "trace": trace, |
|
0 commit comments