PHPackages                             bright/agent-schema - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bright/agent-schema

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bright/agent-schema
===================

The agent-schema providing flexible class to build ai agent tool schema

v1.0.0(3mo ago)00[2 PRs](https://github.com/GoBrightApps/agent-schema/pulls)MITPHPCI passing

Since Feb 8Pushed 1mo agoCompare

[ Source](https://github.com/GoBrightApps/agent-schema)[ Packagist](https://packagist.org/packages/bright/agent-schema)[ RSS](/packages/bright-agent-schema/feed)WikiDiscussions main Synced 2mo ago

READMEChangelog (1)Dependencies (6)Versions (3)Used By (0)

Schema Builder for AI Workflow
==============================

[](#schema-builder-for-ai-workflow)

A type-safe PHP library for building **Structured Outputs** schemas (based on JSON Schema).
Easily create, validate, and serialize schemas for AI Tooling/functions calling structured output.

Features
--------

[](#features)

- Fluent builder API (`Schema::string()->min(3)->max(20)`)
- Full support for JSON Schema types (`string`, `number`, `integer`, `boolean`, `array`, `object`, `enum`, `const`)
- Composition helpers (`anyOf`, `allOf`, `not`)
- Nullable support (`->nullable()`)
- Enum with type inference (`Schema::enum([...])->inferTypes()`)
- Type-safe object properties (`->property('name', Schema::string())`)
- Laravel-ready (`Arrayable`, `Jsonable`, `Stringable`)

---

Installation
------------

[](#installation)

```
composer require bright/agent-schema
```

---

Usage
-----

[](#usage)

### Simple string schema

[](#simple-string-schema)

```
use Agent\Schema;

$schema = Schema::string('User name')
    ->min(3)
    ->max(50)
    ->pattern('^[a-zA-Z ]+$');

echo $schema->toJson(JSON_PRETTY_PRINT);
```

Output:

```
{
    "type": "string",
    "description": "User name",
    "minLength": 3,
    "maxLength": 50,
    "pattern": "^[a-zA-Z ]+$"
}
```

---

### Object schema with properties

[](#object-schema-with-properties)

```
$schema = Schema::object("Schema for a user profile")
    ->required(['id', 'email'])
    ->property('id', Schema::string()->pattern('^[0-9]+$'), 'User ID')
    ->property('email', Schema::string()->format('email'), 'User email')
    ->property('age', Schema::integer()->min(18), 'User age')
    ->property('status', Schema::enum(['active', 'inactive', null])->inferTypes(), 'User status');
```

---

### Enums with type inference

[](#enums-with-type-inference)

```
Schema::enum(['draft', 'published']);                 // default "string"
Schema::enum([1, 2, 3])->inferTypes();                // auto → "integer"
Schema::enum([true, false, null])->inferTypes();      // auto → ["boolean","null"]
Schema::enum([1, "two"])->setType(["integer","string"]); // manual override
```

---

### Array schema

[](#array-schema)

```
$schema = Schema::array(Schema::string(), "Tags")
    ->min(1)
    ->max(5);
```

---

### Advanced composition

[](#advanced-composition)

```
$schema = Schema::allOf([
    Schema::object()->setName('base')->property('id', Schema::integer()),
    Schema::object()->setName('extra')->property('extra', Schema::string())
]);
```

---

Real Example: Function Schema
-----------------------------

[](#real-example-function-schema)

Here’s how you can directly pass a schema built with this package to structured outputs:

```
use OpenAI\Client;
use Agent\Schema;

$client = OpenAI::client('sk-your-api-key');

// Define schema for a weather function
$weatherSchema = Schema::object("Get the weather in a city")
    ->required(['location'])
    ->property('location', Schema::string("City name"))
    ->property('unit', Schema::enum(['celsius', 'fahrenheit'], "Temperature unit"));

// Build function definition
$function = [
    'name' => 'get_weather',
    'description' => 'Retrieve the current weather for a location',
    'parameters' => $weatherSchema->toArray(),
];

// Call OpenAI with structured function
$response = $client->chat()->create([
    'model' => 'gpt-4o-mini',
    'messages' => [
        ['role' => 'user', 'content' => 'What is the weather in Paris in celsius?']
    ],
    'tools' => [
        [
            'type' => 'function',
            'function' => $function
        ]
    ]
]);

print_r($response);
```

This will enforce that OpenAI returns structured JSON like:

```
{
    "location": "Paris",
    "unit": "celsius"
}
```

---

API Overview
------------

[](#api-overview)

- **`Schema::string($description)`**
    - `->minLength()`, `->maxLength()`, `->pattern()`, `->format()`, `->nullable()`
- **`Schema::number()` / `Schema::integer()`**
    - `->minimum()`, `->maximum()`, `->exclusiveMinimum()`, `->exclusiveMaximum()`, `->multipleOf()`
- **`Schema::boolean()`**
- **`Schema::enum([...])`**
    - `->setType()`, `->inferTypes()`, `->nullable()`
- **`Schema::array($itemsSchema)`**
    - `->minItems()`, `->maxItems()`
- **`Schema::object($description)`**
    - `->property($name, BaseSchema $schema, ?string $description)`
    - `->required([...])`
    - `->additional(bool)`
- **Combinators**
    - `Schema::anyOf([...])`
    - `Schema::allOf([...])`
    - `Schema::not($schema)`
    - `Schema::const($value)`

---

License
-------

[](#license)

MIT License

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance86

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 87.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

99d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1f8ebeaa5852b0579934881dcb0e479ab2c970960774be27e224db9ee005cffe?d=identicon)[saeedhosan](/maintainers/saeedhosan)

---

Top Contributors

[![saeedhosan](https://avatars.githubusercontent.com/u/78552486?v=4)](https://github.com/saeedhosan "saeedhosan (7 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

schemaaiAgenttoolsbright

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bright-agent-schema/health.svg)

```
[![Health](https://phpackages.com/badges/bright-agent-schema/health.svg)](https://phpackages.com/packages/bright-agent-schema)
```

###  Alternatives

[maestroerror/laragent

Power of AI Agents in your Laravel project

630106.4k](/packages/maestroerror-laragent)[helgesverre/extractor

AI-Powered Data Extraction for your Laravel application.

22128.0k](/packages/helgesverre-extractor)[symfony/ai-agent

PHP library for building agentic applications.

30536.7k44](/packages/symfony-ai-agent)[withcandour/aardvark-seo

Save time and get your Statamic site to rank better with the SEO addon for Statamic.

13128.3k](/packages/withcandour-aardvark-seo)[anilcancakir/laravel-ai-sdk-skills

A skill system for Laravel AI SDK agents. Define reusable AI capabilities with SKILL.md files.

151.1k](/packages/anilcancakir-laravel-ai-sdk-skills)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
