agents

package
v0.18.0-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 29, 2025 License: Apache-2.0 Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GetAgentInfoCallStack = testutils.NewCallStack()
View Source
var ListAgentsCallStack = testutils.NewCallStack()
View Source
var SendMessageCallStack = testutils.NewCallStack()
View Source
var StartAgentCallStack = testutils.NewCallStack()
View Source
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

func SendMessage(agentId, msgName string, options ...messageOption) (*string, error)

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

func SendMessageAsync(agentId, msgName string, options ...messageOption) error

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

func WithTimeout(timeout time.Duration) messageOption

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) Id

func (a *AgentBase) Id() string

func (*AgentBase) OnInitialize

func (a *AgentBase) OnInitialize() error

func (*AgentBase) OnReceiveMessage

func (a *AgentBase) OnReceiveMessage(msgName string, data *string) (*string, error)

func (*AgentBase) OnResume

func (a *AgentBase) OnResume() error

func (*AgentBase) OnSuspend

func (a *AgentBase) OnSuspend() error

func (*AgentBase) OnTerminate

func (a *AgentBase) OnTerminate() error

type AgentInfo

type AgentInfo struct {
	Id     string
	Name   string
	Status string
}

func GetInfo

func GetInfo(agentId string) (AgentInfo, error)

Gets information about an agent with the given ID.

func ListAll

func ListAll() ([]AgentInfo, error)

Returns a list of all agents, except those that have been fully terminated.

func Start

func Start(name string) (AgentInfo, error)

Starts an agent with the given name. This can be called from any user code, such as function or another agent's methods.

func Stop

func Stop(agentId string) (AgentInfo, error)

Stops an agent with the given ID and returns its status info. This will terminate the agent, and it cannot be resumed or restarted.

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL