Skip to main content

AHP Host

The Agent Host Protocol (AHP) lets you start a listener managed by the Copilot runtime and accept remote clients over WebSocket or GitHub Mission Control. An AHP host is owned by its Client connection. Stopping the listener with Client::stop() or the host’s dispose() does not delete the sessions the host used.

Starting a host

Pass at least one of localServer or githubEnvironment. An authentication mode is also required. To allow anonymous access, you must explicitly pass none.
localServer: [] uses a loopback address and a free port. githubEnvironment requires github authentication. Treat the token returned by the host as a connection secret. workspace is the working directory used by the AHP host. The Copilot runtime resolves this path on the host where the runtime runs, so it may differ from the path inside your Laravel application. When you omit it, the SDK does not include workspace in the RPC call and the runtime keeps its existing behavior.

Authentication modes

  • AhpHostAuthentication::github() authenticates with a GitHub account. You can combine it with githubEnvironment.
  • AhpHostAuthentication::none() explicitly disables authentication.
  • AhpHostAuthentication::custom() validates admission tokens with your own application logic. It requires a stable owner identity and a validation callback.
The custom authentication callback receives a HostValidateAuthenticationRequest containing the decrypted admission token, and a CancellationToken that signals cancellation. On success, return the identity and a future expiresAt in RFC3339 format. To reject the token, return null. The identity must exactly match requireIdentity.
The admission token is a separate credential from the GitHub token or provider token used for inference. Do not store it in logs or session config. The callback’s signal is cancelled when the host receives host.authenticationCancelled or shuts down. If the callback calls external services, register abort handling with onCancellationRequested().

Session creation policy

allowCreatingNewSessions sets the initial policy for remote clients creating new sessions. When omitted, remote session creation is denied. The policy does not apply to sessions created by the owning application, published sessions, or existing connections. To change the policy while the host is running, call the host’s setSessionCreationPolicy(). The new policy applies to requests that arrive after the change is acknowledged. Creation requests that were already accepted can complete. Connected clients are not disconnected.
When using RPC directly, call $client->rpc()->host()->setSessionCreationPolicy() and pass a HostSetSessionCreationPolicyRequest with the hostId and the new setting.

Application-owned sessions

Pass createSession and resumeSession callbacks to hand requests from the AHP host to your application’s Client. Each callback receives a HostMaterializeSessionRequest containing the runtime-verified HostSessionAuthentication and the host-provided config, plus a CancellationToken for cooperative cancellation. Return a session created or resumed with the same Client.
onSessionReleased receives the session whose participation ended. The SDK does not disconnect or destroy the session. HostMaterializeSessionRequest::$authentication is a trusted identity verified by the host, not client input. Still perform any tenant or user authorization you need inside the callback.

Session catalog and shutdown

Unpublishing removes the session from the AHP catalog. It does not delete local history or stop running work. dispose() stops the listener but does not delete related sessions.
Last modified on October 26, 2026