The @superserve.tool decorator converts Python functions into async Ray tasks that execute across your cluster.
import superserve
@superserve.tool(num_cpus=2, memory="4GB")
async def analyze_data(dataset: str) -> dict:
"""Analyze data with heavy computation."""
# This runs as a Ray task with 2 CPUs and 4GB memory
return {"result": "analysis complete"}
You can also import the decorator directly:
from superserve import tool
@tool(num_cpus=1)
def search(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
When you call a tool, Superserve:
- Submits the function as a Ray remote task
- Allocates the specified resources (CPUs, GPUs, memory)
- Returns an awaitable that resolves to the result
Tools are async and must be awaited:
# Single tool call
result = await analyze_data("my_dataset")
Parallel Execution
Use asyncio.gather() to run multiple tools in parallel:
import asyncio
# These run concurrently on Ray workers
results = await asyncio.gather(
analyze_data("dataset_1"),
analyze_data("dataset_2"),
analyze_data("dataset_3"),
)
Use superserve.tool() as a wrapper to run framework tools on Ray:
import superserve
from langchain_community.tools import DuckDuckGoSearchRun
# Wrap a LangChain tool for Ray execution
search = superserve.tool(DuckDuckGoSearchRun(), num_cpus=1)
# Now it executes on Ray workers
result = await search("Python tutorials")
Resource Options
| Option | Type | Default | Description |
|---|
num_cpus | int/float | 1 | CPU cores per task |
num_gpus | int/float | 0 | GPUs per task |
memory | str | None | Memory limit (e.g., “4GB”, “512MB”) |
Tool descriptions for LLM schema generation come from the function’s docstring.