Documentation
¶
Index ¶
- Variables
- type Agent
- func (agent *Agent) CompressContext(messagesList []messages.Message) (*CompressionResult, error)
- func (agent *Agent) CompressContextStream(messagesList []messages.Message, callback StreamCallback) (*CompressionResult, error)
- func (agent *Agent) GetConfig() agents.Config
- func (agent *Agent) GetContext() context.Context
- func (agent *Agent) GetKind() agents.Kind
- func (agent *Agent) GetLastRequestJSON() (string, error)
- func (agent *Agent) GetLastRequestRawJSON() string
- func (agent *Agent) GetLastResponseJSON() (string, error)
- func (agent *Agent) GetLastResponseRawJSON() string
- func (agent *Agent) GetModelConfig() models.Config
- func (agent *Agent) GetModelID() string
- func (agent *Agent) GetName() string
- func (agent *Agent) SetCompressionPrompt(prompt string)
- func (agent *Agent) SetConfig(config agents.Config)
- func (agent *Agent) SetContext(ctx context.Context)
- func (agent *Agent) SetModelConfig(config models.Config)
- type AgentOption
- type BaseAgent
- func (agent *BaseAgent) CompressContext(messagesList []openai.ChatCompletionMessageParamUnion) (response string, finishReason string, err error)
- func (agent *BaseAgent) CompressContextStream(messagesList []openai.ChatCompletionMessageParamUnion, ...) (response string, finishReason string, err error)
- func (agent *BaseAgent) SetCompressionPrompt(prompt string)
- type CompressionPrompts
- type CompressionResult
- type CompressorAgentOption
- type StreamCallback
- type SystemInstructions
Constants ¶
This section is empty.
Variables ¶
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]
`,
}
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) GetContext ¶ added in v1.2.2
GetContext returns the agent's context
func (*Agent) GetLastRequestJSON ¶ added in v1.0.2
func (*Agent) GetLastRequestRawJSON ¶ added in v1.1.2
func (*Agent) GetLastResponseJSON ¶ added in v1.0.2
func (*Agent) GetLastResponseRawJSON ¶ added in v1.1.2
func (*Agent) GetModelConfig ¶ added in v1.0.8
GetModelConfig returns the model configuration
func (*Agent) GetModelID ¶ added in v0.0.7
func (*Agent) SetCompressionPrompt ¶
SetCompressionPrompt sets a custom compression prompt for the agent
func (*Agent) SetContext ¶ added in v1.2.2
SetContext updates the agent's context
func (*Agent) SetModelConfig ¶ added in v1.0.8
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 ¶
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 (*BaseAgent) CompressContextStream ¶
func (*BaseAgent) SetCompressionPrompt ¶
type CompressionPrompts ¶
type CompressionResult ¶
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 ¶
StreamCallback is a function called for each chunk of streaming response