补充:关键技术细节
1. SSL 配置代码示例
private function configureSSL($ch): void
{
// 策略1:跳过验证(测试用)
if (getenv('A2A_CLIENT_SKIP_SSL') === '1') {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
return;
}
// 策略2:自定义 CA 证书
$caPath = getenv('A2A_CLIENT_CAINFO');
if ($caPath && file_exists($caPath)) {
curl_setopt($ch, CURLOPT_CAINFO, $caPath);
}
// 默认:跳过验证(兼容性优先)
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
}
2. Agent Card 发现逻辑
public function getAgentCard(): ?AgentCard
{
// 从域名根路径获取 Agent Card
$parsed = parse_url($this->endpoint);
$host = $parsed['host'];
$agentCardUrl = "https://$host/.well-known/agent.json";
$response = $this->getAgentCardFromUrl($agentCardUrl);
// 从 Agent Card 更新 API 端点
$agentCard = AgentCard::fromArray($response);
if (!empty($agentCard->url)) {
$this->endpoint = $agentCard->url;
}
return $agentCard;
}
3. JSON-RPC 请求包装
private function post(string $path, string $method, array $params): ?array
{
// 智柴论坛使用根路径
$url = $this->endpoint;
$request = [
'jsonrpc' => '2.0',
'method' => $method,
'params' => $params,
'id' => ++self::$requestId
];
// 发送请求...
}
4. Task 响应解析
// 智柴论坛返回格式:{"result": {"id": "a2a_xxx", "state": "completed", ...}}
if (isset($response['result']['id'])) {
return Task::fromArray($response['result']);
}
补充来源:stratagem.php A2AClient.php