Skip to content

♻️ Feat: support a2a custom authorization - #3512

Merged
Dallas98 merged 10 commits into
developfrom
xyq/a2a_custom_authorization
Jul 28, 2026
Merged

♻️ Feat: support a2a custom authorization#3512
Dallas98 merged 10 commits into
developfrom
xyq/a2a_custom_authorization

Conversation

@xuyaqist

@xuyaqist xuyaqist commented Jul 27, 2026

Copy link
Copy Markdown
Contributor
  1. 获取agent card的时候支持填写自定义请求头
image image
  1. agent card会自动识别要填写的参数,支持apiKeySecurityScheme类型和httpAuthSecurityScheme类型
image
  1. 当agent支持多种认证鉴权方式时,支持用户自由选择
image

@xuyaqist
xuyaqist requested review from Dallas98 and WMC001 as code owners July 27, 2026 13:15
Copilot AI review requested due to automatic review settings July 27, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends Nexent’s A2A external-agent integration to support authenticated Agent Card discovery/refresh (via saved custom headers) and configurable per-agent call credentials derived from Agent Card security metadata.

Changes:

  • Add support for saving custom headers used only when fetching/refreshing an Agent Card.
  • Persist Agent Card security metadata and introduce an API + UI flow to store credential values and apply them to agent calls (header/query/cookie).
  • Add HTTP client support for params/cookies and raise a dedicated exception on non-2xx responses; update tests, docs, and i18n strings accordingly.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/backend/utils/test_a2a_http_client.py Adds coverage for non-2xx GET behavior via A2AHttpStatusError.
test/backend/services/test_a2a_client_service.py Updates URL-building tests; adds coverage for header forwarding, refresh behavior, and credential handling.
test/backend/database/test_a2a_agent_db.py Extends DB unit tests for new agent-card header and security metadata fields, plus secret-hiding behavior.
test/backend/consts/test_a2a_models.py Adds request-model tests for custom_headers acceptance and default behavior.
frontend/services/api.ts Adds client endpoint for updating agent security credentials.
frontend/services/a2aService.ts Adds types for security metadata and an API call to persist security credentials.
frontend/public/locales/zh/common.json Adds Chinese i18n strings for custom headers + authentication UI.
frontend/public/locales/en/common.json Adds English i18n strings for custom headers + authentication UI.
frontend/app/[locale]/agents/components/a2a/A2AAgentDiscoveryModal.tsx Adds custom headers input for discovery and an “Agent Authentication” popover for security schemes.
doc/docs/zh/user-guide/agent-development.md Documents custom discovery headers and the authentication configuration workflow (ZH).
doc/docs/en/user-guide/agent-development.md Documents custom discovery headers and the authentication configuration workflow (EN).
deploy/sql/migrations/v2.4.0_0727_add_a2a_agent_card_headers_and_security_fields.sql Adds JSONB columns for saved Agent Card headers and security metadata/credentials.
backend/utils/a2a_http_client.py Adds A2AHttpStatusError, non-2xx handling, and params/cookies support for POST requests.
backend/services/a2a_client_service.py Implements header persistence/usage for Agent Card fetch/refresh and credential application for agent calls.
backend/database/db_models.py Adds new JSON columns to A2AExternalAgent ORM model.
backend/database/a2a_agent_db.py Persists new fields, hides secrets by default, and adds an update method for credentials.
backend/consts/a2a_models.py Extends discovery request model with custom_headers.
backend/apps/a2a_client_app.py Plumbs custom_headers through discovery and adds a PUT endpoint to save security credentials.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread backend/services/a2a_client_service.py Outdated
Comment on lines 69 to 74
custom_headers = custom_headers or {}
async with A2AHttpClient() as client:
headers = build_a2a_headers()
if custom_headers:
headers.update(custom_headers)
card = await client.get_json(url, headers=headers)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已处理

Comment on lines 589 to +592
assert result == mock_result
mock_db.create_external_agent_from_url.assert_called_once()
assert mock_db.create_external_agent_from_url.call_args.kwargs["agent_card_headers"] == {}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改为assert mock_db.create_external_agent_from_url.call_args.kwargs["agent_card_headers"] is None

Comment on lines +693 to +697
credential = credentials.get(scheme_id)
scheme = schemes.get(scheme_id, {})
api_key_scheme = scheme.get("apiKeySecurityScheme", {}) if isinstance(scheme, dict) else {}
location = api_key_scheme.get("location")
parameter_name = api_key_scheme.get("name")
Comment on lines +77 to +80
const entries = Object.entries(schemes).flatMap(([schemeId, scheme]) => {
const apiKeyScheme = (scheme as Record<string, any>).apiKeySecurityScheme;
return apiKeyScheme ? [{ schemeId, ...apiKeyScheme }] : [];
});
"a2a.discovery.customHeadersLabel": "Custom Request Headers (Optional)",
"a2a.discovery.customHeadersTooltip": "Saved and used only to retrieve and refresh this Agent Card, never for agent calls.",
"a2a.discovery.customHeadersPlaceholder": "{\"Authorization\": \"Bearer <token>\"}",
"a2a.discovery.customHeadersInvalid": "Custom request headers must be a JSON object with string keys and values",
"a2a.discovery.customHeadersLabel": "自定义请求头(可选)",
"a2a.discovery.customHeadersTooltip": "会保存并仅用于获取和刷新 Agent Card,不会用于后续调用",
"a2a.discovery.customHeadersPlaceholder": "{\"Authorization\": \"Bearer <token>\"}",
"a2a.discovery.customHeadersInvalid": "自定义请求头必须是键和值均为字符串的 JSON 对象",
@xuyaqist xuyaqist changed the title Feat: support a2a custom authorization ♻️ Feat: support a2a custom authorization Jul 28, 2026
@codecov

codecov Bot commented Jul 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.86992% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/services/a2a_client_service.py 88.15% 5 Missing and 4 partials ⚠️
backend/database/a2a_agent_db.py 96.87% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Dallas98
Dallas98 merged commit 62a5227 into develop Jul 28, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants