This repository has been archived on 2026-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
ollie-core/agent/new.go

62 lines
1.6 KiB
Go

package agent
import (
"sync"
"github.com/simonfxr/pubsub"
"ollie/backend"
olog "ollie/log"
"ollie/toolsrv"
)
// 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() toolsrv.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
ag.wireToolsChanged()
return ag
}