Skip to content

Add metadata to failed Agent Server responses - #49073

Open
banibrata-de wants to merge 3 commits into
Azure:mainfrom
banibrata-de:costcontrol-response-failure-metadata
Open

banibrata-de wants to merge 3 commits into
Azure:mainfrom
banibrata-de:costcontrol-response-failure-metadata

Conversation

@banibrata-de

@banibrata-de banibrata-de commented Sep 17, 2026

Copy link
Copy Markdown

Description

Adds optional validated metadata to ResponseEventStream.emit_failed. The metadata is merged with request-provided response metadata and follows the Responses limits of 16 keys, 64 characters per key, and 512 characters per value.

This enables hosting adapters and ordinary Agent Server handlers to attach structured failure details to the terminal response.failed snapshot while preserving the Responses transport contract. For example, a budget rejection can remain outer HTTP 200 while exposing error.code=budget_exceeded and string-valued metadata.costControl.

The change does not interpret HTTP headers or add CostControl-specific behavior to the generic SDK. The handler or hosting adapter remains responsible for selecting, sanitizing, and supplying public metadata.

Validation

  • Builder tests cover metadata merge, validation, usage, and request metadata preservation.
  • Contract tests cover terminal metadata through both stream=false JSON responses and stream=true SSE responses.
  • A live Agent Server probe confirmed an upstream HTTP 429 budget rejection becomes HTTP 200 plus response.failed, error.code=budget_exceeded, and bounded metadata.costControl.

All SDK Contribution checklist:

  • The pull request does not introduce [breaking changes]
  • CHANGELOG is updated for new features, bug fixes or other significant changes.
  • I have read the contribution guidelines.

General Guidelines and Best Practices

  • Title of the pull request is clear and informative.
  • There are a small number of commits, each of which have an informative message.

Testing Guidelines

  • Pull request includes test coverage for the included changes.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99113cf0-df56-4e0f-979a-a7d39a173e4d
@github-actions github-actions Bot added Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/* labels Sep 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thank you for your contribution banibrata-de! We will review the pull request and get back to you soon.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99113cf0-df56-4e0f-979a-a7d39a173e4d
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 99113cf0-df56-4e0f-979a-a7d39a173e4d
@banibrata-de
banibrata-de marked this pull request as ready for review September 18, 2026 04:28
Copilot AI balanced review requested due to automatic review settings September 18, 2026 04:28

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.

Copilot encountered an error: Your billing is not configured or you have Copilot licenses from multiple standalone organizations or enterprises. To use premium requests, select a billing entity via the GitHub site, under Settings > Copilot > Features.

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
7 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

raise ValueError(f"metadata value for key '{key}' exceeds the 512-character limit")
merged[key] = value

if len(merged) > 16:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what is driving these limits? could these limits change in the future?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Contribution Community members are working on the issue customer-reported Issues that are reported by GitHub users external to the Azure organization. Hosted Agents sdk/agentserver/*

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants