Skip to main content

When to use Pydantic AI

  • You want type-safe agent development
  • You prefer Pydantic’s validation and schema generation
  • You need structured outputs from your agents

Create an agent

superserve create-agent my_agent --framework pydantic

Define tools with @superserve.tool

Use @superserve.tool to create Ray-distributed tools that work directly with Pydantic AI:
import superserve
from pydantic_ai import Agent


@superserve.tool(num_cpus=1)
def search_web(query: str) -> str:
    """Search the web for information."""
    return f"Results for: {query}"


@superserve.tool(num_cpus=2, memory="4GB")
def analyze_data(data: str) -> dict:
    """Analyze data with heavy computation."""
    return {"result": f"Analysis of {data}"}


def make_agent():
    return Agent(
        "openai:gpt-4o-mini",
        system_prompt="You are a helpful assistant.",
        tools=[search_web, analyze_data],
    )


superserve.serve(make_agent, name="my-agent", num_cpus=1, memory="2GB")

Wrap existing tools

Use superserve.tool() as a wrapper for existing callables or framework tools:
import superserve
from pydantic_ai import Agent
from langchain_community.tools import DuckDuckGoSearchRun


# Wrap a LangChain tool for Ray execution
lc_search = superserve.tool(DuckDuckGoSearchRun(), num_cpus=1)


# Wrap a plain function
def calculate(a: int, b: int) -> int:
    """Add two numbers together."""
    return a + b

ray_calculate = superserve.tool(calculate)


def make_agent():
    return Agent("openai:gpt-4o-mini", tools=[lc_search, ray_calculate])


superserve.serve(make_agent, name="calc-agent")

Next steps