Skip to content

How to pass custom HTTP headers to ADK agents in Vertex Agent Engine? #5012

@shashankram

Description

@shashankram

I tried a bunch of things and have been unable to pass custom HTTP headers to an ADK agent running in Vertex Agent Engine. Is there a documented way to allow clients calling the Vertex Agent Engine's endpoint to passthrough custom headers required by the agent?

E.g., code where I try to set the state via the state attribute while creating the session. Note that headers is stripped out and there's nothing in the invocation_context.session.state

    # Create a new session
    response = requests.post(
        f"{BASE_URL}:query",
        headers=headers(),
        data=json.dumps(
            {
                "class_method": "async_create_session",
                "input": {
                    "user_id": USER_ID,
                    "state": {
                        "x-foo": "foo",
                    },
                },
            }
        ),
    )
    response.raise_for_status()
    session = response.json()
    print(f"Created session: {session}")

    session_id = session.get("session_id") or session.get("id")

    # Stream a query to the agent
    response = requests.post(
        f"{BASE_URL}:streamQuery",
        headers=headers(),
        data=json.dumps(
            {
                "class_method": "async_stream_query",
                "input": {
                    "user_id": USER_ID,
                    "session_id": session_id,
                    "message": "What can you do?",
                },
            }
        ),
        stream=True,
    )

Metadata

Metadata

Assignees

Labels

agent engine[Component] This issue is related to Vertex AI Agent Enginerequest clarification[Status] The maintainer need clarification or more information from the author

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions