@@ -50,8 +50,11 @@ var sharedHTTPTransport = func() http.RoundTripper {
5050// CopilotRequestContext is the per-request context handed to every
5151// [CopilotRequestHandler] seam.
5252type CopilotRequestContext struct {
53- RequestID string
54- SessionID string
53+ RequestID string
54+ SessionID string
55+ AgentID string
56+ ParentAgentID string
57+ InteractionType string
5558 // Transport is "http" (covering plain HTTP and SSE) or "websocket".
5659 Transport string
5760 Method string
@@ -144,12 +147,12 @@ type CopilotWebSocketHandler interface {
144147
145148// copilotContextKey is used to attach [CopilotRequestContext] to an
146149// [http.Request] so custom [http.RoundTripper] implementations can access
147- // metadata (e.g. SessionID) without additional parameters.
150+ // metadata (e.g. SessionID and AgentID ) without additional parameters.
148151type copilotContextKey struct {}
149152
150153// RequestContextFrom returns the [CopilotRequestContext] attached to an
151154// http.Request by the adapter, or nil if not present. Call this from a custom
152- // [http.RoundTripper] to access metadata such as SessionID.
155+ // [http.RoundTripper] to access metadata such as SessionID and AgentID .
153156func RequestContextFrom (r * http.Request ) * CopilotRequestContext {
154157 v , _ := r .Context ().Value (copilotContextKey {}).(* CopilotRequestContext )
155158 return v
@@ -194,7 +197,7 @@ func buildHTTPRequest(rctx *CopilotRequestContext) (*http.Request, error) {
194197 return nil , err
195198 }
196199 // Attach rctx so custom RoundTripper implementations can read metadata
197- // (e.g. SessionID) via [RequestContextFrom].
200+ // (e.g. SessionID and AgentID ) via [RequestContextFrom].
198201 httpReq = httpReq .WithContext (context .WithValue (httpReq .Context (), copilotContextKey {}, rctx ))
199202 for name , values := range rctx .Headers {
200203 if isForbiddenRequestHeader (name ) {
@@ -615,14 +618,17 @@ func (a *copilotRequestAdapter) HttpRequestStart(params *rpc.LlmInferenceHTTPReq
615618 }
616619
617620 rctx := & CopilotRequestContext {
618- RequestID : params .RequestID ,
619- SessionID : sessionID ,
620- Method : params .Method ,
621- URL : params .URL ,
622- Headers : headers ,
623- Transport : transport ,
624- body : bodyCh ,
625- Context : ctx ,
621+ RequestID : params .RequestID ,
622+ SessionID : sessionID ,
623+ AgentID : stringOrEmpty (params .AgentID ),
624+ ParentAgentID : stringOrEmpty (params .ParentAgentID ),
625+ InteractionType : stringOrEmpty (params .InteractionType ),
626+ Method : params .Method ,
627+ URL : params .URL ,
628+ Headers : headers ,
629+ Transport : transport ,
630+ body : bodyCh ,
631+ Context : ctx ,
626632 }
627633 sink := & responseSink {requestID : params .RequestID , adapter : a , exchange : exchange }
628634 go a .runHandler (rctx , sink , exchange )
@@ -706,6 +712,13 @@ func (a *copilotRequestAdapter) removePending(requestID string) {
706712 a .mu .Unlock ()
707713}
708714
715+ func stringOrEmpty (value * string ) string {
716+ if value == nil {
717+ return ""
718+ }
719+ return * value
720+ }
721+
709722func decodeChunkData (data string , binary bool ) ([]byte , error ) {
710723 if binary {
711724 return base64 .StdEncoding .DecodeString (data )
0 commit comments