X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/2124c559da8f164a43a3da987b399b6ac6125035..6915dbdfeb246551bf1132823d820beb321fd58c:/daemon_agent.go?ds=sidebyside diff --git a/daemon_agent.go b/daemon_agent.go index 4520f35..227d23b 100644 --- a/daemon_agent.go +++ b/daemon_agent.go @@ -55,7 +55,7 @@ func openDaemonAgents(ctx context.Context, dir, address string, auth ModelAuthor // one agent. All model calls use its cache key and usage file. func openDaemonAgent(ctx context.Context, agent *Agent, address string, auth ModelAuthorizer, compactor ModelConfig, clock func() time.Time, logger *slog.Logger) (*DaemonAgent, error) { client := newModelClient(address, auth, agent.CacheKey(), filepath.Join(agent.dir, "usage.jsonl")) - memory, err := openMemory(ctx, agent.dir, clock, newCompactor(client, agent.Prompt, compactor, agent.Tools()), logger) + memory, err := openMemory(ctx, agent.dir, clock, newCompactor(client, agent.Prompt, compactor, agent.Tools(), agent.Images()), logger) if err != nil { return nil, fmt.Errorf("open memory: %w", err) } @@ -73,6 +73,9 @@ func openDaemonAgent(ctx context.Context, agent *Agent, address string, auth Mod schedules: schedules, clock: clock, logger: logger, + openChild: func(ctx context.Context, child *Agent) (*DaemonAgent, error) { + return openDaemonAgent(ctx, child, address, auth, compactor, clock, logger.With("name", child.config.Name)) + }, }, nil } @@ -86,12 +89,20 @@ type DaemonAgent struct { 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) { - return newTurnLoop(a.agent, a.memory, a.subagents, whatsapp, a.schedules, a.client, a.clock, a.logger, notify) + loop, err := newTurnLoop(a.agent, a.memory, a.subagents, whatsapp, a.schedules, a.client, a.clock, a.logger, notify) + if err != nil { + return nil, err + } + + loop.openChild = a.openChild + + return loop, nil } // Close flushes and closes the subagents and the memory.