GetAgentCard 处理 Agent Card 请求 GET /.well-known/{agentId}/agent-card.json
(c *gin.Context)
| 24 | // GetAgentCard 处理 Agent Card 请求 |
| 25 | // GET /.well-known/{agentId}/agent-card.json |
| 26 | func (h *Handler) GetAgentCard(c *gin.Context) { |
| 27 | ctx := c.Request.Context() |
| 28 | agentID := c.Param("agentId") |
| 29 | |
| 30 | if agentID == "" { |
| 31 | c.JSON(http.StatusBadRequest, gin.H{ |
| 32 | "success": false, |
| 33 | "error": gin.H{ |
| 34 | "code": "bad_request", |
| 35 | "message": "Missing agentId parameter", |
| 36 | }, |
| 37 | }) |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | logging.Info(ctx, "a2a.get_agent_card", map[string]any{ |
| 42 | "agent_id": agentID, |
| 43 | }) |
| 44 | |
| 45 | card, err := h.server.GetAgentCard(agentID) |
| 46 | if err != nil { |
| 47 | c.JSON(http.StatusNotFound, gin.H{ |
| 48 | "success": false, |
| 49 | "error": gin.H{ |
| 50 | "code": "not_found", |
| 51 | "message": "Agent not found: " + err.Error(), |
| 52 | }, |
| 53 | }) |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | // A2A 规范要求直接返回 Agent Card JSON,不包装在 success/data 中 |
| 58 | c.JSON(http.StatusOK, card) |
| 59 | } |
| 60 | |
| 61 | // HandleJSONRPC 处理 JSON-RPC 2.0 请求 |
| 62 | // POST /a2a/{agentId} |