Docs /Templates/ sinapsis-chat-history

ChatHistoryTrim

sinapsis-chat-historyChat Historychatbotschat_historycontext

Python template · sinapsis_chat_history.templates.chat_history_trim

Overview

Template to trim fetched chat history to fit a target prompt budget.

Capabilities

Capabilities: not set

Installation

Install the published package using pip or uv.

Terminalbash
pip install sinapsis-chat-history==1.0.0
uv pip install sinapsis-chat-history==1.0.0
uv add sinapsis-chat-history==1.0.0

Configuration

Effective fields from the inspector schema, including nested Pydantic model fields.

metadata
sinapsis_core.template_base.base_models.TemplateMetadata | None
Optional
Default: null
model_max_contextRequired

Maximum input-plus-output context length supported by the target model.

int
Required
Default: null
safety_margin_tokens

Extra token buffer reserved to absorb formatting and tokenizer-estimation mismatches.

int
Optional
Default: 256
tokenizer_model_nameRequired

Hugging Face tokenizer name or path used for prompt-size estimation.

str
Required
Default: null
reserved_output_tokens

Tokens reserved for model generation.

int
Optional
Default: 1024
preserve_system_messages

Whether history messages with `system` or `developer` roles should be retained whenever possible.

bool
Optional
Default: true

Configuration example

Example from the Python docstring:

yaml
agent:
  name: my_test_agent
templates:
- template_name: InputTemplate
  class_name: InputTemplate
  attributes: {}
- template_name: ChatHistoryTrim
  class_name: ChatHistoryTrim
  template_input: InputTemplate
  attributes:
    tokenizer_model_name: 'Qwen/Qwen3.5-9B'
    model_max_context: 8192
    reserved_output_tokens: 2048
Show schema-based configuration skeleton
yaml
templates:
  - template_name: "ChatHistoryTrim"
    class_name: "ChatHistoryTrim"
    attributes:
      model_max_context: "<required>"
      safety_margin_tokens: 256
      tokenizer_model_name: "<required>"
      reserved_output_tokens: 1024
      preserve_system_messages: true

Inheritance

Immediate parent: sinapsis_core.template_base.template.Template

Environment variables

Environment definitions belong to their canonical Python modules.

No directly related environment variables listed.