62 lines
1.6 KiB
Go
62 lines
1.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
|
|
"ollie/backend"
|
|
)
|
|
|
|
// Prompt holds the agent prompt — a list of file paths to read and concatenate.
|
|
// Unmarshals from either a JSON string (single path) or array of strings.
|
|
type Prompt struct {
|
|
Value []string
|
|
}
|
|
|
|
func (p *Prompt) UnmarshalJSON(data []byte) error {
|
|
var s string
|
|
if err := json.Unmarshal(data, &s); err == nil {
|
|
p.Value = []string{s}
|
|
return nil
|
|
}
|
|
return json.Unmarshal(data, &p.Value)
|
|
}
|
|
|
|
func (p Prompt) MarshalJSON() ([]byte, error) {
|
|
if len(p.Value) == 1 {
|
|
return json.Marshal(p.Value[0])
|
|
}
|
|
return json.Marshal(p.Value)
|
|
}
|
|
|
|
type AgentConfig struct {
|
|
Prompt Prompt `json:"prompt,omitempty"`
|
|
Backend string `json:"backend,omitempty"`
|
|
Model string `json:"model,omitempty"`
|
|
Tools *bool `json:"tools,omitempty"`
|
|
AllowTools []string `json:"allowTools,omitempty"`
|
|
AutoLoad []string `json:"autoLoad,omitempty"`
|
|
// MaxSteps caps the number of tool-call rounds per turn. 0 means unlimited.
|
|
MaxSteps int `json:"maxSteps,omitempty"`
|
|
CompactionModel string `json:"compactionModel,omitempty"`
|
|
// SystemPrompt overrides the embedded system prompt with a file path.
|
|
SystemPrompt string `json:"systemPrompt,omitempty"`
|
|
|
|
backend.GenerationParams
|
|
}
|
|
|
|
// Load parses a Config from r.
|
|
func Load(r io.Reader) (*AgentConfig, error) {
|
|
var cfg AgentConfig
|
|
if err := json.NewDecoder(r).Decode(&cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
return &cfg, nil
|
|
}
|
|
|
|
// ToolsEnabled reports whether tool use is enabled. Defaults to true when
|
|
// the field is omitted from the config.
|
|
func (c *AgentConfig) ToolsEnabled() bool {
|
|
return c.Tools == nil || *c.Tools
|
|
}
|