-
Notifications
You must be signed in to change notification settings - Fork 659
fix(a2a): preserve protocol on card refresh, add custom headers and configurable timeout #3247
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d25ce51
9423398
c1570a4
58a1da1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,18 @@ | |
| ) | ||
|
|
||
|
|
||
| class UpdateAgentSettingsRequest(BaseModel): | ||
| """Request to update user-configurable settings for an external A2A agent.""" | ||
| custom_headers: Optional[dict] = Field( | ||
| default=None, | ||
| description="Custom HTTP headers as JSON object to send with agent requests" | ||
| ) | ||
| timeout: Optional[float] = Field( | ||
| default=None, | ||
| description="Request timeout in seconds (default: 300)" | ||
| ) | ||
|
|
||
|
|
||
| class TestNacosConnectionRequest(BaseModel): | ||
| """Request to test Nacos connectivity without saving the config.""" | ||
| nacos_addr: str = Field(description="Nacos server address (e.g., http://nacos-server:8848)") | ||
|
|
@@ -328,6 +340,59 @@ | |
| ) | ||
|
|
||
|
|
||
| @router.put("/agents/{external_agent_id}/settings") | ||
| async def update_agent_settings( | ||
| external_agent_id: int, | ||
| request: UpdateAgentSettingsRequest, | ||
| authorization: Annotated[Optional[str], Header()] = None, | ||
| http_request: Request = None | ||
| ): | ||
| """Update user-configurable settings for an external A2A agent. | ||
|
|
||
| Updates custom HTTP headers and/or request timeout. | ||
| These settings are preserved across agent card refreshes. | ||
|
|
||
| Args: | ||
| external_agent_id: The external agent database ID. | ||
| request: Request containing the settings to update. | ||
| """ | ||
| try: | ||
| _, tenant_id, _ = get_current_user_info(authorization, http_request) | ||
|
|
||
| result = a2a_client_service.update_agent_settings( | ||
| external_agent_id=external_agent_id, | ||
| tenant_id=tenant_id, | ||
| custom_headers=request.custom_headers, | ||
| timeout=request.timeout, | ||
| ) | ||
|
|
||
| if not result: | ||
| raise HTTPException( | ||
| status_code=HTTPStatus.NOT_FOUND, | ||
| detail=f"Agent {external_agent_id} not found" | ||
| ) | ||
|
|
||
| return JSONResponse( | ||
| status_code=HTTPStatus.OK, | ||
| content={"status": "success", "data": result} | ||
| ) | ||
|
|
||
| except HTTPException: | ||
| raise | ||
| except ValueError as e: | ||
| logger.error(f"Invalid settings: {e}") | ||
|
Check failure on line 383 in backend/apps/a2a_client_app.py
|
||
| raise HTTPException( | ||
| status_code=HTTPStatus.BAD_REQUEST, | ||
| detail=str(e) | ||
| ) | ||
| except Exception as e: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [代码规范] |
||
| logger.error(f"Update agent settings failed: {e}", exc_info=True) | ||
|
Check failure on line 389 in backend/apps/a2a_client_app.py
|
||
| raise HTTPException( | ||
| status_code=HTTPStatus.INTERNAL_SERVER_ERROR, | ||
| detail="Failed to update agent settings" | ||
| ) | ||
|
|
||
|
|
||
| # ============================================================================= | ||
| # External Agent Relations (Sub-agent) | ||
| # ============================================================================= | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| -- Migration: Add custom_headers and timeout columns to ag_a2a_external_agent_t | ||
| -- Date: 2026-06-17 | ||
| -- Description: Support custom HTTP headers and configurable timeout per A2A external agent. | ||
| -- - custom_headers: user-defined HTTP headers sent with every request to this agent | ||
| -- - timeout: per-agent request timeout in seconds (default 300) | ||
|
|
||
| SET search_path TO nexent; | ||
|
|
||
| BEGIN; | ||
|
|
||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS ( | ||
| SELECT 1 FROM information_schema.columns | ||
| WHERE table_schema = 'nexent' | ||
| AND table_name = 'ag_a2a_external_agent_t' | ||
| AND column_name = 'custom_headers' | ||
| ) THEN | ||
| ALTER TABLE nexent.ag_a2a_external_agent_t | ||
| ADD COLUMN custom_headers JSON DEFAULT NULL; | ||
|
|
||
| COMMENT ON COLUMN nexent.ag_a2a_external_agent_t.custom_headers | ||
| IS 'Custom HTTP headers as JSON object for A2A agent requests'; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| DO $$ | ||
| BEGIN | ||
| IF NOT EXISTS ( | ||
| SELECT 1 FROM information_schema.columns | ||
| WHERE table_schema = 'nexent' | ||
| AND table_name = 'ag_a2a_external_agent_t' | ||
| AND column_name = 'timeout' | ||
| ) THEN | ||
| ALTER TABLE nexent.ag_a2a_external_agent_t | ||
| ADD COLUMN timeout DOUBLE PRECISION DEFAULT 300.0; | ||
|
|
||
| COMMENT ON COLUMN nexent.ag_a2a_external_agent_t.timeout | ||
| IS 'Request timeout in seconds for calling this agent (default 300)'; | ||
| END IF; | ||
| END $$; | ||
|
|
||
| COMMIT; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
custom_headers允许用户设置任意 HTTP headers 发送给 A2A agent,但没有验证 header 内容。恶意或有误的用户可能设置Authorization、Host等敏感 header,覆盖系统默认行为或造成安全风险。建议添加 header 名称黑名单(如Authorization,Host,Content-Type)或白名单验证。