trading_agent.runtime.desk_runtime
¶
One desk: its queue of triggers and the loop that works through them.
A desk handles one trigger at a time, so it never runs two turns at once. Different desks each have their own runtime and run side by side.
A message from the user that arrives while a model turn is running is steering: it goes to the desk's steering inbox and the running turn picks it up at its next tool round, instead of waiting for the turn to end. /stop skips the queue altogether and cancels the running turn. Commands that only read the desk, such as /status, also skip the queue and are answered beside the running turn, and so is /btw, which asks a model a side question.
A message that starts with a slash is a command and is answered by code. Anything else goes to the desk's turn runner, prefixed with a line stating the India time and what woke the desk; those facts change every turn, so they belong in the message rather than in the system prompt. A desk with a session keeper lets it resume the saved session when the desk starts, and roll over to a new session before the first turn of a new day.
Typical usage example:
desk = DeskRuntime(desk_configuration, event_bus, turn_runner, 'dry_run') task = asyncio.create_task(desk.run()) desk.submit(trigger)
DeskState
¶
Bases: StrEnum
Whether a desk is waiting for a trigger or running a turn.
DeskRuntime
¶
DeskRuntime(desk_configuration, event_bus, turn_runner, mode='dry_run', tool_registry=None, session_keeper=None, skill_library=None, usage_tracker=None, market_status=None, steering_inbox=None, command_parts=None)
The running state of one desk.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
The desk's name. |
|
state |
Whether the desk is stopped, idle or running a turn. |
|
paused |
Whether the desk answers without asking any model. |
|
turn_runner |
What runs each turn. |
|
usage_tracker |
Today's model usage, shown by /usage, or None. |
Creates the desk without starting its loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
desk_configuration
|
DeskConfiguration
|
The desk's settings. |
required |
event_bus
|
EventBus
|
The bus to publish the desk's events on. |
required |
turn_runner
|
TurnRunner
|
What runs each turn. |
required |
mode
|
str
|
"dry_run" or "live", reported by /status. |
'dry_run'
|
tool_registry
|
ToolRegistry | None
|
The desk's tools, closed when the desk stops, or None. |
None
|
session_keeper
|
SessionKeeper | None
|
Keeps the desk's sessions across restarts and days, or None to keep nothing. |
None
|
skill_library
|
SkillLibrary | None
|
The desk's skills, invocable as / |
None
|
usage_tracker
|
UsageTracker | None
|
Today's model usage, shown by /usage, or None. |
None
|
market_status
|
MarketStatus | None
|
Describes the market for the context line, or None to leave it out. |
None
|
steering_inbox
|
SteeringInbox | None
|
Where mid-turn messages wait for the running turn, shared with the turn runner; None creates one that only this desk reads. |
None
|
command_parts
|
CommandParts | None
|
The subagents and journal some commands read, or None; the desk's own tool registry is added to it. |
None
|
Source code in src/trading_agent/runtime/desk_runtime.py
submit
¶
Adds a trigger to the end of the desk's queue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
trigger
|
Trigger
|
The trigger to handle. |
required |
A /stop is answered at once instead of being queued, a read-only command such as /status is answered beside the running turn, and a user message that arrives during a model turn goes to the steering inbox.
Raises:
| Type | Description |
|---|---|
ValueError
|
The trigger is addressed to a different desk. |
Source code in src/trading_agent/runtime/desk_runtime.py
command_catalogue
¶
The desk's commands and usable skills, for a client's command menu.
Returns:
| Type | Description |
|---|---|
list[dict[str, str]]
|
The entries, as SlashCommands.catalogue describes them. |
Source code in src/trading_agent/runtime/desk_runtime.py
run
async
¶
Handles triggers one at a time until the task is cancelled.
Source code in src/trading_agent/runtime/desk_runtime.py
roll_over
async
¶
Ends the desk's session with a summary and starts a fresh one, for /rollover.
Returns:
| Type | Description |
|---|---|
str
|
What happened, for the reply. |