v0.0.5: context compaction, minimal config, retry/search/code symbols/diff/status/test commands
This commit is contained in:
+58
-14
@@ -20,6 +20,20 @@ import (
|
||||
"agentu/internal/tui"
|
||||
)
|
||||
|
||||
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 main() {
|
||||
if err := run(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "agentu:", err)
|
||||
@@ -43,11 +57,10 @@ func run() error {
|
||||
cfg, err := config.Load(*configPath)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
resolvedPath, resolveErr := config.ResolvePath(*configPath)
|
||||
if resolveErr != nil {
|
||||
return resolveErr
|
||||
if bootstrapErr := bootstrapConfig(*configPath); bootstrapErr != nil {
|
||||
return bootstrapErr
|
||||
}
|
||||
return fmt.Errorf("config not found at %s; create ~/.agentu/config.yaml from agentu.example.yaml and set AGENTU_API_KEY", resolvedPath)
|
||||
return fmt.Errorf("created default config at %s; edit it to set your API key and provider, then restart agentu", *configPath)
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -65,17 +78,22 @@ func run() error {
|
||||
registry.Register(tools.NewBuiltinSearchTool(http.DefaultClient))
|
||||
registry.Register(tools.NewBuiltinFetchTool(http.DefaultClient))
|
||||
systemPrompt := strings.TrimSpace(cfg.Agent.SystemPrompt + "\n\n" + tools.AgentInstructions(cfg.Agent.WorkingDir, *yolo))
|
||||
maxContextTokens := cfg.Agent.MaxContextTokens
|
||||
if maxContextTokens == 0 {
|
||||
maxContextTokens = providerConfig.ContextTokens
|
||||
}
|
||||
|
||||
assistant := agent.New(agent.Options{
|
||||
Provider: provider,
|
||||
ProviderName: providerName,
|
||||
Model: providerConfig.Model,
|
||||
Thinking: providerConfig.Thinking,
|
||||
ThinkingParam: providerConfig.ThinkingParam,
|
||||
ThinkingEnabled: providerConfig.ThinkingConfigured,
|
||||
SystemPrompt: systemPrompt,
|
||||
ToolRegistry: registry,
|
||||
ToolTimeout: cfg.Agent.ToolTimeout,
|
||||
Provider: provider,
|
||||
ProviderName: providerName,
|
||||
Model: providerConfig.Model,
|
||||
Thinking: providerConfig.Thinking,
|
||||
ThinkingParam: providerConfig.ThinkingParam,
|
||||
ThinkingEnabled: providerConfig.ThinkingConfigured,
|
||||
SystemPrompt: systemPrompt,
|
||||
ToolRegistry: registry,
|
||||
ToolTimeout: cfg.Agent.ToolTimeout,
|
||||
MaxContextTokens: maxContextTokens,
|
||||
})
|
||||
|
||||
// Initialize session store
|
||||
@@ -114,6 +132,7 @@ func run() error {
|
||||
Yolo: *yolo,
|
||||
ThemeMode: themeMode,
|
||||
ModelManager: modelManager,
|
||||
WorkingDir: cfg.Agent.WorkingDir,
|
||||
})
|
||||
printExitSession(modelManager)
|
||||
return err
|
||||
@@ -122,12 +141,27 @@ func run() error {
|
||||
return repl(ctx, assistant, modelManager)
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
func repl(ctx context.Context, assistant *agent.Agent, modelManager *session.Manager) error {
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
|
||||
|
||||
fmt.Println("agentu")
|
||||
fmt.Println("Type /exit to quit, /clear to reset context.")
|
||||
fmt.Println("Type /exit to quit, /clear to reset context, /compact to compress context.")
|
||||
for {
|
||||
fmt.Print("> ")
|
||||
if !scanner.Scan() {
|
||||
@@ -150,6 +184,16 @@ func repl(ctx context.Context, assistant *agent.Agent, modelManager *session.Man
|
||||
assistant.Clear()
|
||||
fmt.Println("context cleared")
|
||||
continue
|
||||
case "/compact":
|
||||
if err := assistant.Compact(ctx); err != nil {
|
||||
fmt.Fprintln(os.Stderr, "compact error:", err)
|
||||
} else {
|
||||
fmt.Println("context compacted")
|
||||
if modelManager != nil {
|
||||
_ = modelManager.Save()
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if err := assistant.RunTurn(ctx, input, os.Stdout, os.Stderr); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user