use Cognesy\AgentCtrl\AgentCtrl;
use Cognesy\AgentCtrl\Dto\AgentResponse;
use Cognesy\AgentCtrl\Pi\Domain\Enum\ThinkingLevel;
$response = AgentCtrl::pi()
->withModel('sonnet')
->withThinking(ThinkingLevel::High)
->appendSystemPrompt('Focus on security and performance.')
->withTools(['read', 'bash', 'edit', 'grep'])
->withFiles(['/projects/app/src/Kernel.php'])
->withTimeout(300)
->inDirectory('/projects/app')
->onText(fn(string $text) => print($text))
->onToolUse(fn(string $tool, array $input, ?string $output) => print("\n> [{$tool}]\n"))
->onComplete(fn(AgentResponse $r) => print("\n--- Complete ---\n"))
->executeStreaming('Review the application architecture and suggest improvements.');
if ($response->isSuccess()) {
echo "\nReview completed successfully.\n";
echo "Tools used: " . count($response->toolCalls) . "\n";
$usage = $response->usage();
if ($usage !== null) {
echo "Tokens: {$usage->total()} (in: {$usage->input}, out: {$usage->output})\n";
}
$cost = $response->cost();
if ($cost !== null) {
echo sprintf("Cost: $%.6f\n", $cost);
}
} else {
echo "\nFailed with exit code: {$response->exitCode}\n";
}
// @doctest id="35bc"