This directory contains examples showing how to use the A2A PHP server.
php examples/a2a.phpThe a2a.php file demonstrates:
- Creating a Message Handler - Implements
MessageHandlerInterfaceto process incoming messages - Setting up an Agent Card Provider - Implements
AgentCardProviderInterfaceto define agent capabilities - Creating HTTP Adapters - Implements
HttpRequestInterfaceandHttpResponseInterfacefor framework-agnostic HTTP handling - Initializing the Server - Sets up the A2A server with all required dependencies
- Handling Requests - Shows three examples:
- Getting the agent card
- Sending a message
- Listing tasks
To integrate with your preferred PHP framework:
Create adapters for your framework's request/response objects:
class LaravelHttpRequest implements HttpRequestInterface {
public function __construct(
protected \Illuminate\Http\Request $request
) {}
public function getMethod(): string {
return $this->request->method();
}
// ... implement other methods
}- TaskRepositoryInterface - Store and retrieve tasks (use database, Redis, etc.)
- MessageHandlerInterface - Process messages and generate responses
- AgentCardProviderInterface - Define your agent's capabilities
$server = new A2AServer(
taskRepository: new YourTaskRepository(),
messageHandler: new YourMessageHandler(),
agentCardProvider: new YourAgentCardProvider(),
);
$httpHandler = new A2AHttpHandler(
server: $server,
agentCardProvider: $agentCardProvider,
);
// In your route handler:
$httpHandler->handle($request, $response);message/send- Send messages and receive responsestasks/get- Retrieve a specific tasktasks/list- List all tasks with filteringtasks/cancel- Cancel a running taskagent/getAuthenticatedExtendedCard- Get agent capabilities
The server automatically serves the agent card at:
/.well-known/agent-card.json