trading_agent.requests.permission_gate
¶
Holds a desk's call to a tool that needs the user's permission, and asks for it.
The tools listed in [approvals] tools are never run straight away when a desk or one of its subagents calls them. The call is saved as a permission request that lapses after [approvals] expiry_minutes, and the model is told to end its turn. If the user allows it, the harness runs exactly that call; the model never gets a way around it. A standing "Always allow" grant lets the call through at once.
The user's own actions, such as the Flatten button on the Desks page, do not pass through this gate.
Typical usage example:
gate = PermissionGate(['flatten_desk'], 5, store, grants, event_bus) if gate.needs_permission('main', call.name): result = gate.hold('main', call)
PermissionGate
¶
Decides which calls need permission, and turns them into permission requests.
Creates the gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_names
|
Collection[str]
|
The tools that need permission. |
required |
expiry_minutes
|
int
|
How long a request stays open. |
required |
store
|
UserRequestStore
|
Where requests are saved. |
required |
grants
|
PermissionGrants
|
The standing permissions. |
required |
event_bus
|
EventBus
|
Where requests are published for the web page and Telegram. |
required |
Source code in src/trading_agent/requests/permission_gate.py
needs_permission
¶
Says whether a call must wait for the user.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk calling. |
required |
tool_name
|
str
|
The tool called. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the tool is covered and the desk has no standing permission for it. |
Source code in src/trading_agent/requests/permission_gate.py
hold
¶
Saves and publishes a permission request for a call, instead of running it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk calling. |
required |
call
|
ToolCall
|
The call held. |
required |
Returns:
| Type | Description |
|---|---|
ToolResult
|
What the model is told: the request, when it lapses, and to end the turn. |