Learn about stateful agents in Modus
Agents in Modus are persistent background processes that maintain memory across interactions. Unlike stateless functions that lose everything when operations end, agents remember every detail, survive system failures, and never lose their operational context.
Agents are perfect for:
Every agent starts with the essential framework:
The agent embeds agents.AgentBase
, which provides all the infrastructure for
state management, secure communications, and persistence. Your app
data—intelligence reports, threat assessments, contact logs—lives as fields in
the struct, automatically preserved across all interactions.
Agents are created and managed through regular Modus functions that become part of your GraphQL API. These functions handle agent lifecycle operations:
When you call this function through GraphQL, it returns a unique agent ID:
Response:
You can think of an Agent as a persistent server process with durable memory. Once created, you can reference your agent by its ID across sessions, page reloads, and even system restarts. The agent maintains its complete state and continues operating exactly where it left off.
Agent builders and visual workflows: We’re actively developing Agent Builder tools and “eject to code” features that generate complete agent deployments from visual workflows. These tools automatically create the deployment functions and agent management code for complex multi-agent systems.
Once created, you communicate with agents using their unique ID. Create functions that send messages to specific agent instances:
These functions become GraphQL operations that you can call with your agent’s ID:
Response:
Response:
The agent receives the message, processes it using its internal state and AI reasoning, updates its intelligence database, and returns a response—all while maintaining persistent memory of every interaction.
Agents process requests through their message handling system:
Each message type triggers specific operations, with all data automatically maintained in the agent’s persistent memory.
Here’s how agents handle operations while maintaining persistent state and using AI models for analysis:
This demonstrates how agents maintain state across complex operations while using AI models with the full context of accumulated intelligence.
This combination creates agents that:
First Analysis: “Anomalous activity detected. Limited context available. (Threat level: 0.10 based on 1 intelligence report)”
After Multiple Reports: “Pattern confirmed across 5 previous incidents. Agent Smith replication rate exceeding normal parameters. Immediate extraction recommended. (Threat level: 0.89 based on 8 intelligence reports)”
The agent doesn’t just remember—it learns and becomes more intelligent with every interaction. AI models see the complete operational picture, enabling sophisticated pattern recognition impossible with stateless functions.
Agents automatically preserve their state through Modus’s built-in persistence system:
Agents have built-in lifecycle management protocols:
For fire-and-forget operations where you don’t need to wait for a response, agents support asynchronous messaging:
This enables agents to handle long-running operations like:
For monitoring live operations and receiving real-time intelligence updates, agents support event streaming through GraphQL subscriptions. This enables your clients to receive instant notifications about operational changes, mission progress, and critical alerts.
Monitor your agent’s real-time activities using the unified event subscription:
Your agent streams various types of operational events:
Agents can broadcast real-time operational intelligence by publishing events
during their operations. Use the PublishEvent
method to emit custom events:
This streaming capability enables sophisticated real-time operational patterns:
Live Mission Dashboards: build real-time command centers that show agent activities, mission progress, and threat alerts as they happen.
Reactive Coordination: other agents or systems can subscribe to events and automatically respond to operational changes—enabling true multi-agent coordination.
Operational intelligence: stream events to monitoring systems, alerting platforms, or data lakes for real-time operational awareness and historical analysis.
Progressive Enhancement: update user interfaces progressively as agents work through complex, multi-phase operations without polling or manual refresh.
Modus uses GraphQL subscriptions over Server-Sent Events (SSE) following the GraphQL-SSE specification. To consume these subscriptions:
text/event-stream
and make a POST
request-N
flag and appropriate headers for streamingExample with curl:
You can also poll agent status directly through dedicated functions:
The agent tracks its operational status using the mission state we defined earlier:
Your client can either poll this status endpoint via GraphQL or subscribe to real-time events for instant updates:
The streaming approach provides superior operational intelligence:
Agents enable sophisticated patterns impossible with stateless functions:
Agents represent the evolution from stateless functions to persistent background processes that maintain complete operational continuity, build intelligence over time, and provide real-time operational awareness. They’re the foundation for building systems that never lose track of their work, become smarter with every interaction, and keep teams informed through live event streaming—no matter what happens in the infrastructure.
Learn about stateful agents in Modus
Agents in Modus are persistent background processes that maintain memory across interactions. Unlike stateless functions that lose everything when operations end, agents remember every detail, survive system failures, and never lose their operational context.
Agents are perfect for:
Every agent starts with the essential framework:
The agent embeds agents.AgentBase
, which provides all the infrastructure for
state management, secure communications, and persistence. Your app
data—intelligence reports, threat assessments, contact logs—lives as fields in
the struct, automatically preserved across all interactions.
Agents are created and managed through regular Modus functions that become part of your GraphQL API. These functions handle agent lifecycle operations:
When you call this function through GraphQL, it returns a unique agent ID:
Response:
You can think of an Agent as a persistent server process with durable memory. Once created, you can reference your agent by its ID across sessions, page reloads, and even system restarts. The agent maintains its complete state and continues operating exactly where it left off.
Agent builders and visual workflows: We’re actively developing Agent Builder tools and “eject to code” features that generate complete agent deployments from visual workflows. These tools automatically create the deployment functions and agent management code for complex multi-agent systems.
Once created, you communicate with agents using their unique ID. Create functions that send messages to specific agent instances:
These functions become GraphQL operations that you can call with your agent’s ID:
Response:
Response:
The agent receives the message, processes it using its internal state and AI reasoning, updates its intelligence database, and returns a response—all while maintaining persistent memory of every interaction.
Agents process requests through their message handling system:
Each message type triggers specific operations, with all data automatically maintained in the agent’s persistent memory.
Here’s how agents handle operations while maintaining persistent state and using AI models for analysis:
This demonstrates how agents maintain state across complex operations while using AI models with the full context of accumulated intelligence.
This combination creates agents that:
First Analysis: “Anomalous activity detected. Limited context available. (Threat level: 0.10 based on 1 intelligence report)”
After Multiple Reports: “Pattern confirmed across 5 previous incidents. Agent Smith replication rate exceeding normal parameters. Immediate extraction recommended. (Threat level: 0.89 based on 8 intelligence reports)”
The agent doesn’t just remember—it learns and becomes more intelligent with every interaction. AI models see the complete operational picture, enabling sophisticated pattern recognition impossible with stateless functions.
Agents automatically preserve their state through Modus’s built-in persistence system:
Agents have built-in lifecycle management protocols:
For fire-and-forget operations where you don’t need to wait for a response, agents support asynchronous messaging:
This enables agents to handle long-running operations like:
For monitoring live operations and receiving real-time intelligence updates, agents support event streaming through GraphQL subscriptions. This enables your clients to receive instant notifications about operational changes, mission progress, and critical alerts.
Monitor your agent’s real-time activities using the unified event subscription:
Your agent streams various types of operational events:
Agents can broadcast real-time operational intelligence by publishing events
during their operations. Use the PublishEvent
method to emit custom events:
This streaming capability enables sophisticated real-time operational patterns:
Live Mission Dashboards: build real-time command centers that show agent activities, mission progress, and threat alerts as they happen.
Reactive Coordination: other agents or systems can subscribe to events and automatically respond to operational changes—enabling true multi-agent coordination.
Operational intelligence: stream events to monitoring systems, alerting platforms, or data lakes for real-time operational awareness and historical analysis.
Progressive Enhancement: update user interfaces progressively as agents work through complex, multi-phase operations without polling or manual refresh.
Modus uses GraphQL subscriptions over Server-Sent Events (SSE) following the GraphQL-SSE specification. To consume these subscriptions:
text/event-stream
and make a POST
request-N
flag and appropriate headers for streamingExample with curl:
You can also poll agent status directly through dedicated functions:
The agent tracks its operational status using the mission state we defined earlier:
Your client can either poll this status endpoint via GraphQL or subscribe to real-time events for instant updates:
The streaming approach provides superior operational intelligence:
Agents enable sophisticated patterns impossible with stateless functions:
Agents represent the evolution from stateless functions to persistent background processes that maintain complete operational continuity, build intelligence over time, and provide real-time operational awareness. They’re the foundation for building systems that never lose track of their work, become smarter with every interaction, and keep teams informed through live event streaming—no matter what happens in the infrastructure.