8000 RAG and function call cannot work together · Issue #1293 · google/adk-python · GitHub
[go: up one dir, main page]

Skip to content
RAG and function call cannot work together #1293
Closed
@frankfliu

Description

@frankfliu

Describe the bug
I'm trying to combine the built-in vertex rag tool together with function call. However, I got the following error:

HTTP Request: POST https://us-central1-aiplatform.googleapis.com/v1beta1/projects/frank-dev-1/locations/us-central1/publishers/google/models/gemini-2.0-flash-001:generateContent "HTTP/1.1 400 Bad Request"
Traceback (most recent call last):
  File "/Users/user01/source/adk/rag/main.py", line 61, in <module>
    asyncio.run(main())
  File "/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.11/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/user01/source/adk/rag/main.py", line 55, in main
    await run_prompt(query)
  File "/Users/user01/source/adk/rag/main.py", line 45, in run_prompt
    async for event in runner.run_async(
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/runners.py", line 197, in run_async
    async for event in invocation_context.agent.run_async(invocation_context):
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
    async for event in self._run_async_impl(ctx):
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/agents/llm_agent.py", line 278, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 279, in run_async
    async for event in self._run_one_step_async(invocation_context):
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 305, in _run_one_step_async
    async for llm_response in self._call_llm_async(
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 520, in _call_llm_async
    async for llm_response in llm.generate_content_async(
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/adk/models/google_llm.py", line 146, in generate_content_async
    response = await self.api_client.aio.models.generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/genai/models.py", line 6672, in generate_content
    response = await self._generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/genai/models.py", line 5674, in _generate_content
    response_dict = await self._api_client.async_request(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/genai/_api_client.py", line 789, in async_request
    result = await self._async_request(http_request=http_request, stream=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/genai/_api_client.py", line 733, in _async_request
    await errors.APIError.raise_for_async_response(response)
  File "/Users/user01/source/venv/lib/python3.11/site-packages/google/genai/errors.py", line 129, in raise_for_async_response
    raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 400 INVALID_ARGUMENT. {'error': {'code': 400, 'message': 'Request contains an invalid argument.', 'status': 'INVALID_ARGUMENT', 'details': [{'@type': 'type.googleapis.com/google.rpc.DebugInfo', 'detail': '[ORIGINAL ERROR] generic::invalid_argument: Last user prompt is empty. 525002922 { 6 { 4 { 1: "cloud-gemini-v3s" 3 { 2 { 1 { 1: "cloud-gemini-v3s" 2: 32767 3: 8192 } 1 { 1: "LC-1M-8K" 2: 1048575 3: 8192 } 2 { 1: "cloud-gemini-v3s" 2: 564 3: 1 } } } } } } 525003295 { 1 { 1 { 1 { 1: "blade:cloud.ai.nl.llm.proto.service.languagemodelservice-prod-us-central1" 2: "LanguageModelService" 3: "GenerateMultiModal" } 2 { 1: 3 2: "generic" 3: "Last user prompt is empty." 5 { 1 { 2: 525002922 3 { 6 { 4 { 1: "cloud-gemini-v3s" 3 { 2: "\\n\\031\\n\\020cloud-gemini-v3s\\020\\377\\377\\001\\030\\200@\\n\\021\\n\\010LC-1M-8K\\020\\377\\377?\\030\\200@\\022\\027\\n\\020cloud-gemini-v3s\\020\\264\\004\\030\\001" } } } } } } } 5: 1749593324787532 6: 1610583 8: 1 9: 1 } 2: "PredictionServiceV1beta1" 3: "GenerateContent" } }'}]}}

To Reproduce
Here is python code:

import logging

from google.adk.agents import Agent
from google.adk.tools.retrieval.vertex_ai_rag_retrieval import VertexAiRagRetrieval
from vertexai.preview import rag

from prepare_corpus_and_data import create_or_get_corpus

corpus = create_or_get_corpus("my_corpus")

ask_vertex_retrieval = VertexAiRagRetrieval(
    name='retrieve_rag_documentation',
    description=(
        'Use this tool to retrieve documentation and reference materials for the question from the RAG corpus,'
    ),
    rag_resources=[
        rag.RagResource(
            rag_corpus=corpus.name
        )
    ],
    similarity_top_k=10,
    vector_distance_threshold=0.6,
)


def get_first_name(
        user_id: str = "",
) -> str:
    logging.info("Executing get_first_name tool...")
    return "John"

def get_last_name(
        user_id: str = "",
) -> str:
    logging.info("Executing get_last_name tool...")
    return "Doe"

root_agent = Agent(
    model='gemini-2.0-flash-001',
    name='root_agent',
    instruction="""
    You are chatbot assistant, greeting users with their first name and last name if user_id is provided.
    Your role is to provide accurate and concise answers to questions based
    on documents that are retrievable using ask_vertex_retrieval. If you believe
    the user is just chatting and having casual conversation, don't use the retrieval tool.

    **Tools:**
    You have access to the following tools to assist you:

    *   get_first_name: This tool is used to get user's first name.
            The input parameters are:
            user_id: The user's ID.

    *   get_last_name: This tool is used to get user's last name.
            The input parameters are:
            user_id: The user's ID.

    """,
    # sub_agents=[retrieval_agent, get_first_name_agent, get_last_name_agent],
    tools=[ask_vertex_retrieval, get_first_name, get_last_name]
)

Expected behavior
Should not get 400 error.

Desktop (please complete the following information):

  • OS: macOS 15.5
  • Python version(python -V): 3.11.11
  • ADK version(pip show google-adk): 1.1.1

Additional context

  1. I tried multiple agents, it's working fine
  2. Use function call and RAG individually also works
  3. With combined RAG and function call, Initial model inference call works, but 2nd call with functionResponse failed
  4. Tried gemini-2.5, the same error.
  5. Tried use curl directly to gemini, got the same error:
curl -X POST "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent?key=$GEMINI_API_KEY" \
>     -H "Content-Type: application/json" \
>     -d @$HOME/bad.json
{
  "error": {
    "code": 400,
    "message": "Invalid JSON payload received. Unknown name \"retrieval\" at 'tools[0]': Cannot find field.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "tools[0]",
            "description": "Invalid JSON payload received. Unknown name \"retrieval\" at 'tools[0]': Cannot find field."
          }
        ]
      }
    ]
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0