Skip to content

fix-issue 2407: replaced hard coded value for user_id to the value from the tool context from parent agent. #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

akshaypachpute-1998
Copy link

Description:

The AgentTool in /google/adk/tools/agent_tool.py uses a hardcoded user_id='tmp_user' when creating a new session for the agent it wraps. This happens within the run_async method.

code snippet
... @OverRide async def run_async( self, *, args: dict[str, Any], tool_context: ToolContext, ) -> Any: ... session = await runner.session_service.create_session( app_name=self.agent.name, user_id='tmp_user', # <-- This is hardcoded state=tool_context.state.to_dict(), ) ...

Why is this a problem?
This hardcoding breaks the chain of user identity. When a parent agent calls a sub-agent via the AgentTool, the original user_id is lost. Any tool or logic inside the sub-agent that needs to perform user-specific actions (e.g., accessing user data from a database, retrieving user-specific memory, checking permissions) will fail or operate on the wrong context because it receives 'tmp_user' instead of the actual user's ID.

Impact:
This prevents the creation of robust, multi-agent applications where user context must be maintained across different agents and tools. It limits the utility of AgentTool to only stateless sub-agents that do not require user-specific information.

Suggested Fix:
The user_id should be retrieved from the parent context, which is available via the tool_context parameter passed into run_async. The create_session call should be updated to use the dynamic user_id from the parent session.For example, the fix might involve accessing the user ID from the tool_context.

code-snippet
session = await runner.session_service.create_session( app_name=self.agent.name, user_id=tool_context._invocation_context.user_id, state=tool_context.state.to_dict(), )

To Reproduce
Steps to reproduce the behavior:
To reproduce this bug, we need to set up a two-agent system: a ParentAgent that calls a ChildAgent using the AgentTool. The ChildAgent will have a tool designed to simply return the user_id it receives from its context.

Expected behavior
It should return the user_id of the user calling the agent,

but, in current situation we are getting tmp_user

Copy link

google-cla bot commented Aug 7, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@adk-bot adk-bot added bot triaged [Bot] This issue is triaged by ADK bot tools [Component] This issue is related to tools labels Aug 7, 2025
@adk-bot adk-bot requested a review from seanzhou1023 August 7, 2025 10:08
@adk-bot
Copy link
Collaborator

adk-bot commented Aug 7, 2025

Response from ADK Triaging Agent

Hello @akshaypachpute-1998, thank you for your contribution!

Before we can merge this PR, could you please address the following points from our contribution guidelines:

  • Sign the Contributor License Agreement (CLA): It looks like the CLA check is failing. Please visit https://cla.developers.google.com/ to sign it.
  • Associate an Issue: All PRs, other than small documentation or typo fixes, should have an issue associated with them. If one doesn't exist, please create one and link it in the PR description.
  • Add a Testing Plan: Please include a testing plan section in your PR description to detail how you tested these changes. This helps reviewers understand and verify your work.

You can find more details in our CONTRIBUTING.md.

Thank you!

@akshaypachpute-1998
Copy link
Author

#2407 #2407

@akshaypachpute-1998 akshaypachpute-1998 changed the title replaced hard coded value for user_id to the value from the tool context from parent agent. fix-issue 2407: replaced hard coded value for user_id to the value from the tool context from parent agent. Aug 7, 2025
@akshaypachpute-1998
Copy link
Author

akshaypachpute-1998 commented Aug 7, 2025

Conversation:-
image

logs-after the change :-
image

results :-

[
{
"title": "Tomatina Festival", #record created before change
"description": "in Bu\u00f1ol, Valencia, Spain",
"time": "2025-08-20T12:00:00",
"created_at": "2025-08-07T13:58:58.036026",
"created_by": "tmp_user"
},
{
"title": "Tomatina Festival", #record created after change with web ui
"description": "The festival will be held on August 27, 2025, in the town of Bu\u00f1ol, Valencia, Spain.",
"time": "2025-08-20T12:00:00",
"created_at": "2025-08-07T14:04:09.024231",
"created_by": "user"
},
{
"title": "Tomatina festival", #record created after change with api
"description": "The festival will be held on August 27, 2025, in Bu\u00f1ol, Valencia, Spain.",
"time": "2025-08-20T12:00:00",
"created_at": "2025-08-07T14:12:18.411700",
"created_by": "akshay.pachpute"
}
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot triaged [Bot] This issue is triaged by ADK bot tools [Component] This issue is related to tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants