Skip to main content
The @agent decorator marks a class as a deployable agent and configures its Ray Actor resources.
from rayai import agent

@agent(num_cpus=2, memory="4GB", num_replicas=3)
class MyAgent:
    def run(self, data: dict) -> dict:
        messages = data.get("messages", [])
        # Process messages and return response
        return {"response": "Hello!"}
Each agent instance runs as a Ray Actor with dedicated resources, enabling:
  • Statefulness: Maintain state across requests
  • Resource isolation: Guaranteed CPU, GPU, and memory allocation
  • Horizontal scaling: Multiple replicas for high availability

Resource Options

OptionTypeDefaultDescription
num_cpusint1CPU cores per replica
num_gpusint0GPUs per replica
memorystr”2GB”Memory per replica
num_replicasint1Number of replicas for scaling
If your agent uses async operations, define async def run() - RayAI automatically detects and awaits it.