trading_agent.gateway.routes.desk_routes
¶
Routes for the desks: their state, messages, and pause, resume and flatten.
GET /api/desks every desk's state, models and session GET /api/desks/{desk} one desk, with its persona GET /api/desks/{desk}/context how full the model's context window is, and the desk's tools GET /api/desks/{desk}/commands the desk's slash commands and usable skills, for a command menu POST /api/desks/{desk}/messages queue a message or /command, with uploads named by id; the reply arrives on /ws/events POST /api/desks/{desk}/model try one backend first, optionally with another of its provider's models, or return to the configured order POST /api/desks/{desk}/pause stop asking models until resumed (commands still work) POST /api/desks/{desk}/resume start answering again POST /api/desks/{desk}/flatten cancel the desk's orders and close its positions
Flatten runs the desk's own flatten_desk tool, so it goes through the risk engine and the journal exactly as when the desk calls it.
Typical usage example:
application.include_router(DeskRoutes(desks, guard, parts, layout, 'dry_run').router())
MessageRequest
¶
Bases: BaseModel
The body of a message sent to a desk.
Attributes:
| Name | Type | Description |
|---|---|---|
text |
str
|
What to tell or ask the desk; may be empty when files are attached. |
attachment_ids |
list[str]
|
The uploads to send with it, from POST /api/desks/{desk}/attachments. |
ModelRequest
¶
Bases: BaseModel
The body of a model choice.
Attributes:
| Name | Type | Description |
|---|---|---|
backend |
str | None
|
The backend to try first, or None for the configured order. |
model |
str | None
|
Another model of that backend's provider, from its other_models, or None for its configured model. |
FlattenRequest
¶
Bases: BaseModel
The body of a flatten request.
Attributes:
| Name | Type | Description |
|---|---|---|
reason |
str
|
Why, for the journal. |
DeskRoutes
¶
DeskRoutes(desks, guard, parts=None, layout=None, mode='dry_run', attachment_store=None, backend_configurations=None)
Bases: RouteGroup
The /api/desks routes.
Creates the routes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desks
|
Mapping[str, DeskRuntime]
|
The running desks, keyed by name. |
required |
guard
|
AccessGuard
|
Checks the access token. |
required |
parts
|
Mapping[str, DeskParts] | None
|
Each desk's tools, for flatten, or None when flatten is not offered. |
None
|
layout
|
WorkspaceLayout | None
|
Where the personas are, or None to leave them out. |
None
|
mode
|
str
|
"dry_run" or "live", reported with each desk. |
'dry_run'
|
attachment_store
|
AttachmentStore | None
|
Where uploads are kept, or None when messages cannot carry files. |
None
|
backend_configurations
|
Mapping[str, BackendConfiguration] | None
|
Each backend's settings, keyed by name, for the model menu, or None to leave them out. |
None
|
Source code in src/trading_agent/gateway/routes/desk_routes.py
list_desks
¶
Every desk's state.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desks, in configuration order, and the mode. |
Source code in src/trading_agent/gateway/routes/desk_routes.py
desk
¶
One desk's state and persona.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desk's state, models, session and Persona.md text. |
Source code in src/trading_agent/gateway/routes/desk_routes.py
context
¶
How full the desk's context window is, and which tools it has.
The snapshot belongs to the backend that answered last. Claude's is measured by Claude Code at the end of each turn; the other backends' are estimated from their conversation when asked.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desk's name, the snapshot or None when there is none yet, and its tool names. |
Source code in src/trading_agent/gateway/routes/desk_routes.py
commands
¶
The desk's slash commands and usable skills.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desk's name and its entries, each with name, usage, description, kind and runs. |
Source code in src/trading_agent/gateway/routes/desk_routes.py
send_message
¶
Queues a message for a desk and returns at once.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
message
|
MessageRequest
|
The message. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The new trigger's identifier, to match it with later events. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
There is no such desk (404), or an attachment is not one of the desk's uploads (422). |
Source code in src/trading_agent/gateway/routes/desk_routes.py
choose_model
¶
Tries one backend first from now on, optionally with another of its provider's models, or returns to the configured order, as /model does.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
request
|
ModelRequest
|
The backend to try first and its model, or None for both. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desk's state afterwards. |
Raises:
| Type | Description |
|---|---|
HTTPException
|
The desk has no models (status 409), or no backend of that name, or the backend does not offer that model (status 400). |
Source code in src/trading_agent/gateway/routes/desk_routes.py
pause
¶
Pauses a desk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desk's state. |
Source code in src/trading_agent/gateway/routes/desk_routes.py
resume
¶
Resumes a desk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The desk's state. |
Source code in src/trading_agent/gateway/routes/desk_routes.py
flatten
async
¶
Cancels a desk's orders and closes its positions, through its own flatten_desk tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_name
|
str
|
The desk. |
required |
request
|
FlattenRequest
|
Why. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The tool's report and whether it failed. |