trader.chat.prompt module

Building the chat prompts, and parsing what comes back.

Same two rules trader.llm.prompt states for the trading decision prompt, applied to a conversational one:

Everything that can go wrong becomes a safe, honest string. A missing response key, a non-string value, an empty reply — none of them raise, and none of them invent an answer. A misbehaving model must never be presented to the operator as a confident answer it did not actually give.

The model is only ever shown data this process already fetched and verified against the database. Every builder here takes pre-rendered context text, never a repository or a session — the same separation trader.llm.prompt.build_messages keeps between “what the model saw” and how it was fetched, so what reaches the model is exactly what a human reading inputs_json for a trading decision would also see.

trader.chat.prompt.build_chat_messages(message, context)[source]

(system, user) for a general Q&A / positions / trades / performance turn.

Parameters:
  • message (str)

  • context (str)

Return type:

tuple[str, str]

trader.chat.prompt.build_explain_decision_messages(message, decision_text)[source]

(system, user) for explaining one recorded decision.

Parameters:
  • message (str)

  • decision_text (str)

Return type:

tuple[str, str]

trader.chat.prompt.build_strategy_review_messages(message, strategies_yaml)[source]

(system, user) for reviewing config/strategies.yaml.

Parameters:
  • message (str)

  • strategies_yaml (str)

Return type:

tuple[str, str]

trader.chat.prompt.parse_chat_response(payload)[source]

Turn a model reply into plain text. Never raises.

Same discipline as trader.llm.prompt.parse_decision: an unusable response degrades to a safe, honest string rather than raising past this boundary or presenting garbage as an answer.

Parameters:

payload (dict[str, object])

Return type:

str