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

Commit e5e2384

Browse files
support agent persistence
1 parent f6cb27b commit e5e2384

File tree

26 files changed

+649
-183
lines changed

26 files changed

+649
-183
lines changed

.trunk/configs/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@
119119
"minilm",
120120
"modfile",
121121
"modusdb",
122+
"modusgraph",
122123
"Msgf",
123124
"mydb",
124125
"mydgraph",

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
## UNRELEASED
66

77
- feat: initial implementation of Modus Agents [#840](https://github.com/hypermodeinc/modus/pull/840)
8+
- feat: persistence and lifecycle improvements for Modus Agents [#843](https://github.com/hypermodeinc/modus/pull/843)
89

910
## 2025-05-06 - CLI 0.17.4
1011

go.work

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
go 1.24.2
1+
go 1.24.3
22

33
use (
44
./lib/manifest

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)