Documentation
¶
Index ¶
- type ArrayInfo
- type TruncationResult
- type Truncator
- func (t *Truncator) Limit() int
- func (t *Truncator) ShouldTruncate(content string) bool
- func (t *Truncator) SimpleTruncate(content string) string
- func (t *Truncator) SimpleTruncateBudget() int
- func (t *Truncator) Truncate(content, toolName string, args map[string]interface{}) *TruncationResult
- func (t *Truncator) TruncateWithRecordPath(content, toolName string, args map[string]interface{}, pinnedPath string) *TruncationResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TruncationResult ¶
type TruncationResult struct {
TruncatedContent string `json:"truncated_content"`
CacheKey string `json:"cache_key,omitempty"`
RecordPath string `json:"record_path,omitempty"`
TotalRecords int `json:"total_records,omitempty"`
TotalSize int `json:"total_size"`
CacheAvailable bool `json:"cache_available"`
}
TruncationResult represents the result of truncating a tool response
type Truncator ¶
type Truncator struct {
// contains filtered or unexported fields
}
Truncator handles truncating large tool responses
func NewTruncator ¶
NewTruncator creates a new truncator with the specified character limit
func (*Truncator) Limit ¶ added in v0.68.0
Limit returns the character limit this truncator applies. A nil truncator applies none (0).
func (*Truncator) ShouldTruncate ¶
ShouldTruncate returns true if content should be truncated
func (*Truncator) SimpleTruncate ¶ added in v0.57.0
SimpleTruncate cuts content to the limit and appends the plain "cache not available" notice, minting no pagination handle at all. It is the terminal path for a caller that has nothing left to subdivide: a cache key there would resolve to the same oversize payload, so the honest answer is a bounded response that says pagination is not on offer. Content already inside the limit — and any content when truncation is disabled (limit 0) — is returned untouched.
func (*Truncator) SimpleTruncateBudget ¶ added in v0.51.0
SimpleTruncateBudget returns the number of content bytes the simpleTruncate path actually retains before appending its notice, or 0 when truncation is disabled (limit 0 = unlimited). Spec 084 (T031b): the TOON encoder's too-small-budget guard must match the truncator's REAL retained prefix, not the raw limit — an encoded TOON block is not valid JSON, so Truncate always falls into simpleTruncate for it, which keeps limit - messageSpace bytes (messageSpace = 200, or limit/2 when limit < 200, and the limit itself is a hard ceiling: when the notice cannot fit under it the notice is dropped and a bare limit-sized prefix is kept). This mirrors simpleTruncate exactly; keep the two in sync. When the cut falls inside a multi-byte rune, simpleTruncate backs off to the rune boundary and keeps up to 3 bytes fewer.
func (*Truncator) Truncate ¶
func (t *Truncator) Truncate(content, toolName string, args map[string]interface{}) *TruncationResult
Truncate analyzes and truncates a tool response if it exceeds the limit. The record array the resulting cache handle pages is inferred from the payload; callers that already know which array their truncation banner promises should use TruncateWithRecordPath instead.
func (*Truncator) TruncateWithRecordPath ¶ added in v0.57.0
func (t *Truncator) TruncateWithRecordPath(content, toolName string, args map[string]interface{}, pinnedPath string) *TruncationResult
TruncateWithRecordPath truncates like Truncate but pins the pagination contract to pinnedPath instead of inferring it. Inference prefers whichever array has the most elements, which for a caller-composed payload can be a sibling array (retrieve_tools' Spec 049 "disabled" list) or an array nested inside a record (an input schema's "required"). read_cache would then page records the banner never advertised, and the records it did advertise would be unreachable past the cut.
An empty pinnedPath keeps the inferred behaviour. A pinnedPath that is not an array in content falls back to simple truncation with no cache handle at all, so a banner can never advertise a contract that does not hold.