- PHP 8.4 or newer.
- Composer 2.x.
- Extensions:
pdo,pdo_sqlite,mbstring,json.
From this repository:
composer installAs a dependency:
composer require arcp/arcpuse Amp\Cancellation;
use Arcp\Auth\AuthRouter;
use Arcp\Auth\NoneAuth;
use Arcp\Client\ARCPClient;
use Arcp\Messages\Session\Auth;
use Arcp\Messages\Session\Capabilities;
use Arcp\Messages\Session\PeerInfo;
use Arcp\Runtime\ARCPRuntime;
use Arcp\Runtime\JobContext;
use Arcp\Runtime\ToolHandler;
use Arcp\Transport\MemoryTransport;
$runtime = new ARCPRuntime(authRouter: new AuthRouter([new NoneAuth()]));
$runtime->registerTool('echo', new class implements ToolHandler {
public function invoke(array $arguments, JobContext $ctx, ?Cancellation $cancellation = null): mixed
{
return ['echoed' => $arguments];
}
});
[$serverTransport, $clientTransport] = MemoryTransport::pair();
$server = $runtime->serveAsync($serverTransport);
$client = new ARCPClient($clientTransport);
$client->open(Auth::none(), new PeerInfo('demo', '0.1'), new Capabilities(anonymous: true));
$result = $client->invokeTool('echo', ['hello' => 'php']);
print_r($result->value);
$client->close();
$server->await();Start a runtime:
bin/arcp serve --host 127.0.0.1 --port 8765Invoke a tool:
bin/arcp send ws://127.0.0.1:8765 echo -a '{"hello":"php"}'StdioTransport frames envelopes as newline-delimited JSON. It is best
for subprocess agents where the parent process owns the client and the
child owns the runtime.
Sample programs live under ../samples/. They are kept
small and protocol-focused.