Documentation
¶
Index ¶
- func CompactHistory(ctx context.Context, cm einomodel.BaseChatModel, history []adk.Message) []adk.Message
- func DrainBgNotifications(bm *tools.BackgroundManager, history []adk.Message) []adk.Message
- func NewAgent(ctx context.Context, chatmodel model.ToolCallingChatModel, ...) (*adk.ChatModelAgent, error)
- func NewBudgetMiddleware(manager *BudgetManager, tokenUsage *internalmodel.TokenUsage, ...) adk.ChatModelAgentMiddleware
- func NewCompactionMiddleware(strategy CompactionStrategy, contextLimit int, ...) adk.ChatModelAgentMiddleware
- func NewReminderMiddleware(cfg ReminderConfig, tokenUsage *internalmodel.TokenUsage) adk.ChatModelAgentMiddleware
- func NewTeammateHandlers(approvalFunc ApprovalFunc) []adk.ChatModelAgentMiddleware
- func SyncSummarization(cap *SummarizationCapture, history []adk.Message, rec *session.Recorder) []adk.Message
- func TruncateStr(s string, maxLen int) string
- type ApprovalFunc
- type BudgetManager
- type BudgetStatus
- type CompactionState
- type CompactionStrategy
- type LocalReductionBackend
- type ReminderConfig
- type SummarizationCapture
- type ThresholdCompactionStrategy
- type WarningLevel
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CompactHistory ¶
func CompactHistory(ctx context.Context, cm einomodel.BaseChatModel, history []adk.Message) []adk.Message
CompactHistory summarizes the conversation history using the model, replacing all messages with a system summary + the last few messages.
func DrainBgNotifications ¶
DrainBgNotifications injects any completed background task results into the conversation history so the agent is aware of them on the next turn.
func NewAgent ¶
func NewAgent( ctx context.Context, chatmodel model.ToolCallingChatModel, tools []tool.BaseTool, instruction string, approvalFunc ApprovalFunc, middlewares []adk.AgentMiddleware, handlers []adk.ChatModelAgentMiddleware, ) (*adk.ChatModelAgent, error)
NewAgent creates a ChatModelAgent with the following middleware stack (outermost to innermost):
Middlewares (old-style): [langfuse] Handlers (new-style): [...caller handlers, approval+safeTool]
ModelRetryConfig is always enabled (3 retries with default exponential backoff).
func NewBudgetMiddleware ¶
func NewBudgetMiddleware(manager *BudgetManager, tokenUsage *internalmodel.TokenUsage, onWarn func(BudgetStatus)) adk.ChatModelAgentMiddleware
NewBudgetMiddleware creates a ChatModelAgentMiddleware that tracks budget. tokenUsage is the per-agent tracker to read from. onWarn is called when the budget warning level changes to WarningApproach or WarningExceeded. It may be nil.
func NewCompactionMiddleware ¶
func NewCompactionMiddleware(strategy CompactionStrategy, contextLimit int, tokenUsage *internalmodel.TokenUsage, onCompact func(int)) adk.ChatModelAgentMiddleware
NewCompactionMiddleware creates a ChatModelAgentMiddleware that monitors token usage and compacts the conversation when the strategy says to. tokenUsage is the per-agent tracker to read from. onCompact is an optional callback invoked after a successful compaction.
func NewReminderMiddleware ¶
func NewReminderMiddleware(cfg ReminderConfig, tokenUsage *internalmodel.TokenUsage) adk.ChatModelAgentMiddleware
NewReminderMiddleware creates a ChatModelAgentMiddleware that injects conditional reminders (todo check, token warning, error streak) into the message stream before each model invocation. tokenUsage is the per-agent tracker to read from; may be nil.
func NewTeammateHandlers ¶
func NewTeammateHandlers(approvalFunc ApprovalFunc) []adk.ChatModelAgentMiddleware
NewTeammateHandlers returns the middleware stack for a teammate agent. It includes the approval + safe-tool-error middleware with the given approval function.
func SyncSummarization ¶
func SyncSummarization(cap *SummarizationCapture, history []adk.Message, rec *session.Recorder) []adk.Message
SyncSummarization checks whether Eino's summarization middleware fired during the last runner.Run() and, if so, replaces history with the compacted version so the next turn starts from the summarized state.
func TruncateStr ¶
TruncateStr truncates a string to maxLen characters, appending "..." if truncated.
Types ¶
type ApprovalFunc ¶
type BudgetManager ¶
type BudgetManager struct {
// contains filtered or unexported fields
}
BudgetManager tracks token consumption and cost against configurable limits.
func NewBudgetManager ¶
func NewBudgetManager(cfg *config.BudgetConfig, pricing internalmodel.ModelPricing) *BudgetManager
NewBudgetManager creates a BudgetManager from config and model pricing. A nil BudgetConfig results in a manager with no limits.
func (*BudgetManager) Check ¶
func (b *BudgetManager) Check() (BudgetStatus, bool)
Check returns the current budget status and whether the budget has been exceeded.
func (*BudgetManager) Status ¶
func (b *BudgetManager) Status() BudgetStatus
Status returns the current budget status without modifying state.
func (*BudgetManager) Track ¶
func (b *BudgetManager) Track(promptTokens, completionTokens int64) BudgetStatus
Track records a model call's token usage and returns the updated status.
type BudgetStatus ¶
type BudgetStatus struct {
PromptTokens int64
CompletionTokens int64
TotalTokens int64
EstimatedCost float64
RemainingBudget float64
WarningLevel WarningLevel
}
BudgetStatus is a snapshot of current token/cost usage.
type CompactionState ¶
type CompactionState struct {
// contains filtered or unexported fields
}
CompactionState tracks compaction history for diagnostics.
func (*CompactionState) CompactionCount ¶
func (cs *CompactionState) CompactionCount() int
CompactionCount returns how many compactions have occurred.
func (*CompactionState) SavedTokens ¶
func (cs *CompactionState) SavedTokens() int
SavedTokens returns the total estimated tokens saved by compaction.
type CompactionStrategy ¶
type CompactionStrategy interface {
// ShouldCompact returns true when the current token count warrants compaction.
ShouldCompact(currentTokens, limit int) bool
// Compact compresses the messages slice, keeping the most recent keepRecent
// messages intact and summarising the rest.
Compact(ctx context.Context, messages []*schema.Message, keepRecent int) ([]*schema.Message, error)
}
CompactionStrategy decides when and how to compact conversation history.
type LocalReductionBackend ¶
type LocalReductionBackend struct {
RootDir string
}
LocalReductionBackend implements reduction.Backend by writing truncated tool output to local files so the agent can re-read them via the read tool.
func (*LocalReductionBackend) Write ¶
func (b *LocalReductionBackend) Write(_ context.Context, req *filesystem.WriteRequest) error
type ReminderConfig ¶
type ReminderConfig struct {
TodoStore *tools.TodoStore
GoalStore *tools.GoalStore
PlanStore *tools.PlanStore
EnvLabel string
IsRemote bool
ContextLimit int
TaskManager *tools.SubagentTaskManager
}
ReminderConfig holds the static configuration for the reminder middleware.
type SummarizationCapture ¶
type SummarizationCapture struct {
// contains filtered or unexported fields
}
SummarizationCapture captures the result when Eino's summarization middleware fires, so that the application-level history can be synced afterwards.
func (*SummarizationCapture) Capture ¶
func (c *SummarizationCapture) Capture(summary string, compactedN int)
Capture records a summarization event. Called from the Finalize callback.
type ThresholdCompactionStrategy ¶
type ThresholdCompactionStrategy struct {
// contains filtered or unexported fields
}
ThresholdCompactionStrategy triggers compaction when token usage exceeds a configurable fraction of the context limit and uses a chat model to generate a summary of older messages.
func NewThresholdCompactionStrategy ¶
func NewThresholdCompactionStrategy(threshold float64, summarizer einomodel.ToolCallingChatModel, keepRecent int) *ThresholdCompactionStrategy
NewThresholdCompactionStrategy creates a compaction strategy. threshold is the fraction (0-1) of the context limit that triggers compaction. summarizer is the model used to generate summaries. keepRecent is the number of recent messages to preserve verbatim.
func (*ThresholdCompactionStrategy) ShouldCompact ¶
func (s *ThresholdCompactionStrategy) ShouldCompact(currentTokens, limit int) bool
type WarningLevel ¶
type WarningLevel int
WarningLevel indicates the severity of a budget warning.
const ( WarningNone WarningLevel = iota WarningApproach // approaching budget limit WarningExceeded // budget limit exceeded )