PHP code example of bogdankharchenko / laravel-graphiti

1. Go to this page and download the library: Download bogdankharchenko/laravel-graphiti library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bogdankharchenko / laravel-graphiti example snippets


use BogdanKharchenko\Graphiti\Data\Message;
use BogdanKharchenko\Graphiti\Facades\Graphiti;

Graphiti::addMessages('team-eng', [
    new Message(
        content: $transcriptChunk,          // "Speaker: text" lines
        role: 'transcript',
        name: 'Standup 2026-08-06 (part 1/3)',
        timestamp: $meetingStartedAt,       // real-world time, not ingestion time
        sourceDescription: 'Tuple call transcript',
    ),
]);

$messages = LazyCollection::make(function () use ($calls) {
    foreach ($calls as $call) {
        yield from $this->toMessages($call);   // never all in memory at once
    }
});

$sent = Graphiti::addMessages('team-eng', $messages, chunkSize: 25);

$facts = Graphiti::search(
    'who owns metering?',
    groupIds: $user->allowedGroupIds(),   // always resolved server-side
    maxFacts: 15,
);

foreach ($facts as $fact) {
    $fact->fact;          // "Marcus Webb owns the metering work."
    $fact->isCurrent();   // false once superseded
    $fact->validAt;       // CarbonImmutable|null
    $fact->invalidAt;     // CarbonImmutable|null
}

Graphiti::episodes('team-eng', lastN: 10);   // Collection<Episode>, provenance content gainst them instead of inventing near-duplicates:
Graphiti::addEntityNode('team-eng', uuid: $person->id, name: 'Bogdan Kharchenko');

// Agent memory: facts relevant to an in-flight conversation
Graphiti::getMemory('team-eng', $recentMessages, centerNodeUuid: null, maxFacts: 10);

Graphiti::entityEdge($uuid);                 // one Fact by uuid
Graphiti::deleteEntityEdge($uuid);
Graphiti::deleteEpisode($uuid);
Graphiti::deleteGroup('dm-alice-bob');       // e.g. offboarding, data deletion requests
Graphiti::clearGraph();                      // wipes EVERYTHING — dev/test only
Graphiti::healthy();                         // bool, never throws

Http::fake(['*/search' => Http::response(['facts' => []])]);
sh
docker run --rm -v "$PWD":/app -w /app php:8.3-cli bash -c \
  "pecl install pcov && docker-php-ext-enable pcov && php vendor/bin/pest --coverage --min=100"