compressor

package
v1.3.9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 20, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Instructions = SystemInstructions{
	Minimalist: `You are a context compression assistant. Your task is to summarize conversations concisely, preserving key facts, decisions, and context needed for continuation.`,
	Expert: `
	You are a context compression specialist. Your task is to analyze the conversation history and compress it while preserving all essential information.

	## Instructions:
	1. **Preserve Critical Information**: Keep all important facts, decisions, code snippets, file paths, function names, and technical details
	2. **Remove Redundancy**: Eliminate repetitive discussions, failed attempts, and conversational fluff
	3. **Maintain Chronology**: Keep the logical flow and order of important events
	4. **Summarize Discussions**: Convert long discussions into concise summaries with key takeaways
	5. **Keep Context**: Ensure the compressed version provides enough context for continuing the conversation

	## Output Format:
	Return a compressed version of the conversation that:
	- Uses clear, concise language
	- Groups related topics together
	- Highlights key decisions and outcomes
	- Preserves technical accuracy
	- Maintains references to files, functions, and code

	## Compression Guidelines:
	- Remove: Greetings, acknowledgments, verbose explanations, failed attempts
	- Keep: Facts, code, decisions, file paths, function signatures, error messages, requirements
	- Summarize: Long discussions into bullet points with essential information
	`,
	Effective: `You are an expert at summarizing and compressing conversations.
	Your role is to create concise summaries that preserve:
	- Key information and important facts
	- Decisions made
	- User preferences
	- Emotional context if relevant
	- Ongoing or pending actions

	Output format:
	## Conversation Summary
	[Concise summary of exchanges]

	## Key Points
	- [Point 1]
	- [Point 2]

	## To Remember
	[Important information for continuity]
	`,
}
View Source
var Prompts = CompressionPrompts{

	Minimalist: `Summarize the conversation history concisely, preserving key facts, decisions, and context needed for continuation.`,
	Structured: `Compress this conversation into a brief summary including:
		- Main topics discussed
		- Key decisions/conclusions
		- Important context for next exchanges
		Keep it under 200 words.
	`,
	UltraShort:      `Summarize this conversation: extract key facts, decisions, and essential context only.`,
	ContinuityFocus: `Create a compact summary of this conversation that preserves all information needed to continue the discussion naturally.`,
}

Functions

This section is empty.

Types

type Agent

type Agent struct {
	// contains filtered or unexported fields
}

Agent represents a simplified compressor agent that hides OpenAI SDK details

func NewAgent

func NewAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig models.Config,
	options ...any,
) (*Agent, error)

NewAgent creates a new simplified compressor agent

func (*Agent) CompressContext

func (agent *Agent) CompressContext(messagesList []messages.Message) (*CompressionResult, error)

CompressMessages compresses a list of messages and returns the compressed result

func (*Agent) CompressContextStream

func (agent *Agent) CompressContextStream(
	messagesList []messages.Message,
	callback StreamCallback,
) (*CompressionResult, error)

CompressMessagesStream compresses a list of messages and streams the result via callback

func (*Agent) GetConfig added in v1.0.8

func (agent *Agent) GetConfig() agents.Config

GetConfig returns the agent configuration

func (*Agent) GetContext added in v1.2.2

func (agent *Agent) GetContext() context.Context

GetContext returns the agent's context

func (*Agent) GetKind added in v0.0.3

func (agent *Agent) GetKind() agents.Kind

func (*Agent) GetLastRequestJSON added in v1.0.2

func (agent *Agent) GetLastRequestJSON() (string, error)

func (*Agent) GetLastRequestRawJSON added in v1.1.2

func (agent *Agent) GetLastRequestRawJSON() string

func (*Agent) GetLastResponseJSON added in v1.0.2

func (agent *Agent) GetLastResponseJSON() (string, error)

func (*Agent) GetLastResponseRawJSON added in v1.1.2

func (agent *Agent) GetLastResponseRawJSON() string

func (*Agent) GetModelConfig added in v1.0.8

func (agent *Agent) GetModelConfig() models.Config

GetModelConfig returns the model configuration

func (*Agent) GetModelID added in v0.0.7

func (agent *Agent) GetModelID() string

func (*Agent) GetName added in v0.0.3

func (agent *Agent) GetName() string

func (*Agent) SetCompressionPrompt

func (agent *Agent) SetCompressionPrompt(prompt string)

SetCompressionPrompt sets a custom compression prompt for the agent

func (*Agent) SetConfig added in v1.0.8

func (agent *Agent) SetConfig(config agents.Config)

SetConfig updates the agent configuration

func (*Agent) SetContext added in v1.2.2

func (agent *Agent) SetContext(ctx context.Context)

SetContext updates the agent's context

func (*Agent) SetModelConfig added in v1.0.8

func (agent *Agent) SetModelConfig(config models.Config)

SetModelConfig updates the model configuration Note: This updates the stored config but doesn't regenerate the internal OpenAI params For most parameters to take effect, create a new agent with the new config

type AgentOption

type AgentOption func(*BaseAgent)

func WithCompressionPrompt

func WithCompressionPrompt(prompt string) AgentOption

WithCompressionPrompt sets a custom compression prompt for the agent

type BaseAgent

type BaseAgent struct {
	*base.Agent
	// contains filtered or unexported fields
}

BaseAgent wraps the shared base.Agent and adds compression-specific functionality

func NewBaseAgent

func NewBaseAgent(
	ctx context.Context,
	agentConfig agents.Config,
	modelConfig openai.ChatCompletionNewParams,
	options ...AgentOption,
) (compressorAgent *BaseAgent, err error)

NewBaseAgent creates a new CompressorAgent instance using the shared base agent

func (*BaseAgent) CompressContext

func (agent *BaseAgent) CompressContext(messagesList []openai.ChatCompletionMessageParamUnion) (response string, finishReason string, err error)

func (*BaseAgent) CompressContextStream

func (agent *BaseAgent) CompressContextStream(
	messagesList []openai.ChatCompletionMessageParamUnion,
	callBack func(partialResponse string, finishReason string) error) (response string, finishReason string, err error)

func (*BaseAgent) SetCompressionPrompt

func (agent *BaseAgent) SetCompressionPrompt(prompt string)

type CompressionPrompts

type CompressionPrompts struct {
	Minimalist      string
	Structured      string
	UltraShort      string
	ContinuityFocus string
}

type CompressionResult

type CompressionResult struct {
	CompressedText string
	FinishReason   string
}

CompressionResult represents the result of a context compression

type CompressorAgentOption added in v1.2.9

type CompressorAgentOption func(*Agent)

CompressorAgentOption is a functional option for configuring an Agent during creation

func AfterCompletion added in v1.2.9

func AfterCompletion(fn func(*Agent)) CompressorAgentOption

AfterCompletion sets a hook that is called after each compression (standard and streaming)

func BeforeCompletion added in v1.2.9

func BeforeCompletion(fn func(*Agent)) CompressorAgentOption

BeforeCompletion sets a hook that is called before each compression (standard and streaming)

type StreamCallback

type StreamCallback func(chunk string, finishReason string) error

StreamCallback is a function called for each chunk of streaming response

type SystemInstructions

type SystemInstructions struct {
	Minimalist string
	Expert     string
	Effective  string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL