Skip to content
This repository was archived by the owner on Sep 11, 2025. It is now read-only.

Commit f2c8680

Browse files
.
1 parent 3c4f804 commit f2c8680

File tree

16 files changed

+561
-141
lines changed

16 files changed

+561
-141
lines changed

runtime/actors/actorsystem.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ import (
1313
"context"
1414
"time"
1515

16+
"github.com/hypermodeinc/modus/runtime/db"
1617
"github.com/hypermodeinc/modus/runtime/logger"
1718
"github.com/hypermodeinc/modus/runtime/pluginmanager"
1819
"github.com/hypermodeinc/modus/runtime/plugins"
20+
"github.com/hypermodeinc/modus/runtime/wasmhost"
1921

2022
goakt "github.com/tochemey/goakt/v3/actor"
2123
)
@@ -45,18 +47,36 @@ func Initialize(ctx context.Context) {
4547

4648
logger.Info(ctx).Msg("Actor system started.")
4749

48-
pluginmanager.RegisterPluginLoadedCallback(reloadAgentActors)
50+
pluginmanager.RegisterPluginLoadedCallback(loadAgentActors)
4951
}
5052

51-
func reloadAgentActors(ctx context.Context, plugin *plugins.Plugin) error {
52-
for _, pid := range _actorSystem.Actors() {
53+
func loadAgentActors(ctx context.Context, plugin *plugins.Plugin) error {
54+
// reload modules for actors that are already running
55+
actors := _actorSystem.Actors()
56+
runningAgents := make(map[string]bool, len(actors))
57+
for _, pid := range actors {
5358
if actor, ok := pid.Actor().(*WasmAgentActor); ok {
59+
runningAgents[actor.agentId] = true
5460
if err := actor.reloadModule(ctx, plugin); err != nil {
5561
return err
5662
}
5763
}
5864
}
5965

66+
// spawn actors for agents with state in the database, that are not already running
67+
// TODO: when we scale out with GoAkt cluster mode, we'll need to decide which node is responsible for spawning the actor
68+
agents, err := db.QueryActiveAgents(ctx)
69+
if err != nil {
70+
logger.Err(ctx, err).Msg("Failed to query agents from database.")
71+
return err
72+
}
73+
host := wasmhost.GetWasmHost(ctx)
74+
for _, agent := range agents {
75+
if !runningAgents[agent.Id] {
76+
spawnActorForAgent(host, plugin, agent.Id, agent.Name, true, &agent.Data)
77+
}
78+
}
79+
6080
return nil
6181
}
6282

0 commit comments

Comments
 (0)