69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
package agent
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"ollie/backend"
|
|
olog "ollie/log"
|
|
"ollie/toolsrv"
|
|
)
|
|
|
|
// AgentCfg is the configuration for constructing a new Agent.
|
|
type AgentCfg struct {
|
|
ID string // unique agent identity (uname)
|
|
SessionID string // id of session the agent belongs to
|
|
Profile string // config profile name (e.g. "default" → agents/default.json)
|
|
History *History
|
|
Runtime *Runtime
|
|
AgentsDir string
|
|
Cwd string // working directory for tool execution
|
|
SystemPrompt string
|
|
EnvBlock string
|
|
PromptEnvExtra []string
|
|
NewToolServer func() *toolsrv.Conn
|
|
NewBackend func(string) (backend.Backend, error)
|
|
Output EventHandler
|
|
Log *olog.Logger
|
|
AuditLog *olog.Logger
|
|
StartupMsgs []string
|
|
ReadPlanStep func() string
|
|
Save func()
|
|
Flush func()
|
|
}
|
|
|
|
// NewAgent constructs an Agent from the given configuration.
|
|
func NewAgent(cfg AgentCfg) *Agent {
|
|
auditLog := cfg.AuditLog
|
|
if auditLog == nil && cfg.Log != nil {
|
|
cfg.Log.Warn("AuditLog not provided for agent %s, deriving from Log", cfg.ID)
|
|
auditLog = cfg.Log.Sub("audit")
|
|
}
|
|
|
|
ag := &Agent{
|
|
history: cfg.History,
|
|
runtime: cfg.Runtime,
|
|
profile: cfg.Profile,
|
|
name: cfg.ID, // display name defaults to uname
|
|
agentsDir: cfg.AgentsDir,
|
|
id: cfg.ID,
|
|
cwd: cfg.Cwd,
|
|
systemPrompt: cfg.SystemPrompt,
|
|
envBlock: cfg.EnvBlock,
|
|
promptEnvExtra: cfg.PromptEnvExtra,
|
|
newToolServer: cfg.NewToolServer,
|
|
newBackend: cfg.NewBackend,
|
|
output: cfg.Output,
|
|
log: cfg.Log,
|
|
auditLog: auditLog,
|
|
sessionID: cfg.SessionID,
|
|
startupMessages: cfg.StartupMsgs,
|
|
readPlanStep: cfg.ReadPlanStep,
|
|
save: cfg.Save,
|
|
flush: cfg.Flush,
|
|
state: "idle",
|
|
}
|
|
ag.changeCond = sync.NewCond(&ag.changeMu)
|
|
ag.wireToolsChanged()
|
|
return ag
|
|
}
|