Agents APIs
Build stateful agents that maintain persistent memory across interactions
While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.
Modus Agents APIs documentation is available on the following pages:
- AssemblyScript Agents APIs(this page)
- Go Agents APIs
The Modus Agents APIs allow you to create stateful agents that maintain persistent memory across interactions, survive system failures, and coordinate complex multi-step operations.
Import
To begin, import the agents
namespace and Agent
base class from the SDK:
Agent APIs
The APIs in the agents
namespace are below, organized by category.
We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!
Agent Management Functions
register
Register an agent class with the Modus runtime before it can be instantiated.
The agent class type that extends the Agent
base class.
Agent registration must be done at the module level, outside of any function.
start
Create and start a new agent instance.
The name of the agent class to instantiate. This must match the name
property returned by the agent class.
stop
Stop an agent instance. Once stopped, the agent can’t be resumed.
The unique identifier of the agent instance to stop.
get info
Get information about a specific agent instance.
The unique identifier of the agent instance.
list all
List all active agent instances.
Communication Functions
send message
Send a synchronous message to an agent and wait for a response.
The unique identifier of the target agent instance.
The name of the message to send to the agent.
Optional data payload to send with the message.
sendMessageAsync
Send an asynchronous message to an agent without waiting for a response.
The unique identifier of the target agent instance.
The name of the message to send to the agent.
Optional data payload to send with the message.
Agent Base Class
Agent
The base class that all agents must extend.
Abstract property that must return a unique name for the agent class.
Abstract method that handles incoming messages to the agent. Must be implemented by all agent classes.
Optional method that returns the agent’s current state as a string for persistence. Called automatically when the agent needs to be suspended or migrated.
Optional method that restores the agent’s state from a string. Called automatically when the agent is resumed or migrated.
Optional lifecycle method called when the agent is first created.
Optional lifecycle method called when the agent is about to be suspended.
Optional lifecycle method called when the agent is resumed from suspension.
Optional lifecycle method called when the agent is about to be terminated.
Types
AgentInfo
Information about an agent instance.
The unique identifier of the agent instance.
The name of the agent class.
The current status of the agent instance.
Example Usage
Here’s a complete example of a simple counter agent:
Agent Implementation
Function Integration
GraphQL Usage
Once deployed, your agent functions become available via GraphQL: