Documentation
¶
Index ¶
- Constants
- func EffectiveTemperatureForModel(model string, requested *float64, baseURL string) (*float64, error)
- func Main(ctx context.Context, args []string) int
- func NewCommand() *cobra.Command
- func Run(ctx context.Context, o Options) error
- type AggregateMetrics
- type CompressionConfig
- type Compressor
- func (c *Compressor) CompressTrajectoryAsync(ctx context.Context, trajectory any) (any, *TrajectoryMetrics, error)
- func (c *Compressor) CountTokens(text any) (int, error)
- func (c *Compressor) CountTrajectoryTokens(traj []any) (int, error)
- func (c *Compressor) CountTurnTokens(traj []any) ([]int, error)
- func (c *Compressor) ProcessDirectory(ctx context.Context, inputDir, outputDir string) error
- func (c *Compressor) ProcessEntry(ctx context.Context, entry any) (any, *TrajectoryMetrics, error)
- type Encoder
- type Options
- type TrajectoryMetrics
Constants ¶
const OpenRouterBaseURL = "https://openrouter.ai/api/v1"
OpenRouterBaseURL is the default summarization endpoint
Variables ¶
This section is empty.
Functions ¶
func EffectiveTemperatureForModel ¶
func EffectiveTemperatureForModel(model string, requested *float64, baseURL string) (*float64, error)
Temperature a direct call sends, nil when the model manages temperature itself and the call must omit it
func Main ¶
Process entry of the compressor binary, the .env files loaded first and an error line on failure
func NewCommand ¶
Command line of the compressor with fire style flags and positional arguments bound in parameter order
Types ¶
type AggregateMetrics ¶
type AggregateMetrics struct {
TotalTrajectories int
TrajectoriesCompressed int
TrajectoriesSkippedUnderTarget int
TrajectoriesStillOverLimit int
TrajectoriesFailed int
TotalTokensBefore int
TotalTokensAfter int
TotalTokensSaved int
TotalTurnsBefore int
TotalTurnsAfter int
TotalTurnsRemoved int
TotalSummarizationCalls int
TotalSummarizationErrors int
CompressionRatios []float64
TokensSavedList []int
TurnsRemovedList []int
ProcessingStartTime string
ProcessingEndTime string
ProcessingDurationSeconds float64
}
AggregateMetrics are the totals across every trajectory of a run
func (*AggregateMetrics) AddTrajectoryMetrics ¶
func (a *AggregateMetrics) AddTrajectoryMetrics(m *TrajectoryMetrics)
Adds one trajectory's metrics to the totals
func (*AggregateMetrics) ToDict ¶
func (a *AggregateMetrics) ToDict() *jsonutil.Object
Ordered dict of summary, tokens, turns, averages, summarization and processing sections
type CompressionConfig ¶
type CompressionConfig struct {
TokenizerName string
TargetMaxTokens int
SummaryTargetTokens int
ProtectFirstSystem bool
ProtectFirstHuman bool
ProtectFirstGPT bool
ProtectFirstTool bool
ProtectLastNTurns int
SummarizationModel string
BaseURL string
APIKeyEnv string
Temperature float64
MaxRetries int
RetryDelay float64
AddSummaryNotice bool
SummaryNoticeText string
OutputSuffix string
NumWorkers int
MaxConcurrentRequests int
SkipUnderTarget bool
SaveOverLimit bool
PerTrajectoryTimeout int
MetricsEnabled bool
MetricsPerTrajectory bool
MetricsOutputFile string
}
CompressionConfig holds tokenizer, targets, protected turns, summarizer, output, processing and metrics settings
func ConfigFromYAML ¶
func ConfigFromYAML(path string) (*CompressionConfig, error)
Loads a YAML config file, missing sections and keys keeping the defaults and a null base_url keeping its default
func DefaultConfig ¶
func DefaultConfig() *CompressionConfig
Configuration with the dataclass defaults
type Compressor ¶
type Compressor struct {
Config *CompressionConfig
Aggregate *AggregateMetrics
// contains filtered or unexported fields
}
Compressor fits agent trajectories into a token budget by summarizing part of the middle
func NewCompressor ¶
func NewCompressor(ctx context.Context, cfg *CompressionConfig) (*Compressor, error)
Compressor with its tokenizer loaded and summarizer route resolved
func (*Compressor) CompressTrajectoryAsync ¶
func (c *Compressor) CompressTrajectoryAsync(ctx context.Context, trajectory any) (any, *TrajectoryMetrics, error)
Compresses one trajectory into the target budget through the async call_llm surface
func (*Compressor) CountTokens ¶
func (c *Compressor) CountTokens(text any) (int, error)
Token count of a turn value, zero when empty, a quarter of its length when it is not encodable text
func (*Compressor) CountTrajectoryTokens ¶
func (c *Compressor) CountTrajectoryTokens(traj []any) (int, error)
Total tokens of a trajectory
func (*Compressor) CountTurnTokens ¶
func (c *Compressor) CountTurnTokens(traj []any) ([]int, error)
Token counts of every turn value in order
func (*Compressor) ProcessDirectory ¶
func (c *Compressor) ProcessDirectory(ctx context.Context, inputDir, outputDir string) error
Compresses every *.jsonl of inputDir into outputDir with concurrent summary calls, then reports and saves metrics
func (*Compressor) ProcessEntry ¶
func (c *Compressor) ProcessEntry(ctx context.Context, entry any) (any, *TrajectoryMetrics, error)
Compresses the conversations of one JSONL entry, attaching per trajectory metrics when it was compressed
type Encoder ¶
type Encoder = tokenizers.Encoder
Encoder gives the token ids of a text
func LoadTokenizer ¶
LoadTokenizer loads the tokenizer of a local folder or a hub model from the tokenizer files it ships
type Options ¶
type Options struct {
Input string
Output string
Config string
TargetMaxTokens int
Tokenizer string
// Percentage of the trajectories to sample before compressing, nil to compress all of them
SamplePercent *float64
Seed int64
DryRun bool
}
Options are the arguments of the trajectory compressor command
type TrajectoryMetrics ¶
type TrajectoryMetrics struct {
OriginalTokens int
CompressedTokens int
TokensSaved int
CompressionRatio float64
OriginalTurns int
CompressedTurns int
TurnsRemoved int
TurnsCompressedStartIdx int
TurnsCompressedEndIdx int
TurnsInCompressedRegion int
WasCompressed bool
StillOverLimit bool
SkippedUnderTarget bool
SummarizationAPICalls int
SummarizationErrors int
}
TrajectoryMetrics are the counts of one trajectory compression
func NewTrajectoryMetrics ¶
func NewTrajectoryMetrics() *TrajectoryMetrics
Metrics with the dataclass defaults
func (*TrajectoryMetrics) ToDict ¶
func (m *TrajectoryMetrics) ToDict() *jsonutil.Object
Ordered dict of the metrics with the compression region nested after turns_removed