Documentation
¶
Overview ¶
Package smart_compact provides smart context compression for Anthropic requests.
The transformer removes thinking fields from non-current conversation rounds. MVP focuses on Anthropic v1 and v1beta APIs.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CompactTransformer ¶
type CompactTransformer struct {
protocol.Transformer
KeepLastNRounds int // Number of recent rounds to preserve thinking blocks (min: 1)
// contains filtered or unexported fields
}
CompactTransformer implements the Transformer interface.
func NewCompactTransformer ¶
func NewCompactTransformer(keepLastNRounds int) *CompactTransformer
NewCompactTransformer creates a new smart_compact transformer instance.
The keepLastNRounds parameter controls how many recent conversation rounds should have their thinking blocks preserved. Higher values retain more reasoning context but save fewer tokens.
Recommendations:
- keepLastNRounds=1: Default, preserves only the current request's thinking
- keepLastNRounds=2-3: Suitable for multi-step reasoning, debugging, or document analysis
- Minimum allowed value is 1 (current round's thinking is always preserved)
func (*CompactTransformer) HandleV1 ¶
func (t *CompactTransformer) HandleV1(req *anthropic.MessageNewParams) error
HandleV1 compacts an Anthropic v1 request by removing thinking fields from non-current rounds.
func (*CompactTransformer) HandleV1Beta ¶
func (t *CompactTransformer) HandleV1Beta(req *anthropic.BetaMessageNewParams) error
HandleV1Beta compacts an Anthropic v1beta request by removing thinking fields from non-current rounds.