Convert OpenAI agents to Agent Spec#

This usage example showcases how a OpenAI Agent can be converted into an Agent Spec configuration in JSON format.

# Create an OpenAI Agent
from agents.agent import Agent, function_tool

@function_tool
def subtraction_tool(a: float, b: float) -> float:
    """subtract two numbers together"""
    return a - b

openai_agent = Agent(
    name="openai_agent",
    model="gpt-5-mini",
    instructions="Perform subtraction with the given tool.",
    tools=[subtraction_tool],
)

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

agentspec_config = AgentSpecExporter().to_json(openai_agent)