]> git.giacomolli.uk - onechat/blobdiff - daemon_agent.go
Import WhatsApp history into a child
[onechat] / daemon_agent.go
index 1161c8a67a26e3055aa7c9b066227d75f5d4ac18..662291c637c14c208987e135316bf1f8e0141112 100644 (file)
@@ -60,7 +60,7 @@ func openDaemonAgent(ctx context.Context, agent *Agent, address string, auth Mod
                return nil, fmt.Errorf("open memory: %w", err)
        }
 
-       schedules, err := openSchedules(filepath.Join(agent.dir, scheduleFileName), clock, logger)
+       schedules, err := openSchedules(filepath.Join(agent.dir, scheduleFileName), agent.config.Name, clock, logger)
        if err != nil {
                return nil, errors.Join(fmt.Errorf("open schedules: %w", err), memory.Close())
        }
@@ -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.