PHPackages                             descom/ai-core - 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. descom/ai-core

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

descom/ai-core
==============

A Laravel module for AI core functionalities

1.2.0(2w ago)02MITPHPPHP ^8.4CI passing

Since May 21Pushed 2w agoCompare

[ Source](https://github.com/descom-es/ai-core)[ Packagist](https://packagist.org/packages/descom/ai-core)[ RSS](/packages/descom-ai-core/feed)WikiDiscussions main Synced 1w ago

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

Ai
==

[](#ai)

[![tests](https://github.com/descom-es/ai-core/actions/workflows/tests.yml/badge.svg)](https://github.com/descom-es/ai-core/actions/workflows/tests.yml)[![static analysis](https://github.com/descom-es/ai-core/actions/workflows/static-analysis.yml/badge.svg)](https://github.com/descom-es/ai-core/actions/workflows/static-analysis.yml)[![lint](https://github.com/descom-es/ai-core/actions/workflows/lint.yml/badge.svg)](https://github.com/descom-es/ai-core/actions/workflows/lint.yml)

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

[](#installation)

```
composer require descom/ai-core
```

Usage
-----

[](#usage)

`BedrockClientConverse` is the wrapper around AWS Bedrock's Converse API. The recommended way to use it is through the `Agent` abstraction; you can also instantiate the client directly when you need finer control over the message history.

### 1. Recommended flow — extend `Agent`

[](#1-recommended-flow--extend-agent)

Define an agent by extending `Descom\Ai\Bedrock\Converse\Agent` and providing a model id, a system prompt and the list of tools (empty array if you don't use any):

```
use Descom\Ai\Bedrock\Converse\Agent;

final class SupportAgent extends Agent
{
    protected string $modelId = 'anthropic.claude-3-haiku-20240307-v1:0';

    public function systemPrompt(): ?string
    {
        return 'You are a customer-support assistant.';
    }

    public function tools(): array
    {
        return [];
    }
}
```

`Agent` exposes three convenience helpers that build the `Messages` collection for you:

```
$agent = new SupportAgent();

$response = $agent->ask('How do I reset my password?');
$response = $agent->sendImage('/path/to/screenshot.png', 'What error is shown?');
$response = $agent->sendDocument('/path/to/invoice.pdf', 'Summarize this invoice.');

echo $response->output()->message->text();
echo $response->usage()->totalTokens;
echo $response->metrics()->latencyMs;
```

### 2. Direct use of `BedrockClientConverse`

[](#2-direct-use-of-bedrockclientconverse)

When you need to build a custom message history (multi-turn conversation, mixed roles, replayed transcripts) instantiate the client directly with an `Agent` and call `request()`:

```
use Descom\Ai\Bedrock\Converse\BedrockClientConverse;
use Descom\Ai\Bedrock\Messages\Contents\Contents;
use Descom\Ai\Bedrock\Messages\Contents\TextContent;
use Descom\Ai\Bedrock\Messages\Message;
use Descom\Ai\Bedrock\Messages\Messages;
use Descom\Ai\Bedrock\Messages\Role;

$client = new BedrockClientConverse(new SupportAgent());

$messages = new Messages([
    new Message(Role::USER, new Contents([new TextContent('Hi!')])),
    new Message(Role::ASSISTANT, new Contents([new TextContent('Hello, how can I help?')])),
    new Message(Role::USER, new Contents([new TextContent('I forgot my password.')])),
]);

$response = $client->request($messages);
```

### 3. Multi-modal message (image + text in a single turn)

[](#3-multi-modal-message-image--text-in-a-single-turn)

A single message can carry several content items. Combine `TextContent` with `ImageContent`, `DocumentContent` or `AudioContent`, and choose `BinarySource` (raw bytes) or `S3Source` (objects stored in S3):

```
use Descom\Ai\Bedrock\Messages\Contents\ImageContent;
use Descom\Ai\Bedrock\Messages\Contents\Sources\BinarySource;

$contents = new Contents([
    new TextContent('What is in this picture?'),
    new ImageContent('png', new BinarySource(file_get_contents('photo.png'))),
]);

$messages = new Messages([new Message(Role::USER, $contents)]);

$response = $client->request($messages);
```

### 4. Tool calling

[](#4-tool-calling)

Define a tool by implementing `Descom\Ai\Tools\ToolsContract`:

```
use Descom\Ai\Tools\ToolsContract;

final class GetWeatherTool implements ToolsContract
{
    public function __construct(public object|array $arguments) {}

    public function run(object|array $parameters): bool|string|array
    {
        return "Sunny, 25C in {$parameters['location']}";
    }
}
```

Then expose it from your agent's `tools()` method. Each entry describes the JSON schema sent to Bedrock and the PHP class that handles invocations:

```
public function tools(): array
{
    return [[
        'name' => 'get_weather',
        'description' => 'Get current weather for a location',
        'parameters' => [
            'type' => 'object',
            'properties' => [
                'location' => ['type' => 'string', 'description' => 'City name'],
            ],
            'required' => ['location'],
        ],
        'tool_action' => [
            'class' => GetWeatherTool::class,
            'arguments' => [],
        ],
    ]];
}
```

When the model returns a `tool_use` stop reason, `BedrockClientConverse::request()` automatically runs the tool, appends its result to the conversation and re-calls the model — your code only needs to read the final `Response`.

### 5. Inspecting the response

[](#5-inspecting-the-response)

`request()` returns a `Descom\Ai\Bedrock\Messages\Response\Response` with typed accessors:

```
$response->output()->message->text();      // assistant text
$response->output()->message->toolUses();  // ToolUseContent[]
$response->stopReason()->value;            // 'end_turn', 'tool_use', ...
$response->usage()->inputTokens;
$response->usage()->outputTokens;
$response->usage()->totalTokens;
$response->metrics()->latencyMs;
```

### 6. Error handling

[](#6-error-handling)

Any AWS SDK exception raised during the underlying `converse()` call is wrapped in `BedrockRequestException`. The original exception is preserved as `$previous`, and the offending request payload is exposed on the `payload` property for debugging:

```
use Descom\Ai\Bedrock\Converse\Exceptions\BedrockRequestException;

try {
    $response = $agent->ask('Hello');
} catch (BedrockRequestException $e) {
    Log::error('Bedrock call failed', [
        'message' => $e->getMessage(),
        'payload' => $e->payload,
    ]);
    throw $e;
}
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance96

Actively maintained with recent releases

Popularity3

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Every ~0 days

Total

3

Last Release

19d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25681494?v=4)[Cesar Garcia](/maintainers/cesargb)[@cesargb](https://github.com/cesargb)

---

Top Contributors

[![cesargb](https://avatars.githubusercontent.com/u/25681494?v=4)](https://github.com/cesargb "cesargb (13 commits)")

---

Tags

laravelmoduletoolsaws-bedrockai-core

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

### Embed Badge

![Health badge](/badges/descom-ai-core/health.svg)

```
[![Health](https://phpackages.com/badges/descom-ai-core/health.svg)](https://phpackages.com/packages/descom-ai-core)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

9782.1M153](/packages/laravel-ai)[moonshine/moonshine

Laravel administration panel

1.3k239.9k72](/packages/moonshine-moonshine)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45344.0k1](/packages/pressbooks-pressbooks)[linkxtr/laravel-qrcode

A clean, modern, and easy-to-use QR code generator for Laravel

3614.9k](/packages/linkxtr-laravel-qrcode)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.2k](/packages/tomshaw-electricgrid)

PHPackages © 2026

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