CX Agent Studio: How to pass dynamic frontend session parameters to custom headers in an OpenAPI Tool

Hi there!

I am using CX Agent Studio with the web component (v1.16) and a Node.js AWS Lambda backend configured as an OpenAPI Tool (defined via an OpenAPI schema specification in the console).

Our application is a multi-tenant platform. On the frontend, we initialize the chat widget and pass tenant-specific runtime context using chatSdk.registerContext parameters like this:

chatSdk.registerContext(
  chatSdk.prebuilts.ces.createContext({
    deploymentName: 'projects/.../deployments/my-deployment-id',
    tokenBroker: { enableTokenBroker: true, enableRecaptcha: false },
    parameters: {
      company_origin: localStorage.getItem('ORIGIN'),
      user_role: localStorage.getItem('TIPO_USUARIO'),
      auth_status: 'logged_in'
    },
    enableWelcomeEvent: true,
  })
);

On our AWS Lambda backend, we process the incoming requests by extracting metadata directly from the API Gateway event headers:

exports.handler = async (event) => {
    if (event.headers) {
        // We successfully extract the token, but origin is always missing/undefined
        const origin = event.headers['x-company-origin'] || event.headers['X-Company-Origin'];
        const token = event.headers['x-auth-token'] || event.headers['X-Auth-Token'];
    }
    // ... database resolution and tool routing logic
};

The Problem:
When Gemini invokes the OpenAPI Tool, the request is executed server-side by Google (User-Agent: Google-CES).

We manually hardcoded the x-auth-token inside the Authentication section of the Tool settings in the Google Cloud Console, so that specific header arrives safely at AWS Lambda. However, we cannot do the same for company_origin because it must remain completely dynamic depending on the tenant currently interacting with the frontend.

Unfortunately, the custom parameter company_origin declared in registerContext never gets forwarded by Google into the HTTP request headers or the parameters object received by our Lambda payload.

My Questions:

  1. Inside CX Agent Studio OpenAPI Tool definition or agent instructions, is there a native method or variable syntax to map a dynamic session parameter (from registerContext) straight into a custom HTTP request header (like x-company-origin) for outbound server-side calls?
  2. If custom header injection of dynamic variables isn’t natively supported for OpenAPI tools, what is the standard recommended architecture to propagate frontend tenant context down to a server-side OpenAPI executor?

Any insights, workarounds, or documentation pointers on how to bridge registerContext session parameters with outbound OpenAPI Tool headers would be greatly appreciated.

Thanks!

1 Like