[Context](../core/base#class-context) implementations for common conversation patterns.
Provides ChatContext, which accumulates all turns in a sliding-window chat history
(configurable via window_size), and SimpleContext, in which each interaction
is treated as a stateless single-turn exchange (no prior history is passed to the
model). Import ChatContext for multi-turn conversations and SimpleContext when
you want each call to the model to be independent.
Classes
CLASS ChatContext
Initializes a chat context with unbounded window_size and is_chat=True by default.
Args:
window_size: Maximum number of context turns to include when callingview_for_generation.None(the default) means the full history is always returned.
FUNC add
c: The component or content block to append.
- A new
ChatContextwith the added entry, preserving the - current
window_sizesetting.
FUNC view_for_generation
window_size set during initialisation to limit how many past
turns are included. None is returned when the underlying history is
non-linear.
Returns:
- list[Component | CBlock] | None: Ordered list of context entries up to
window_sizeturns, orNoneif the history is non-linear.
CLASS SimpleContext
A SimpleContext is a context in which each interaction is a separate and independent turn. The history of all previous turns is NOT saved..
Methods:
FUNC add
c: The component or content block to record.
- A new
SimpleContextcontaining only the added entry; - prior history is not retained.
FUNC view_for_generation
SimpleContext does not pass history to the model.
Each call to the model is treated as a stateless, independent exchange.
No prior turns are forwarded.
Returns:
- list[Component | CBlock] | None: Always an empty list.