compact: retain newest ~20% of context; refactor startup into internal/app
- Replace fixed 6-message compact retention with ratio-based logic: retain ~20% of compactable estimated tokens, with a 6-message floor and user-turn boundary alignment - Add compactRetainedTokenBudget, compactRecentStart, compactTurnBoundary helpers in internal/agent/agent.go - Add TestAgentCompactKeepsTwentyPercentRecentContext - Move startup/session/repl/bootstrap logic from root into internal/app so main.go is a thin binary entry point (15 lines) - Update /compact docs in README.md
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"agentu/pkg/config"
|
||||
)
|
||||
|
||||
const defaultConfigContent = `# agentu configuration
|
||||
# Replace the placeholder values below with your actual provider settings.
|
||||
# See agentu.example.yaml for the full reference.
|
||||
providers:
|
||||
default:
|
||||
base_url: https://api.openai.com
|
||||
api_key: YOUR_API_KEY_HERE
|
||||
models:
|
||||
- id: gpt-4o
|
||||
context: 128000
|
||||
- id: gpt-4o-mini
|
||||
context: 128000
|
||||
`
|
||||
|
||||
func bootstrapConfig(configPath string) error {
|
||||
resolved, err := config.ResolvePath(configPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("resolve config path: %w", err)
|
||||
}
|
||||
dir := filepath.Dir(resolved)
|
||||
if err := os.MkdirAll(dir, 0o755); err != nil {
|
||||
return fmt.Errorf("create config directory: %w", err)
|
||||
}
|
||||
if err := os.WriteFile(resolved, []byte(defaultConfigContent), 0o644); err != nil {
|
||||
return fmt.Errorf("write default config: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user