Skip to content

Python: [Bug]: Foundry Hosted Agent Library - Unable to access metadata and client headers #5578

@ashishmundra4001

Description

@ashishmundra4001

Description

I am deploying my Agent to Foundry Hosted Agent.

I have a middleware like below:

class UserContextAgentMiddleware(AgentMiddleware):

    async def process(
        self,
        context: AgentContext,
        next: Callable[[], Awaitable[None]],
    ) -> None:

This is how I will invoke my Agent from Postman:
http://localhost:8088/responses
headers:
Authorization: Bearer ey
x-client-abc: some value
traceparent: 00-abc-01
body:
{
"agent": {
"name": "MyAgent",
"type": "agent_reference"
},
"stream": false,
"input": [
{"type": "message", "role": "user", "content": "Arrival time of Bus at IT."},
{"type": "message", "role": "assistant", "content": "in next 5 mins"},
{"type": "message", "role": "user", "content": "KRB."}
],
"metadata": {
"latitude": "1.2976",
"longitude": "103.7767",
"skipobo": "True",
"traceparent": "00-a0a00417202600001234cafeface5677-a0a0041720260001-01"
}
}

Earlier when I was using previous hosting adapter library (from azure.ai.agentserver.agentframework import from_agent_framework) I was able to read metadata sent in /responses api as below:

    if hasattr(context.agent, '_request_headers'):                
                    request_data = context.agent._request_headers

But now with this new library (from agent_framework_foundry_hosting import ResponsesHostServer), how can I read following in Middleware?

  • metadata
  • Authorization Header (so that I can get a OBO token in my agent which I will later send to my API tool)
  • x-client-* (for any additional headers that I will send to my API tool)
  • traceparent header - this is sent by caller of Agent and I want to maintain that (so that I can send that too to my API for end-to-end traceability from caller-Agent-Tools)

Code Sample

Error Messages / Stack Traces

Package Versions

agent-framework-core-1.2.2 agent-framework-foundry-hosting-1.0.0a260429

Python Version

Python 3.13

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions