Skip to content

trading_agent.tools.ask_user_tool

The ask_user tool: puts one to four multiple-choice questions to the user, as Claude Code's question card does.

The desk does not wait. The questions are saved and shown in the web chat and on Telegram, and the user's answers arrive later as a new message.

Typical usage example:

tool = AskUserTool(store, event_bus, 'main')

QuestionOption

Bases: BaseModel

One choice in a question.

Attributes:

Name Type Description
label str

The short text on the choice, one to five words.

description str

What choosing it means, or its trade-offs.

preview str | None

Optional Markdown shown beside the choices when this one is highlighted, such as a table of levels or an order ticket.

Question

Bases: BaseModel

One question with its choices.

Attributes:

Name Type Description
question str

The full question, ending with a question mark.

header str

A tag of at most 12 characters naming the topic, such as "Stop loss".

options list[QuestionOption]

Two to four choices; an "Other" box for a free answer is added automatically.

multi_select bool

True when more than one choice may be picked.

AskUserArguments

Bases: BaseModel

The arguments of ask_user.

Attributes:

Name Type Description
questions list[Question]

One to four questions, shown together.

AskUserTool

AskUserTool(store, event_bus, desk_name)

Bases: Tool

Saves and shows the desk's questions to the user.

Creates the tool.

Parameters:

Name Type Description Default
store UserRequestStore

Where the request is saved.

required
event_bus EventBus

Where it is published for the web page and Telegram.

required
desk_name str

The desk asking.

required
Source code in src/trading_agent/tools/ask_user_tool.py
def __init__(
    self,
    store: user_request_store_module.UserRequestStore,
    event_bus: event_bus_module.EventBus,
    desk_name: str,
):
    """Creates the tool.

    Args:
        store (user_request_store_module.UserRequestStore): Where the request is saved.
        event_bus (event_bus_module.EventBus): Where it is published for the web page and Telegram.
        desk_name (str): The desk asking.
    """
    self._store = store
    self._event_bus = event_bus
    self._desk_name = desk_name

run async

run(arguments)

Saves the questions and publishes them.

Parameters:

Name Type Description Default
arguments AskUserArguments

The questions.

required

Returns:

Type Description
ToolResult

The request's identifier and what happens next.

Source code in src/trading_agent/tools/ask_user_tool.py
async def run(self, arguments: AskUserArguments) -> tool.ToolResult:
    """Saves the questions and publishes them.

    Args:
        arguments (AskUserArguments): The questions.

    Returns:
        tool.ToolResult: The request's identifier and what happens next.
    """
    request = user_request_module.UserRequest.new(
        self._desk_name,
        user_request_module.QUESTION,
        arguments.model_dump(),
    )
    self._store.save(request)
    self._event_bus.publish(
        event_module.Event.now(
            event_module.EventKind.USER_REQUEST,
            self._desk_name,
            request.to_json_dictionary(),
        )
    )
    return tool.ToolResult.success(
        f'The question was sent to the user as request {request.request_id}. Do not wait for it: end this turn. The answer will arrive as a new message naming the request.'
    )