<?php
require 'examples/boot.php';
require_once dirname(__DIR__).'/Support.php';
use Cognesy\Agents\Capability\Cancellation\InMemoryCancellationSource;
use Cognesy\Tell\Tell;
use Cognesy\Tell\TellEvent;
use Cognesy\Tell\TellRequest;
$project = TellHarnessExample::project();
$cancellation = new InMemoryCancellationSource();
try {
$tell = Tell::open($project, cancellation: $cancellation);
$tell->workspace()->initialize();
$stream = $tell->runStream(
TellRequest::prompt('Inspect the project and report only actionable findings.')
->durable()
->maxSteps(5)
->maxRetries(1)
->timeoutMs(30_000)
->maxOutputChars(20_000)
->maxToolOutputChars(4_000)
->maxToolCalls(8)
->onEvent(static function (TellEvent $event): void {
// Safe for queues, logs, server-sent events, and telemetry.
echo json_encode($event->envelope(), JSON_THROW_ON_ERROR)."\n";
}),
);
foreach ($stream as $checkpoint) {
echo 'Completed steps: '.$checkpoint->stepCount()."\n";
}
$result = $stream->getReturn();
// A supervisor can call this while the loop is running. A cancelled
// durable run throws and leaves its selected workspace head unpublished.
// $cancellation->cancel('Job deadline reached');
assert($result->isCompleted(), 'Expected a bounded Tell run to complete.');
} finally {
TellHarnessExample::remove($project);
}