X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/4343ca5fb6cc86eb887951f4fe16063bab29a238..c781f79f3c8cb9a7577ee1574d196988da2719b3:/daemon_agent.go diff --git a/daemon_agent.go b/daemon_agent.go index 227d23b..682fed7 100644 --- a/daemon_agent.go +++ b/daemon_agent.go @@ -9,6 +9,22 @@ import ( "time" ) +// DaemonAgent owns the open files and model client of one persistent agent. Its +// loop must stop before Close releases the files. +type DaemonAgent struct { + agent *Agent + memory *Memory + client *ModelClient + subagents *Subagents + schedules *Schedules + clock func() time.Time + logger *slog.Logger + openChild func(context.Context, *Agent) (*DaemonAgent, error) +} + +// DaemonAgents holds the root first and then its children in directory order. +type DaemonAgents []*DaemonAgent + // openDaemonAgents opens the root and its direct children. An invalid child // stops startup, and each opened agent is closed when startup fails. func openDaemonAgents(ctx context.Context, dir, address string, auth ModelAuthorizer, compactor ModelConfig, clock func() time.Time, logger *slog.Logger) (agents DaemonAgents, err error) { @@ -79,19 +95,6 @@ func openDaemonAgent(ctx context.Context, agent *Agent, address string, auth Mod }, nil } -// DaemonAgent owns the open files and model client of one persistent agent. Its -// loop must stop before Close releases the files. -type DaemonAgent struct { - agent *Agent - memory *Memory - client *ModelClient - subagents *Subagents - schedules *Schedules - clock func() time.Time - logger *slog.Logger - openChild func(context.Context, *Agent) (*DaemonAgent, error) -} - // Loop makes the turn loop with its event destination. Only the root has a // WhatsApp link. Child events stay with their own logs. func (a *DaemonAgent) Loop(whatsapp *WhatsApp, notify func(Event)) (*TurnLoop, error) { @@ -110,9 +113,6 @@ func (a *DaemonAgent) Close() error { return errors.Join(a.subagents.Close(), a.memory.Close()) } -// DaemonAgents holds the root first and then its children in directory order. -type DaemonAgents []*DaemonAgent - // Close closes all agents, including after a partial startup. func (a DaemonAgents) Close() error { var err error