Schema

Schema Types

AgentScript uses schema definitions for type-checking generated code and tool parameters at runtime. These schemas help the LLM understand the structure of data and generate correct code.

Basic Types

s.string(options)

A string value.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property

s.number(options)

A number value.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property

s.boolean(options)

A boolean value.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property

s.date(options)

A date value.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property

s.void(options)

A void value.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property

s.unknown(options)

An unknown value.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property

Complex Types

s.object(options)

A composite type that represents an object with defined props.

  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property
    • props (object, required): A map of property names and schemas
    • optional (boolean, optional): Marks type as optional
    • nullable (boolean, optional): Marks type as nullable
import * as s from 'agentscript-ai/schema';
 
const user = s.object({
  name: 'User',
  props: {
    name: s.string({description: "Name of the user"}),
    email: s.string({description: "Email of the user"})
  }
});

s.array(options)

An array of a specific type.

  • options:
    • of (schema, required): Type of array elements
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property
import * as s from 'agentscript-ai/schema';
 
const users = s.array({of: s.string()});

s.enum(values, options)

Enum, where the type has one of the predefined set of string values.

  • values (string[], required): Array of possible values
  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property
import * as s from 'agentscript-ai/schema';
 
const status = s.enum(['active', 'inactive']);

s.union(schemas)

Union, where the type is one of defined schema types.

  • schemas (schema[], required): Array of possible schema types
  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property
import * as s from 'agentscript-ai/schema';
 
const primitiveType = s.union([s.string(), s.number(), s.boolean()]);

Modifiers

s.nullable(schema)

Makes a schema type nullable.

  • schema (schema, required): Existing schema type to modify

s.optional(schema)

Makes a schema type optional.

  • schema (schema, required): Existing schema type to modify

s.extend(schema, options)

Extends schema type with optional description and name.

  • schema (schema, required): Existing schema type to modify
  • options:
    • name (string, optional): The name of the type
    • description (string, optional): Description of the property
import * as s from 'agentscript-ai/schema';
 
const user = s.object({
  name: 'User',
  props: {
    name: s.string({description: "Name of the user"}),
    email: s.string({description: "Email of the user"})
  }
});
 
const nullableUser = s.nullable(user);
const optionalName = s.extend(s.string(), {description: "Optional name"});

Important Note on Types

Please be careful when defining schemas, especially for tool input types, as they are used for:

  1. Runtime type-checking of generated code
  2. Tool parameter validation
  3. Helping the LLM understand data structure
  4. Generating correct code