Convert CrewAI agents to Agent Spec#

# Create a CrewAI Agent
from crewai import LLM, Agent
from crewai.tools.base_tool import Tool
from pydantic import BaseModel

class InputSchema(BaseModel):
    a: float
    b: float

def subtract(a: float, b: float) -> float:
    """Subtract two numbers"""
    return a - b

llm = LLM(
    model="hosted_vllm/Llama-4-Maverick",
    api_base="http://url.to.my.llama.model/v1",
    max_tokens=512,
)

crewai_agent = Agent(
    role="Calculator agent",
    goal="Computes the mathematical operation prompted by the user",
    backstory="You are a calculator with 20 years of experience",
    llm=llm,
    tools=[
        Tool(
            name="subtract",
            description="Subtract two numbers",
            args_schema=InputSchema,
            func=subtract,
        ),
    ],
)

# Convert to Agent Spec
from pyagentspec.adapters.crewai import AgentSpecExporter

agentspec_config = AgentSpecExporter().to_json(crewai_agent)