61 lines
1.6 KiB
Go
61 lines
1.6 KiB
Go
package agent
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"github.com/simonfxr/pubsub"
|
|
"ollie/backend"
|
|
olog "ollie/log"
|
|
"ollie/tools"
|
|
)
|
|
|
|
// AgentCfg is the configuration for constructing a new Agent.
|
|
type AgentCfg struct {
|
|
History *History
|
|
Runtime *Runtime
|
|
AgentName string
|
|
AgentsDir string
|
|
AgentID string // unique agent identity
|
|
CWD string // working directory for tool execution
|
|
BaseLayers []string
|
|
PromptEnvExtra []string
|
|
NewToolServer func() tools.Runner
|
|
NewBackend func(string) (backend.Backend, error)
|
|
Bus *pubsub.Bus
|
|
Log *olog.Logger
|
|
AuditLog *olog.Logger
|
|
SessionID string
|
|
StartupMsgs []string
|
|
ReadPlanStep func() string
|
|
SaveSession func()
|
|
FlushSave func()
|
|
}
|
|
|
|
// NewAgent constructs an Agent from the given configuration.
|
|
func NewAgent(cfg AgentCfg) *Agent {
|
|
ag := &Agent{
|
|
history: cfg.History,
|
|
runtime: cfg.Runtime,
|
|
agentName: cfg.AgentName,
|
|
agentsDir: cfg.AgentsDir,
|
|
id: cfg.AgentID,
|
|
cwd: cfg.CWD,
|
|
baseLayers: cfg.BaseLayers,
|
|
promptEnvExtra: cfg.PromptEnvExtra,
|
|
newToolServer: cfg.NewToolServer,
|
|
newBackend: cfg.NewBackend,
|
|
bus: cfg.Bus,
|
|
log: cfg.Log,
|
|
auditLog: cfg.AuditLog,
|
|
sessionID: cfg.SessionID,
|
|
startupMessages: cfg.StartupMsgs,
|
|
readPlanStep: cfg.ReadPlanStep,
|
|
saveSession: cfg.SaveSession,
|
|
flushSave: cfg.FlushSave,
|
|
state: "idle",
|
|
}
|
|
ag.changeCond = sync.NewCond(&ag.changeMu)
|
|
ag.turnError = ag.defaultTurnError
|
|
return ag
|
|
}
|