Functions in Modus
Functions in Modus are stateless, request-response operations that handle specific tasks with precision and speed. They get in, complete their objective, and report back—no unnecessary complications, no lingering presence, just pure operational efficiency. You can think of a function as an endpoint—each function you write automatically becomes a callable API endpoint that external systems can access. Functions are the backbone of your app, handling everything from data gathering to AI-powered analysis, all while maintaining clean, predictable behavior.Core characteristics
Functions are stateless, request-response operations designed for fast, predictable execution. They’re your go-to choice when you need quick data processing, external API integration, or computational tasks without maintaining state between requests.Key capabilities
- Stateless: Each operation is independent with no memory of previous requests
- Lightning fast: Optimized for sub-second response times
- Infinitely scalable: Deploy as many instances as needed
- Clean operations: Straightforward request-in, response-out pattern
- Auto-deployed: Exposed automatically as GraphQL queries or mutations
How functions become endpoints
When you deploy your functions, Modus automatically exposes them through a GraphQL API. Your functions become either queries (for data retrieval) or mutations (for data modifications) based on their operation type.Data retrieval queries
Most functions become GraphQL queries—perfect for fetching and processing data:Data modification mutations
Functions that modify data automatically become GraphQL mutations. Modus detects these by their operation prefixes:create
, update
, delete
, and similar action words
automatically become mutations.
Example: Weather intelligence analysis
Here’s a complete example that demonstrates how functions integrate external APIs with AI models for intelligent data processing:Setting up the function
To use this function, you’ll need to: Sign up for a free API key at OpenWeatherMap Add the connections and models to yourmodus.json
:
.env.dev.local
:
When to use agents instead
Functions are perfect for most computational tasks, but when you need persistent state, complex multi-step workflows, or processes that remember details across multiple interactions, it’s time to consider agents. Consider upgrading to agents when your use case requires:- Persistent memory across multiple requests
- Conversation context that builds over time
- Multi-step workflows spanning extended periods
- Recovery from failures with state preservation
- Continuous monitoring with context retention