trader.llm.base module

The LLM interface the Core depends on.

A Protocol for the same reason BrokerAdapter is one: the Core holds no HTTP client, tests need no server, and a second provider is an addition rather than a rewrite.

Anthropic is a deferred future feature, not a planned step — see docs/ideas.md for the trigger conditions. This Protocol exists so that decision stays cheap to revisit, not because a second provider is scheduled.

exception trader.llm.base.LlmError[source]

Bases: TraderError

The language model call failed or returned something unusable.

Derives from TraderError so the pipeline’s per-symbol handler treats a model failure the way it treats a market-data failure: abort that symbol, record why, continue the cycle.

class trader.llm.base.LlmProvider(*args, **kwargs)[source]

Bases: Protocol

A model that returns structured JSON.

model: str
generate_json(system, user, schema)[source]

Return parsed JSON conforming to schema. Raises LlmError.

Parameters:
  • system (str)

  • user (str)

  • schema (dict[str, object])

Return type:

dict[str, object]

health()[source]

Return the reachable model’s name. Raises LlmError if not.

Return type:

str