goose icon indicating copy to clipboard operation
goose copied to clipboard

Propagate session ID in LLM and MCP requests

Open codefromthecrypt opened this issue 3 months ago • 2 comments

Summary

Adds goose-session-id header to HTTP requests and _meta.goose-session-id to MCP operations when a session exists. Enables external observability tools like Envoy AI Gateway to correlate requests by session without requiring OpenTelemetry in Goose.

Implementation:

  • Task-local storage for session context propagation
  • HTTP header injection in api_client (case-insensitive via reqwest)
  • MCP metadata injection preserving existing _meta fields (case-insensitive cleanup)
  • Integration and unit tests for both HTTP and MCP propagation

Example use case: Configure Envoy AI Gateway with OTEL_AIGW_SPAN_REQUEST_HEADER_ATTRIBUTES=goose-session-id:session.id to send traces to Arize Phoenix grouped by session.

Type of Change

  • [x] Feature
  • [ ] Bug fix
  • [ ] Refactor / Code quality
  • [ ] Performance improvement
  • [ ] Documentation
  • [ ] Tests
  • [ ] Security fix
  • [ ] Build / Release
  • [ ] Other (specify below)

Testing

added tests including an integrated one

Related Issues

Relates to https://github.com/envoyproxy/ai-gateway/issues/1221 which asked for this in other agent frameworks

codefromthecrypt avatar Oct 14 '25 16:10 codefromthecrypt

very flexible on this one, too, header naming.. whether it is configurable.. all that!

codefromthecrypt avatar Oct 14 '25 21:10 codefromthecrypt

thanks for the advice! I was AWOL but coming online again now. will touch this up tomorrow UTC+8

codefromthecrypt avatar Oct 28 '25 07:10 codefromthecrypt

ok rebased and also tried to shred the lines in a good way. if I made things worse lemme know

codefromthecrypt avatar Oct 30 '25 03:10 codefromthecrypt

cool I think the live provider red X is due to it not being on a protected branch. probably safe to review!

codefromthecrypt avatar Oct 30 '25 06:10 codefromthecrypt

over to you @jamadeo

michaelneale avatar Oct 31 '25 05:10 michaelneale