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:
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.
To begin, import the agents
namespace and Agent
base class from the SDK:
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!
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.
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 an agent instance. Once stopped, the agent can’t be resumed.
The unique identifier of the agent instance to stop.
Get information about a specific agent instance.
The unique identifier of the agent instance.
List all active agent instances.
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.
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.
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.
Publishes an event from this agent to any subscribers. The event must extend
the AgentEvent
base class.
Base class for agent events that can be published to subscribers.
The name of the event type. Must be provided in the constructor and can’t be empty.
Custom events should extend this class and include any additional data as properties:
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.
Here’s a complete example of a simple counter agent with event streaming:
Once deployed, your agent functions become available via GraphQL:
To receive real-time events from your agent, subscribe using GraphQL subscriptions over Server-Sent Events:
Example events you might receive:
Use appropriate GraphQL Server-Sent Events (SSE) clients such as:
Example with EventSource:
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:
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.
To begin, import the agents
namespace and Agent
base class from the SDK:
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!
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.
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 an agent instance. Once stopped, the agent can’t be resumed.
The unique identifier of the agent instance to stop.
Get information about a specific agent instance.
The unique identifier of the agent instance.
List all active agent instances.
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.
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.
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.
Publishes an event from this agent to any subscribers. The event must extend
the AgentEvent
base class.
Base class for agent events that can be published to subscribers.
The name of the event type. Must be provided in the constructor and can’t be empty.
Custom events should extend this class and include any additional data as properties:
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.
Here’s a complete example of a simple counter agent with event streaming:
Once deployed, your agent functions become available via GraphQL:
To receive real-time events from your agent, subscribe using GraphQL subscriptions over Server-Sent Events:
Example events you might receive:
Use appropriate GraphQL Server-Sent Events (SSE) clients such as:
Example with EventSource: