AI Agent Integration
How AI agents discover and consume domain schemas at runtime.
Prerequisites
Ensure you have network access to the Domains API. All examples use the base
URL https://domains.younndai.com/api.
Runtime Schema Discovery
AI agents don't need prior knowledge of domain schemas. They can discover, parse, and use schemas at runtime — adapting to any industry without retraining.
The Discovery Flow
Discover available domains
const domains = await fetch("/api/domains").then((r) => r.json());Find the relevant domain
const healthDomain = domains.find(
(d) => d.path === "yon.health",
);Fetch the full schema
const schema = await fetch(
`/api/domains/${healthDomain.path}`,
).then((r) => r.json());Field Extraction
Once the schema is loaded, agents extract field definitions to use as tool parameters:
// Extract fields from a specific record
const vitalsRecord = schema.records.VITALS;
const fields = Object.entries(vitalsRecord.fields);
// Each field has: name (key), type, required, range?, enum?, pattern?, description?
fields.forEach(([name, constraint]) => {
console.log(
`${name}: ${constraint.type}${constraint.required ? " (required)" : ""}`,
);
});
// Output:
// bp: string (required)
// hr: int
// temp_c: float
Validation
Before processing data, agents validate inputs against field definitions:
function validateField(value: unknown, constraint: FieldConstraint): boolean {
if (constraint.required && (value === undefined || value === null))
return false;
if (value === undefined) return true; // optional field, not provided
switch (constraint.type) {
case "string":
if (typeof value !== "string") return false;
if (constraint.enum && !constraint.enum.includes(value)) return false;
if (constraint.pattern && !new RegExp(constraint.pattern).test(value))
return false;
return true;
case "int":
case "float":
if (typeof value !== "number") return false;
if (
constraint.range &&
(value < constraint.range[0] || value > constraint.range[1])
)
return false;
return true;
case "bool":
return typeof value === "boolean";
case "ts":
return typeof value === "string" && !isNaN(Date.parse(value));
default:
return true;
}
}
💡Tip
Client libraries provide validate() functions that handle all type checking,
enum validation, and required field enforcement automatically. You don't need
to implement this from scratch.
Agent-to-Agent Communication
When two agents share the same domain vocabulary, structured communication emerges naturally:
Agent A structures output
Emits data according to yon.health
Agent B validates and consumes
Fetches yon.health and knows exactly what fields to expect
No negotiation needed
The schema IS the contract
This is the core thesis: when grammar (YON) and vocabulary (Domains) are shared, interoperability is free.
