Commit ebaa4ff
ApproverAgent authorization loop + ProposeOptions interactive UX (#36)
Replaces three disconnected approval systems (ApprovalGateGrain,
UISession.RegisterApproval, orphaned NotificationService.SendApprovalAsync)
with a single agent-based primitive: ApproverAgent is a per-user reentrant
Orleans grain that decides tool authorization dynamically via its own Fast-tier
LLM, stores natural-language policies in durable state, and drives an
end-to-end Telegram inline-keyboard flow (ApprovalRequested → Telegram ↔
callback → ResolveApproval).
Every tool invocation now flows through a GatedAIFunction wrapper that blocks
execution until the Approver allows or denies. There are no hardcoded risk
levels, denylists, or timeouts — the LLM is the judge, guided only by its
system prompt and stored policies, which are written and removed conversationally
via new Thread tools (AddApproverPolicy / RemoveApproverPolicy /
ListApproverPolicies).
ProposeOptions is a new Thread-level tool whose implementation is ~10 lines:
it pushes an OptionsPart onto a per-turn hint list that ResponseStreamer drains
and renders as inline-keyboard buttons. The < 200 chars short-circuit in
ResponseStreamer is dropped; RichContentParser gains an A)/B) fallback so
lettered LLM prose still renders as buttons. Thread.AgentInstructions gains a
USER INTERACTION section telling the LLM to always use ProposeOptions instead
of inlining choices.
Security hardening from the post-implementation review:
- [Reentrant] on ApproverAgent so the blocking Authorize TCS can be completed
from a concurrent ResolveApproval call on the same grain.
- TCS waiter registered before publishing the event to close the race window.
- ExtractUserIdFromGrainKey requires a numeric head so non-user grains
(CodeOrchestrator, AgentRegistry) don't accidentally bind to a bogus
IApprover.
- ExtractThreadIdFromGrainKey strips sub-agent interface suffixes so
thread-scoped policies actually match sub-agent tool calls.
- Approver LLM pulls recent turn snippets from the Thread grain (not the
sub-agent) so localized button labels reflect the user's actual language.
- DiscoverInterfaceToolsEnabled = false on ApproverAgent prevents
self-resolution loops via auto-exposed IApprover methods.
- Approval callback ownership check — only the user who owns an approval can
resolve it; other users' taps are rejected.
- GatedAIFunction redacts api_key / token / password / authorization / bearer
strings from the args preview before it leaves the silo for the Approver LLM.
Deleted: ApprovalGateGrain, IApprovalGate, ApprovalRequest, ApprovalDecision,
PendingApproval, ApprovalResult, UISession.RegisterApproval/ResolveApproval,
ApprovalGateTests. The two UISessionTests approval cases are removed; the two
Phase2IntegrationTests approval cases are removed; 5 new ApproverAgentTests
cover AddPolicy, ListPolicies, RemovePolicy-empty, ResolveApproval no-op,
Thread-scoped policy storage.
Full verification: build clean (0 warnings, 0 errors), Core.Tests 467 passed,
Integration.Tests 7 passed, Aspire AppHost boots all 13 resources Running &
Healthy, Telegram logs "Subscribed to ... approval streams".
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 7f15f33 commit ebaa4ff
31 files changed
Lines changed: 1156 additions & 329 deletions
File tree
- src
- Agents
- Orchestration
- Security
- UI
- Core
- AI
- Agents
- Contracts
- Events
- Security
- UI
- Grains
- Telegram
- Formatting
- Services
- test/Core.Tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
30 | 44 | | |
31 | 45 | | |
32 | 46 | | |
33 | 47 | | |
| 48 | + | |
34 | 49 | | |
35 | 50 | | |
36 | 51 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| 13 | + | |
| 14 | + | |
11 | 15 | | |
12 | 16 | | |
13 | 17 | | |
| |||
64 | 68 | | |
65 | 69 | | |
66 | 70 | | |
67 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
68 | 86 | | |
69 | 87 | | |
70 | 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 | + | |
71 | 142 | | |
72 | 143 | | |
73 | 144 | | |
| |||
0 commit comments