trading_agent.gateway.routes.request_routes
¶
Routes for the desks' questions, plans and permission requests to the user.
GET /api/requests the requests, pending ones only unless status=all POST /api/requests/{id}/answer answer a question request POST /api/requests/{id}/plan approve a plan, or ask for changes POST /api/requests/{id}/permission allow a held call once or always, or deny it POST /api/requests/{id}/dismiss close a request without answering GET /api/permissions the standing "Always allow" permissions POST /api/permissions/revoke make a desk ask again before using a tool
Each response is handed to the desk as a new message; the desk never waited for it. A response is recorded as given "via web" unless the client names itself with the header X-Trading-Agent-Client: terminal.
Typical usage example:
application.include_router(RequestRoutes(guard, store, responder).router())
QuestionAnswer
¶
Bases: BaseModel
The answer to one question.
Attributes:
| Name | Type | Description |
|---|---|---|
selected |
list[str]
|
The labels of the options chosen. |
other |
str
|
The user's own answer typed under "Other", or empty. |
AnswerRequest
¶
Bases: BaseModel
The body of an answer to a question request.
Attributes:
| Name | Type | Description |
|---|---|---|
answers |
list[QuestionAnswer]
|
One answer per question, in order. |
PlanDecisionRequest
¶
Bases: BaseModel
The body of a decision on a plan.
Attributes:
| Name | Type | Description |
|---|---|---|
decision |
str
|
"approve" or "revise". |
feedback |
str
|
What should change, or a note with an approval. |
PermissionDecisionRequest
¶
Bases: BaseModel
The body of a decision on a held call.
Attributes:
| Name | Type | Description |
|---|---|---|
decision |
str
|
"allow_once", "always_allow" or "deny". |
reason |
str
|
Why it was denied, or a note; may be empty. |
RevokeRequest
¶
Bases: BaseModel
The body of a revocation.
Attributes:
| Name | Type | Description |
|---|---|---|
desk |
str
|
The desk. |
tool_name |
str
|
The tool it must ask about again. |
RequestRoutes
¶
Bases: RouteGroup
The /api/requests routes.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
AccessGuard
|
Checks the access token. |
required |
store
|
UserRequestStore
|
Where the requests are kept. |
required |
responder
|
UserRequestResponder
|
Records responses and tells the desks. |
required |
grants
|
PermissionGrants | None
|
The standing permissions, or None when permissions are not used. |
None
|
Source code in src/trading_agent/gateway/routes/request_routes.py
list_requests
¶
Lists the requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
status
|
str
|
"pending" for those still waiting, or "all". |
'pending'
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The requests, oldest first. |
Source code in src/trading_agent/gateway/routes/request_routes.py
answer
¶
Answers a question request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
The request. |
required |
body
|
AnswerRequest
|
The answers. |
required |
client
|
str
|
The client that sent it, from the X-Trading-Agent-Client header. |
_CLIENT_HEADER
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The answered request. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
No such request (404), it is no longer pending (409), or the answers do not fit it (422). |
Source code in src/trading_agent/gateway/routes/request_routes.py
decide_plan
¶
Approves a plan or asks for changes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
The request. |
required |
body
|
PlanDecisionRequest
|
The decision and feedback. |
required |
client
|
str
|
The client that sent it, from the X-Trading-Agent-Client header. |
_CLIENT_HEADER
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The decided request. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
No such request (404), it is no longer pending (409), or the decision is not valid (422). |
Source code in src/trading_agent/gateway/routes/request_routes.py
decide_permission
async
¶
Allows a held call once or always, running it, or denies it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
The request. |
required |
body
|
PermissionDecisionRequest
|
The decision and reason. |
required |
client
|
str
|
The client that sent it, from the X-Trading-Agent-Client header. |
_CLIENT_HEADER
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The decided request, with the call's result when it ran. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
No such request (404), it is no longer pending or has lapsed (409), or the decision is not valid (422). |
Source code in src/trading_agent/gateway/routes/request_routes.py
list_permissions
¶
Lists the standing permissions.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The grants, oldest first. |
Source code in src/trading_agent/gateway/routes/request_routes.py
revoke_permission
¶
Makes a desk ask again before using a tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
RevokeRequest
|
The desk and the tool. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Whether a grant was removed. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
There is no such grant (404). |
Source code in src/trading_agent/gateway/routes/request_routes.py
dismiss
¶
Closes a request without answering it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request_id
|
str
|
The request. |
required |
client
|
str
|
The client that sent it, from the X-Trading-Agent-Client header. |
_CLIENT_HEADER
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The dismissed request. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
No such request (404), or it is no longer pending (409). |