Skip to main content

Run agentic workloads on Ray

Project description

RayAI Logo

Scalable runtime for Agents, MCP Servers, and coding sandboxes, orchestrated with Ray.

License Python

Features

  • Distributed Runtime - Resource-aware tool execution on Ray clusters with automatic scaling
  • Framework Agnostic - Works with LangChain, Pydantic AI, or pure Python (support for more frameworks coming soon)
  • Secure Sandboxing - gVisor-sandboxed environments for AI-generated code execution
  • Simple CLI - Initialize projects, create agents, and serve with single commands
  • Production Ready - Built on Ray Serve for reliable, scalable deployments

Quick Start

# Install
pip install rayai

# Create a new project
rayai init my_project
cd my_project

# Create your first agent
rayai create-agent my_agent

# Run locally
rayai serve

Your agent is now available at http://localhost:8000/agents/my_agent/chat

Installation

pip install rayai

With optional sandbox support (for code execution):

pip install rayai[sandbox]

Requirements: Python 3.12+

Usage

CLI Commands

Initialize a Project

rayai init my_project

Creates a project structure with configuration files and an agents/ directory.

Create an Agent

rayai create-agent my-agent
rayai create-agent my-agent --framework langchain
rayai create-agent my-agent --framework pydantic

Supported frameworks: python (default), langchain, pydantic

Serve Agents

rayai serve                          # Serve all agents on port 8000
rayai serve --port 9000              # Custom port
rayai serve --agents agent1,agent2   # Serve specific agents

Creating Your First Agent

After running rayai create-agent my_agent, edit agents/my_agent/agent.py:

from rayai import agent, tool

@tool(desc="Search for information", num_cpus=1)
def search(query: str) -> str:
    return f"Results for: {query}"

@agent(num_cpus=1, memory="2GB")
class MyAgent:
    def __init__(self):
        self.tools = [search]

    def run(self, data: dict) -> dict:
        messages = data.get("messages", [])
        user_message = messages[-1]["content"] if messages else ""

        # Your agent logic here
        return {"response": f"You said: {user_message}"}

Test your agent:

curl -X POST http://localhost:8000/agents/my_agent/chat \
  -H "Content-Type: application/json" \
  -d '{"data": {"messages": [{"role": "user", "content": "Hello!"}]}, "session_id": "test"}'

API Reference

@agent Decorator

Marks a class as a deployable agent with resource requirements.

@agent(num_cpus=2, memory="4GB", num_gpus=1, num_replicas=2)
class MyAgent:
    def run(self, data: dict) -> dict:
        return {"response": "Hello!"}
Parameter Type Default Description
num_cpus int 1 CPU cores per replica
num_gpus int 0 GPUs per replica
memory str "2GB" Memory allocation
num_replicas int 1 Number of replicas

@tool Decorator

Creates a Ray remote task from a function.

@tool(desc="Tool description", num_cpus=2, memory="1GB")
def my_tool(query: str) -> dict:
    return {"result": query}
Parameter Type Default Description
desc str required Tool description for LLM
num_cpus int 1 CPU requirement
num_gpus int 0 GPU requirement
memory str None Memory requirement

execute_tools

Define tools and execute them in parallel on Ray:

from rayai import tool, execute_tools

@tool(desc="Tool 1 description")
def tool_1(x: str) -> str:
    return process_1(x)

@tool(desc="Tool 2 description")
def tool_2(x: str) -> dict:
    return process_2(x)

# Execute both tools in parallel on Ray
results = execute_tools([
    (tool_1, {"x": "input_1"}),
    (tool_2, {"x": "input_2"})
], parallel=True)

Examples

See the examples/ directory for complete implementations:

  • Token-Efficient Agent - Autonomous code execution in sandboxed environments
  • Finance Agent - Multi-step financial analysis with external APIs

Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.


If you find this project helpful, please consider giving it a ⭐

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rayai-0.1.0.tar.gz (53.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rayai-0.1.0-py3-none-any.whl (52.1 kB view details)

Uploaded Python 3

File details

Details for the file rayai-0.1.0.tar.gz.

File metadata

  • Download URL: rayai-0.1.0.tar.gz
  • Upload date:
  • Size: 53.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for rayai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2352caf4b27aaec36f779630ef2401e0765f9a5c830e02ffb920137d4523d971
MD5 f628f5daae11de49b5df9be4517e88bf
BLAKE2b-256 266e9218ba1f26cff1cf8081575cb5c77b0d225a8c79abd787e6db0505b60029

See more details on using hashes here.

File details

Details for the file rayai-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: rayai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 52.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.0

File hashes

Hashes for rayai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9e2fdeb355f8e5326d01c0e38fad0cbaad68a2037af5a1e473b26bf1ff14ab9
MD5 4c6263b4a0623b891da0de1eeb34ad35
BLAKE2b-256 ef881c6908e9353d2537f92ba97ecdfa3896a6ec8a162376c118024ea8f9e3bc

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page