Documentation
¶
Index ¶
- Variables
- func Register(agent Agent)
- func SendMessage(agentId, msgName string, options ...messageOption) (*string, error)
- func SendMessageAsync(agentId, msgName string, options ...messageOption) error
- func WithData(data string) messageOption
- func WithTimeout(timeout time.Duration) messageOption
- type Agent
- type AgentBase
- func (a *AgentBase) Id() string
- func (a *AgentBase) OnInitialize() error
- func (a *AgentBase) OnReceiveMessage(msgName string, data *string) (*string, error)
- func (a *AgentBase) OnResume() error
- func (a *AgentBase) OnSuspend() error
- func (a *AgentBase) OnTerminate() error
- func (a *AgentBase) PublishEvent(event AgentEvent) error
- type AgentEvent
- type AgentInfo
- type AgentStatus
- type MessageResponse
Constants ¶
This section is empty.
Variables ¶
var GetAgentInfoCallStack = testutils.NewCallStack()
var ListAgentsCallStack = testutils.NewCallStack()
var PublishEventCallStack = testutils.NewCallStack()
var SendMessageCallStack = testutils.NewCallStack()
var StartAgentCallStack = testutils.NewCallStack()
var StopAgentCallStack = testutils.NewCallStack()
Functions ¶
func Register ¶
func Register(agent Agent)
Registers an agent so it can be used. This function should be called from an init function.
func SendMessage ¶
SendMessage sends a message to the specified agent and waits for a response. The message is sent synchronously and the function will block until a response is received or the timeout is reached. The timeout can be set using the WithTimeout option, and defaults to 10 seconds if not set. Data can be sent with the message using the WithData option.
func SendMessageAsync ¶
SendMessageAsync sends a message to the specified agent without waiting for a response. The message is sent asynchronously and the function will return immediately. Data can be sent with the message using the WithData option. The timeout is ignored for asynchronous messages and is always set to 0.
func WithData ¶
func WithData(data string) messageOption
WithData sets the data for the message. This is optional and can be omitted if no data is needed.
func WithTimeout ¶
WithTimeout sets the timeout for the message. This is optional and defaults to 10 seconds for synchronous messages, if not set. A value of 0 means the message will be sent asynchronously without waiting for a response.
Types ¶
type Agent ¶
type Agent interface {
// Id returns the unique identifier of the agent.
// This is set by the Modus Runtime when the agent is activated.
// Custom agents should not implement this method, but rather use the default implementation provided by AgentBase.
Id() string
// Name returns the name of the agent.
// This should be unique across all agents in the module.
// Custom agents must implement this method.
Name() string
// GetState returns the serialized state of the agent.
// Custom agents must implement this method.
GetState() *string
// SetState sets the state of the agent from a serialized string.
// Custom agents must implement this method.
SetState(data *string)
// OnInitialize is called when the agent is started.
// Custom agents may implement this method to perform any initialization.
OnInitialize() error
// OnSuspend is called when the agent is suspended.
// Custom agents may implement this method if for example, to send a notification.
// Note that you do not need to save the internal state of the agent here, as that is handled automatically.
OnSuspend() error
// OnResume is called when the agent is resumed from a suspended state.
// Custom agents may implement this method if for example, to send a notification.
// Note that you do not need to restore the internal state of the agent here, as that is handled automatically.
OnResume() error
// OnTerminate is called when the agent is terminated.
// Custom agents may implement this method to send or save any final data.
OnTerminate() error
// OnReceiveMessage is called when the agent receives a message.
// Custom agents may implement this method to handle incoming messages.
OnReceiveMessage(msgName string, data *string) (*string, error)
}
The Agent interface defines the methods that an agent must implement. Agents are long-running processes that can receive messages and maintain state.
type AgentBase ¶
type AgentBase struct {
}
The AgentBase struct provides default implementations for the Agent interface methods. Custom agents can embed this struct to avoid implementing all methods.
func (*AgentBase) OnInitialize ¶
func (*AgentBase) OnReceiveMessage ¶
func (*AgentBase) OnTerminate ¶
func (*AgentBase) PublishEvent ¶
func (a *AgentBase) PublishEvent(event AgentEvent) error
Publishes an event from this agent to any subscribers.
type AgentEvent ¶
type AgentEvent interface {
// EventName returns the type of the event.
EventName() string
}
AgentEvent is an interface that represents an event emitted by an agent. Custom agent events should implement this interface.
type AgentInfo ¶
AgentInfo contains information about an agent.
type AgentStatus ¶
type AgentStatus = string
const ( AgentStatusStarting AgentStatus = "starting" AgentStatusRunning AgentStatus = "running" AgentStatusSuspending AgentStatus = "suspending" AgentStatusSuspended AgentStatus = "suspended" AgentStatusResuming AgentStatus = "resuming" AgentStatusStopping AgentStatus = "stopping" AgentStatusTerminated AgentStatus = "terminated" )
type MessageResponse ¶
type MessageResponse struct {
// contains filtered or unexported fields
}