Propagate session ID in LLM and MCP requests
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
very flexible on this one, too, header naming.. whether it is configurable.. all that!
thanks for the advice! I was AWOL but coming online again now. will touch this up tomorrow UTC+8
ok rebased and also tried to shred the lines in a good way. if I made things worse lemme know
cool I think the live provider red X is due to it not being on a protected branch. probably safe to review!
over to you @jamadeo