Documentation
¶
Overview ¶
budget.go: session-level quota for tokens, tool calls, and time.
loopdetect.go: loop detection for repeated/similar actions.
permission.go: permission evaluation (allow/deny/ask) for tools and operations.
ratelimit.go: token-bucket rate limiting for request throttling.
Index ¶
- Constants
- type Budget
- type BudgetConfig
- type BudgetRequest
- type BudgetResult
- type BudgetState
- type Cost
- type LoopDetectAction
- type LoopDetectConfig
- type LoopDetectResult
- type LoopDetectStats
- type LoopDetector
- type PermAction
- type PermEvaluator
- type PermRule
- type PermRuleset
- type RateLimitStats
- type RateLimiter
Constants ¶
View Source
const ( LoopDetectWindowSize = 10 LoopDetectMaxRepeats = 5 )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Budget ¶
type Budget interface {
Check(ctx context.Context, req BudgetRequest) (BudgetResult, error)
Consume(ctx context.Context, sessionID string, amount Cost) error
GetState(sessionID string) BudgetState
Reset(sessionID string)
ResetAll()
RecordToolCall(ctx context.Context, sessionID string)
RecordTokens(ctx context.Context, sessionID string, tokens int)
CanExecute(sessionID string) bool
}
func NewBudget ¶
func NewBudget(cfg *BudgetConfig) Budget
type BudgetConfig ¶
type BudgetRequest ¶
type BudgetResult ¶
type BudgetState ¶
type LoopDetectAction ¶
type LoopDetectConfig ¶
func DefaultLoopDetectConfig ¶
func DefaultLoopDetectConfig() *LoopDetectConfig
type LoopDetectResult ¶
type LoopDetectStats ¶
type LoopDetector ¶
type LoopDetector interface {
Detect(ctx context.Context, sessionID string, action LoopDetectAction) *LoopDetectResult
Record(sessionID string, action LoopDetectAction)
Reset(sessionID string)
GetStats(sessionID string) LoopDetectStats
}
func NewLoopDetector ¶
func NewLoopDetector(cfg *LoopDetectConfig) LoopDetector
type PermAction ¶
type PermAction string
const ( PermActionAllow PermAction = "allow" PermActionDeny PermAction = "deny" PermActionAsk PermAction = "ask" )
type PermEvaluator ¶
type PermEvaluator struct {
Ruleset PermRuleset
// contains filtered or unexported fields
}
func NewPermEvaluator ¶
func NewPermEvaluator(ruleset PermRuleset) *PermEvaluator
func (*PermEvaluator) Evaluate ¶
func (e *PermEvaluator) Evaluate(permission string, input map[string]interface{}) PermAction
func (*PermEvaluator) Merge ¶
func (e *PermEvaluator) Merge(other PermRuleset)
type PermRule ¶
type PermRule struct {
Permission string `json:"permission"`
Action PermAction `json:"action"`
Pattern string `json:"pattern,omitempty"`
Extra map[string]interface{} `json:"extra,omitempty"`
}
func PermEvaluate ¶
func PermEvaluate(permission string, name string, ruleset PermRuleset) PermRule
type PermRuleset ¶
type PermRuleset []PermRule
func PermFromAllowDenyAsk ¶
func PermFromAllowDenyAsk(denied, ask, allowed []string) PermRuleset
func PermFromConfig ¶
func PermFromConfig(config map[string]interface{}) PermRuleset
func PermMerge ¶
func PermMerge(rulesets ...PermRuleset) PermRuleset
type RateLimitStats ¶
type RateLimiter ¶
type RateLimiter interface {
Allow(ctx context.Context) error
Wait(ctx context.Context) error
Stats() RateLimitStats
}
func NewTokenBucket ¶
func NewTokenBucket(capacity int64, refillRate int64) RateLimiter
Click to show internal directories.
Click to hide internal directories.