-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.php
More file actions
97 lines (85 loc) · 2.56 KB
/
main.php
File metadata and controls
97 lines (85 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
declare(strict_types=1);
require __DIR__ . '/../../vendor/autoload.php';
use Amp\Cancellation;
use Arcp\Auth\AuthRouter;
use Arcp\Auth\NoneAuth;
use Arcp\Client\ARCPClient;
use Arcp\Envelope\Envelope;
use Arcp\Messages\Execution\JobAccepted;
use Arcp\Messages\Session\Auth;
use Arcp\Messages\Session\Capabilities;
use Arcp\Messages\Session\PeerInfo;
use Arcp\Runtime\ARCPRuntime;
use Arcp\Runtime\Credentials\InMemoryCredentialProvisioner;
use Arcp\Runtime\JobContext;
use Arcp\Runtime\ToolHandler;
use Arcp\Transport\MemoryTransport;
use Arcp\Transport\Transport;
$provisioner = new InMemoryCredentialProvisioner();
$runtime = new ARCPRuntime(
authRouter: new AuthRouter([new NoneAuth()]),
credentialProvisioner: $provisioner,
);
$runtime->registerTool('planner', new class () implements ToolHandler {
#[\Override]
public function invoke(array $arguments, JobContext $ctx, ?Cancellation $cancellation = null): mixed
{
$ctx->assertModelAllowed('anthropic/claude-3-5-sonnet');
return ['planned' => true];
}
});
[$serverT, $clientT] = MemoryTransport::pair();
$recording = new class ($clientT) implements Transport {
/** @var list<Envelope> */
public array $received = [];
public function __construct(private readonly Transport $inner)
{
}
#[\Override]
public function send(Envelope $env, ?Cancellation $cancellation = null): void
{
$this->inner->send($env, $cancellation);
}
#[\Override]
public function receive(?Cancellation $cancellation = null): ?Envelope
{
$env = $this->inner->receive($cancellation);
if ($env instanceof Envelope) {
$this->received[] = $env;
}
return $env;
}
#[\Override]
public function close(): void
{
$this->inner->close();
}
#[\Override]
public function isClosed(): bool
{
return $this->inner->isClosed();
}
};
$serverFuture = $runtime->serveAsync($serverT);
$client = new ARCPClient($recording);
$client->open(Auth::none(), new PeerInfo('provisioned-demo', '0.1'), new Capabilities(
anonymous: true,
features: ['provisioned-credentials', 'model.use'],
));
$result = $client->invokeTool('planner', [
'lease' => [
'model.use' => ['anthropic/*'],
'cost.budget' => ['USD:1.00'],
],
]);
foreach ($recording->received as $env) {
if ($env->payload instanceof JobAccepted) {
print_r($env->payload->credentials);
break;
}
}
print_r($result->value);
print_r(['revoked' => $provisioner->revoked]);
$client->close();
$serverFuture->await();