Skip to content

How do I pass authorization header to LlmAgent tool? #1816

Closed

Description

@matino

I have an instance that has a Runner object as a dependency. I want to pass the request "authorization" header value to the runner agent tool. As I understand, the correct way is to do it via session service (per #267). However, this doesn't work when I prefix the key with temp: (since I don't want to persist tokens).

        state_changes = {
            "temp:token": "<my token>",
        }
        actions_with_update = EventActions(state_delta=state_changes)
        system_event = Event(
            invocation_id="inv_login_update",
            author="system",  # Or 'agent', 'tool' etc.
            actions=actions_with_update,
        )

        await self.runner.session_service.append_event(session, system_event)

If I change the key from temp:token to user:token, the state is visible in the LlmAgent tool inside the ToolContext state.

Can somebody suggest a better approach?

Activity

  1. added
    services
    on Jul 7, 2025
  2. sindrigunnars commented on Jul 7, 2025

    @sindrigunnars
    Contributor

    I agree that the temp session key is fairly misleading. The way I've done this is just to make it user: specific. You could do some redis acrobatics with TTL to have it truly temporary or even write an empty value to it in the agent when you have retrieved it.

    Let me know if you have any other suggestions/fixed I may have missed.

  3. matino commented on Jul 8, 2025

    @matino
    ContributorAuthor

    I think another option would be to use the credential service. The Runner instance could call save_credentials, then the LLM tool could call load_credentials with tool_context._invocation_context.credential_service.load_credential(...). That's not super clean, but I guess it's more secure than persisting the token in the session service (even if only for a short while).

  4. sindrigunnars commented on Jul 8, 2025

    @sindrigunnars
    Contributor

    But does this solve the problem in the context of MCP tools?

  5. matino commented on Jul 8, 2025

    @matino
    ContributorAuthor

    But does this solve the problem in the context of MCP tools?

    I haven't used MCP tools, so can't really tell :/

  6. seanzhou1023 commented on Jul 8, 2025

    @seanzhou1023
    Collaborator

    the key prefixed with temp: won't be added to the session state. One thing you can do is that each time your tool read it your tool can remove it from the session state.

  7. seanzhou1023 commented on Jul 8, 2025

    @seanzhou1023
    Collaborator

    feel free to reopen if the above suggestion still doesn't work for you.

  8. self-assigned this
    on Jul 8, 2025
  9. matino commented on Jul 9, 2025

    @matino
    ContributorAuthor

    @seanzhou1023 Could you please help with reviewing/merging #1829? It would really help to use credential service for secrets instead of session service 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

services

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions