trader.chat.intent module

Turning a chat message into what to look up before answering it.

Deterministic keyword/regex classification — never a model call. The hard rule that a conversational backtest trigger must never route to LlmStrategy (backtestable = False) has to hold structurally, and a rule engine is exhaustively testable in the way an LLM classification would not be. This module only decides what data to fetch; ChatService still asks the model to compose the natural-language answer once that data is in hand, the same two-step shape LlmStrategy uses (build inputs, then ask).

A simple heuristic, not NLU: classify() never raises, an unrecognised message always falls back to Intent.GENERAL, and every extracted field is optional — a caller that gets None back asks the user to be more specific rather than guessing.

class trader.chat.intent.Intent(*values)[source]

Bases: Enum

What kind of chat turn this is, and therefore what to fetch.

GENERAL = 'general'
EXPLAIN_DECISION = 'explain_decision'
BACKTEST = 'backtest'
STRATEGY_REVIEW = 'strategy_review'
class trader.chat.intent.ParsedIntent(intent, raw_message, symbol=None, decision_id=None, on_date=None, strategy_id=None, ticker=None, start=None, end=None)[source]

Bases: object

What classify() extracted from one message. Every field but the first two is intent-specific and may be None when the message did not say.

Parameters:
  • intent (Intent)

  • raw_message (str)

  • symbol (str | None)

  • decision_id (int | None)

  • on_date (date | None)

  • strategy_id (str | None)

  • ticker (str | None)

  • start (date | None)

  • end (date | None)

intent: Intent
raw_message: str
symbol: str | None

EXPLAIN_DECISION only.

decision_id: int | None
on_date: date | None
strategy_id: str | None

BACKTEST (strategy_id also used to focus STRATEGY_REVIEW).

ticker: str | None
start: date | None
end: date | None
trader.chat.intent.classify(message, *, strategy_ids=())[source]

Route one chat message. Never raises.

strategy_ids is the configured strategies’ ids (config/strategies.yaml), used only to recognise one by name inside a BACKTEST or STRATEGY_REVIEW message — it never changes which Intent a message is classified as.

Parameters:
  • message (str)

  • strategy_ids (Sequence[str])

Return type:

ParsedIntent