<?php
require 'examples/boot.php';
use Cognesy\Agents\AgentLoop;
use Cognesy\Agents\Capability\Bash\BashTool;
use Cognesy\Agents\Data\AgentState;
use Cognesy\Agents\Events\Support\AgentEventConsoleObserver;
$logger = new AgentEventConsoleObserver(
useColors: true,
showTimestamps: true,
showToolArgs: true,
);
// Build loop with BashTool directly
$loop = AgentLoop::default()
->withTool(BashTool::inDirectory(getcwd()))
->wiretap($logger->wiretap());
$state = AgentState::empty()->withUserMessage(
'What is the current date and time? Also show the hostname and working directory. Be concise.'
);
echo "=== Agent Execution ===\n\n";
$finalState = $loop->execute($state);
echo "\n=== Result ===\n";
$response = $finalState->finalResponse()->toString() ?? 'No response';
echo "Answer: {$response}\n";
echo "Steps: {$finalState->stepCount()}\n";
echo "Tokens: {$finalState->usage()->total()}\n";
if ($finalState->status()->value !== 'completed') {
echo "Skipping assertions because execution status is {$finalState->status()->value}.\n";
return;
}
// Assertions
assert(!empty($finalState->finalResponse()->toString()), 'Expected non-empty response');
assert($finalState->stepCount() >= 1, 'Expected at least 1 step');
assert($finalState->usage()->total() > 0, 'Expected token usage > 0');
?>