This repository was archived by the owner on Sep 11, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmain.go
More file actions
78 lines (66 loc) · 2.45 KB
/
Copy pathmain.go
File metadata and controls
78 lines (66 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* This example is part of the Modus project, licensed under the Apache License 2.0.
* You may modify and use this example in accordance with the license.
* See the LICENSE file that accompanied this code for further details.
*/
package main
import (
"strconv"
"github.com/hypermodeinc/modus/sdk/go/pkg/agents"
)
// All agents must be registered before they can be used.
// This is done in an init function.
func init() {
agents.Register(&CounterAgent{})
}
// The following are regular Modus functions.
// They are not part of the agent, but are used to start the agent and interact with it.
// Note that they cannot use an instance of the CounterAgent struct directly,
// but rather they will start an instance by name, and then send messages to it by ID.
// This is because the agent instance will actually be running in a different WASM instance,
// perhaps on a different process or even on a different machine.
// Starts a counter agent and returns info including its ID and status.
func StartCounterAgent() (agents.AgentInfo, error) {
return agents.Start("Counter")
}
// Stops the specified agent by ID, returning its status info.
// This will terminate the agent, and it cannot be resumed or restarted.
// However, a new agent with the same name can be started at any time.
func StopAgent(agentId string) (agents.AgentInfo, error) {
return agents.Stop(agentId)
}
// Gets information about the specified agent.
func GetAgentInfo(agentId string) (agents.AgentInfo, error) {
return agents.GetInfo(agentId)
}
// List all agents, except those that have been fully terminated.
func ListAgents() ([]agents.AgentInfo, error) {
return agents.ListAll()
}
// Returns the current count of the specified agent.
func GetCount(agentId string) (int, error) {
count, err := agents.SendMessage(agentId, "count")
if err != nil {
return 0, err
}
if count == nil {
return 0, nil
}
return strconv.Atoi(*count)
}
// Increments the count of the specified agent by 1 and returns the new count.
func UpdateCount(agentId string) (int, error) {
count, err := agents.SendMessage(agentId, "increment")
if err != nil {
return 0, err
}
if count == nil {
return 0, nil
}
return strconv.Atoi(*count)
}
// Increments the count of the specified agent by the specified quantity.
// This is an asynchronous operation and does not return a value.
func UpdateCountAsync(agentId string, qty int) error {
return agents.SendMessageAsync(agentId, "increment", agents.WithData(strconv.Itoa(qty)))
}