adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

FunctionResponse event contents are given role="user"

Open dannovikov opened this issue 1 year ago • 4 comments

Describe the bug FunctionResponse event contents are given role="user". Because of this, before_model_callbacks that parse llmrequest.contents looking for user events must check that both role="user" and function_response = None to identify user messages. Solely filtering for role='user' includes both user messages and function responses.

To Reproduce Steps to reproduce the behavior: Create a before model callback, and iterate llm_request.contents looking for user events.

def before_model_callback(callback_context, llm_request):
    for idx, content in enumerate(llm_request.contents):
        if content.role=='user':
            print(content)

and give it to an agent with a tool.

Run the agent, asking it to call the tool. Then, after it responds, run the agent again asking it something else. The second time, observe the output of the before_model_callback, and you'll see that in includes function responses.

Expected behavior Instead, I expect function responses to come from role="system".

Desktop (please complete the following information):

  • OS: Windows 11
  • Python version(python -V): 3.13.3
  • ADK version(pip show google-adk): 1.8.0

Model Information: AzureOpenAI gpt-4o-mini

Additional Information FunctionCall events are given role='model', which makes sense. And it makes sense that FunctionResponse are not role='model', but I think it also shouldn't be role='user'.

dannovikov avatar Jul 31 '25 21:07 dannovikov

https://github.com/google/adk-python/blob/a54c7024cf19740951282659bff491e5e46de66e/src/google/adk/flows/llm_flows/functions.py#L512

This is where the role "user" is being assigned

dannovikov avatar Jul 31 '25 21:07 dannovikov

This is working as intended. function_response is provided by user.

The true meaning is that model ask user to execute a function_call with given parameters, so from LLM's perspective, the function_response is a message from user indicating that "I'm done and here is my result for you".


system has other meaning, it doesn't mean the software system. It actually means the context for the entire conversation, e.g.

  • LLM should be polite and verbose or be concise and cool;
  • LLM should know some context of this user (e.g. name, age, etc) and apply it the entire conversation.

Jacksunwei avatar Jul 31 '25 23:07 Jacksunwei

What about including a role of type tool?

paward35 avatar Aug 15 '25 22:08 paward35

Could this role="user" behavior for FunctionResponse messages potentially confuse an orchestrator agent that is managing both tool calls and user I/O?

For example, in a multi-agent setup where the root agent coordinates sub-agents as tools that also use tools, having tool outputs use role="user" can make it harder to distinguish between real user messages and intermediate tool responses.

marttinslucas avatar Nov 07 '25 15:11 marttinslucas