Skip to content

TLS 配置

当 Agent 需要被 HTTPS 页面调用时,必须启用 TLS。

地址协议

协议gRPCWebSocket适用场景
a2a://普通 gRPCws://开发环境、内网
a2as://gRPC + TLSwss://生产环境、HTTPS 页面

Server 端配置

使用 a2as:// 协议并提供证书配置:

typescript
const config: AgentConfig = {
  agentId: 'my-agent',
  name: 'My Agent',
  version: '1.0.0',
  description: '支持 TLS 的 Agent',

  // 使用 a2as:// 协议启用 TLS
  address: 'a2as://0.0.0.0:50061',

  // TLS 证书配置
  tls: {
    cert: '/etc/ssl/certs/agent.pem',
    key: '/etc/ssl/private/agent-key.pem',
    ca: '/etc/ssl/certs/ca.pem',  // 可选
  },

  skills: [...],
  defaultSkill: 'execute',
}

const server = createAgentServer(config)
await server.start()
// gRPC: grpcs://0.0.0.0:50061
// WebSocket: wss://0.0.0.0:50062

Client 端连接

typescript
// HTTP 页面(开发环境)
const client = createAgentClient({
  agentId: 'chat-agent',
  address: 'a2a://localhost:50054',  // ws://
})

// HTTPS 页面(生产环境)
const client = createAgentClient({
  agentId: 'chat-agent',
  address: 'a2as://agent.example.com:50054',  // wss://
})

TLSConfig 类型

typescript
interface TLSConfig {
  cert: string   // 证书文件路径(PEM 格式)
  key: string    // 私钥文件路径(PEM 格式)
  ca?: string    // CA 证书文件路径(可选)
}

提示

配置 a2as:// 要提供 tls,否则启动会报错:

Error: [Server] TLS is required (a2as://) but no tls config provided

MIT Licensed