Skip to content

Expose Span Customization / Event Iteration for handle_ag_ui_request and other AG-UI functions #2639

@Snejj

Description

@Snejj

Description

When using handle_ag_ui_request() with instrument_all=True, there’s no official way to enrich telemetry spans before they’re emitted (e.g., adding request IDs, inputs/outputs). My attempts today either create duplicate spans or require subclassing Agent despite it being marked as final.

It would be useful if AG-UI exposed a hook or iterator similar to Agent.iter, something like e.g.:

run_input = RunAgentInput.model_validate(await request.json())
request_id = request.headers.get("X-Request-ID")

async def handler(events):
   async for event in events:
        event.span.set_attribute("request.id", request_id)
        event.span.set_attribute("run_input", run_input.json())
        yield event

return await handle_ag_ui_request(
    agent,
    request,
    event_stream_handler=handler,
)

This would make it easy to add metadata and integrate cleanly.

Metadata

Metadata

Assignees

Labels

StalequestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions