Skip to content

Runtimes

AgentSchema provides official runtime libraries for multiple programming languages, making it easy to load, create, and manipulate agent definitions programmatically.

Terminal window
pip install agentschema

Or using uv:

Terminal window
uv add agentschema

Parse a YAML string into an agent definition:

from agentschema import AgentDefinition
yaml_content = """
name: my-agent
model: gpt-4o
instructions: You are a helpful assistant.
"""
agent = AgentDefinition.from_yaml(yaml_content)
print(agent.name) # "my-agent"

Load agent definitions directly from files:

from agentschema import AgentDefinition
# Load from YAML file
agent = AgentDefinition.from_yaml_file("agent.yaml")
# Load from JSON file
agent = AgentDefinition.from_json_file("agent.json")

Create agent definitions using strongly-typed classes:

from agentschema import AgentDefinition, FunctionTool, Property
agent = AgentDefinition(
name="weather-agent",
description="Helps users check the weather",
model="gpt-4o",
instructions="You help users check the weather.",
tools={
"get_weather": FunctionTool(
name="get_weather",
description="Get current weather for a location",
parameters={
"location": Property(
kind="string",
description="City name",
required=True,
),
},
),
},
)

Export agent definitions to YAML or JSON:

# Convert to YAML string
yaml_str = agent.to_yaml()
# Convert to JSON string
json_str = agent.to_json(indent=2)
# Save to files
agent.to_yaml_file("output.yaml")
agent.to_json_file("output.json")
# Convert to dictionary
data = agent.save()

Customize loading and saving behavior with context objects:

from agentschema import AgentDefinition, LoadContext, SaveContext
# Custom load processing
def pre_process(data: dict) -> dict:
print(f"Loading: {data.get('name')}")
return data
load_ctx = LoadContext(pre_process=pre_process)
agent = AgentDefinition.from_yaml(yaml_content, load_ctx)
# Custom save formatting
save_ctx = SaveContext(
collection_format="object", # Use object format
use_shorthand=True, # Use shorthand notation
)
yaml_str = agent.to_yaml(save_ctx)

Choose the runtime that matches your development environment:

  • Python - For data science workflows, AI/ML pipelines, or Python-based backends
  • TypeScript/JavaScript - For Node.js applications, serverless functions, or web applications
  • C# / .NET - For enterprise applications, Azure Functions, or .NET-based services
  • Go - For high-performance services, CLI tools, or cloud-native applications

For detailed API documentation, select your language:

Python Runtime

Full API reference with async support and type hints.

View Details →