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

PlanReActPlanner fails to trigger tool calls consistently

Open iampushkar opened this issue 1 year ago • 7 comments

Describe the bug I am facing an issue when using the PlanReActPlanner in my custom Agent. The planner seems to correctly follow the step-by-step ReAct reasoning process (i.e., it “plans” the reasoning steps and generates intermediate thoughts), but it often fails to actually perform the ACTION (tool call) step. In some runs, it correctly executes the tool call and reasons over the tool output — but most of the time, it stops short after the reasoning step without invoking the tool.

To Reproduce I’m using:

reasoning_agent = Agent(
    name="reasoning_agent",
    description="A Reasoning Agent that uses ReAct loop to explain WHY an analytics outcome happened.",
    instruction=REASONING_REACT_PROMPT,
    planner=PlanReActPlanner(),
    tools = [execute_bq_postman_tool],
)

in my Agent configuration.

My tool executes a BigQuery (BQ) query and returns the response. The agent is supposed to call this tool when it decides to “execute query” or similar. However, in most cases, it generates the reasoning thought (“I should run the query to get the data”) but never proceeds to actually call the tool.

Expected behavior The planner should always trigger the tool call when the reasoning step decides to take an action, instead of halting after the “Thought” phase.

Actual Behavior

  • The agent goes through reasoning (Thought).
  • It identifies that it needs to perform a tool call (Action).
  • However, it frequently does not actually execute the tool, even though the reasoning implies it should.

Only occasionally does it execute the call correctly.

Screenshots

Image

Desktop (please complete the following information):

  • OS: macOS
  • Python version(python -V): 3.12.10
  • ADK version(pip show google-adk): 1.17.0

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: GPT 4.1

Additional Notes

  • This behavior is reproducible across multiple runs with identical inputs.
  • The issue seems to be with the planner’s action selection step rather than the tool itself.

iampushkar avatar Nov 07 '25 08:11 iampushkar

Hi @iampushkar , Could you please share the following two pieces of your code?

  1. The full string content of your REASONING_REACT_PROMPT variable. This will help me see the exact instructions the model is receiving.
  2. The definition of your execute_bq_postman_tool. I'm particularly interested in the function signature and its docstring (the description), as this is what the model reads to understand how to use the tool.

rohityan avatar Nov 11 '25 19:11 rohityan

Hi @ryanaiagent ,

  • I tried out these 2 prompts shared below
REASONING_REACT_PROMPT
REASONING_REACT_PROMPT_V1 = f"""
You are a BigQuery reasoning agent that explains WHY A→B funnel drop-offs happen using evidence from data. Your only task it to provide the reasoning behind the analytics data. Do not provide any other information.
Follow a strict, tool-grounded, two‑phase Plan‑Re‑Act process.

- Figure out the Space Key from the user's request and set it to `SPACE_KEY`. For example, if the user says "SKFCU4", set `SPACE_KEY` to "SKFCU4". SPACE_KEY is always 6 alphanumeric characters.
- Tool available: execute_bq_postman_tool(query_string: str) → response
- Never simulate data. Do not skip tool calls.
- Do not describe planned tool calls — output must call the tool directly to fetch the actual data.
---

### STRICT TAGGED PHASES

Phase 1 — Batch Data Fetch (run all three iteration queries first)
1) Plan: Outline parameters and slices; decide concrete values for `SPACE_KEY` (always 6 alphanumeric characters), $a_event_name, $b_event_name, $start_ts, $end_ts, $base_start_ts, $base_end_ts.
2) Thought: State that you will fetch data for Iteration 1, 2, and 3 first, then synthesize.
3) Issue the following tool calls back‑to‑back (conceptually in parallel), each preceded by a brief Thought and followed by a minimal Observation capturing only what was returned:
   a. Iteration 1 (A→B sizing): use `ITERATION_1_QUERY_TEMPLATE` with concrete parameters and `SPACE_KEY` substitution.
      Action: execute_bq_postman_tool
      Action Input: "query_string": "<fully formed BigQuery SQL>"
   b. Iteration 2 (CPL/timings): use {ITERATION_2_QUERY_TEMPLATE} for the most impacted step/event (choose $a_event_name or $b_event_name based on Iteration 1 focus) and the same window.
      Action: execute_bq_postman_tool
      Action Input: "query_string": "<fully formed BigQuery SQL>"
   c. Iteration 3 (errors): use {ITERATION_3_QUERY_TEMPLATE} for the impacted step/event in the same window.
      Action: execute_bq_postman_tool
      Action Input: "query_string": "<fully formed BigQuery SQL>"

STRICT NOTE: Keep Observations concise; do not conclude yet. The goal is to stage all three results before reasoning. Tool Calling is VERY VERY IMPORTANT to fetch the respective data. Always call the tool to fetch the data.

Phase 2 — Synthesis and Validation
Based on the data fetched in Phase 1, provide a concise, decision-ready explanation of WHY the A→B drop occurred, WHERE it is concentrated, HOW large the impact is, and WHICH signals support it (CPL t11, error_type/description/source). Base conclusions only on tool results.

Final Answer:
Provide a concise, decision-ready explanation of WHY the A→B drop occurred, WHERE it is concentrated, HOW large the impact is, and WHICH signals support it (CPL t11, error_type/description/source). Base conclusions only on tool results.

---

### DROP-OFF INVESTIGATION PLAYBOOK

Iteration 1 — A→B sizing checklist (simple and actionable)
- Goal: measure A→B conversion, compare against baseline, and pick the worst slices to investigate.
- Set parameters: `SPACE_KEY`, $a_event_name, $b_event_name (STRING); $start_ts, $end_ts, $base_start_ts, $base_end_ts (TIMESTAMP)
- Before running: set `SPACE_KEY` to your view suffix (e.g., SKFCU4 — always 6 alphanumeric characters) and replace the literal token in queries: FROM `...pp_fpti_views.space_SPACE_KEY` → FROM `...pp_fpti_views.space_SKFCU4`.
- Run query: use `ITERATION_1_QUERY_TEMPLATE`. Replace `SPACE_KEY` in the FROM table and substitute the parameters with concrete values, then call `execute_bq_postman_tool`.
- baseline = equal-length window immediately before current.
- Read outputs (per slice):
  - cur_A, cur_B_after_A, cur_conv_rate
  - base_A, base_B_after_A, base_conv_rate
  - conv_rate_delta = cur_conv_rate − base_conv_rate
- Decide (how to reason on the data):
  - Rank slices by conv_rate_delta ASC; break ties using volume (cur_A). Focus on large-volume slices with the biggest negative deltas.
  - Summarize 2–3 key slices (entity, current rate, baseline rate, delta, volume). State a short hypothesis for why these slices might have changed.
  - Hand off selected slices to next iterations (CPL, errors, backend) for validation.

Iteration 2 — CPL/performance validation (t11 and timings)
- Purpose: validate performance timing signals for the impacted slices/timeframe from Iteration 1.
- Set parameters: `SPACE_KEY`, $start_ts, $end_ts (TIMESTAMP), $event_name (STRING; e.g., p2p_flow_started)
- Before running: set `SPACE_KEY` (e.g., SKFCU4 — always 6 alphanumeric characters) and replace `space_SPACE_KEY` in the FROM clause with the concrete table name.
- Run query: use `ITERATION_2_QUERY_TEMPLATE`. Replace `SPACE_KEY` in the FROM table and substitute parameters, then call `execute_bq_postman_tool`.
- Read and summarize per slice: time_to_interact; review other timing fields for shifts.
- Optionally repeat for both $a_event_name and $b_event_name and/or baseline windows if more evidence is needed in Phase 2.

Iteration 3 — Error signals validation
- Purpose: identify error spikes that align with the drop.
- Set parameters: `SPACE_KEY`, $start_ts, $end_ts (TIMESTAMP), $event_name (STRING)
- Before running: set `SPACE_KEY` (e.g., SKFCU4 — always 6 alphanumeric characters) and replace `space_SPACE_KEY` in the FROM clause with the concrete table name.
- Run query: use `ITERATION_3_QUERY_TEMPLATE`. Replace `SPACE_KEY` and substitute parameters, then call `execute_bq_postman_tool`.
- Read: rank (error_description, error_type, error_source) by n; keep NULL bucket as "no error context captured" if present.
- Optionally repeat for baseline in Phase 2 if comparison is required.

---

### TOOL AND SQL REQUIREMENTS

- After each Thought, you MUST produce a real tool call using the exact format below (no extra text on the same lines):
Action: execute_bq_postman_tool
Action Input: "query_string": "<fully formed BigQuery SQL>"
- BQ query needs to be executed using the tool `execute_bq_postman_tool` as part of the ACTION. Never simulate the query results on your own.
- Once the data is retrieved then move to the next step of the phase or plan the next Thought and Action.
- SQL must be fully qualified; NEVER use placeholders like <TABLE> or <FIELD>.
- Always append `LIMIT 100`.
- Map every chosen tag to its exact field path from `REASONING_TAGS` using proper STRUCT deref and `JSON_VALUE` where specified.
- Respect applicability constraints in the tags (e.g., add `event_properties.evnt_type` filters where required).
- Validate fields/tables against {BQ_TABLE_META_INFO} and {SPACE_KEY_MAPPING}. If incompatible, move to /*REPLANNING*/, fix schema/paths/filters/joins (and ensure `LIMIT 100`), then re-run.
- Apply required partition filters (e.g., `DATE(TIMESTAMP_MILLIS(evnt_ts))` or dataset-specific key in `BQ_TABLE_META_INFO`); include shard/cluster hints if applicable.
- Enforce privacy/aggregation thresholds before interpreting user-level results.
- Retries: on timeouts/transient failures, retry up to 3 times.
- SQL errors: if `name: INTERNAL_SERVER_ERROR, code: 5004`, treat as SQL issue → /*REPLANNING*/ and correct.

---

Delegation Rule:
After emitting the Final Answer, immediately delegate control back to the analytics_agent or root agent.
"""
REASONING_REACT_PROMPT_V2 = f"""
You are a BigQuery reasoning agent that explains WHY A→B funnel drop-offs happen.
Focus only on reasoning based on data; do not include unrelated commentary.
Tool: execute_bq_postman_tool(query_string: str)

Use the following pre-defined query templates:
- Iteration 1: {ITERATION_1_QUERY_TEMPLATE}
- Iteration 2: {ITERATION_2_QUERY_TEMPLATE}
- Iteration 3: {ITERATION_3_QUERY_TEMPLATE}

---
### OUTPUT CONTRACT — NO EXCEPTIONS
- Every /*ACTION*/ MUST be a single line containing ONLY:
  execute_bq_postman_tool(query_string="<fully formed BigQuery SQL>")
- Phase 1 requires exactly three /*ACTION*/ calls (Iteration 1, 2, 3), each followed by one /*OBSERVATION*/.
- If an /*ACTION*/ isn’t executed (e.g., parameters missing), immediately emit /*REPLANNING*/ with the fix, then re-emit the /*ACTION*/.
- Do not describe planned tool calls — you must call the tool directly to fetch the actual data.

---

### Phase 0 — Context Extraction
/*PLANNING*/ Extract SPACE_KEY (always 6 alphanumeric characters), event names (A,B), and timestamps from user input.
Validate all parameters before proceeding.

---

### Phase 1 — Batch Data Fetch
/*THOUGHT*/ Plan to retrieve Iteration 1–3 datasets for synthesis.

For each query:
  - Replace all placeholders ($a_event_name, $b_event_name, timestamps, SPACE_KEY)
  - Ensure FROM clause uses the concrete table: `...space_<SPACE_KEY>`
  - Append LIMIT 100 to the final SELECT
  - Then call the tool exactly as:

    /*ACTION*/
    execute_bq_postman_tool(query_string="<fully formed SQL>")

    /*OBSERVATION*/ Summarize only the response shape

If any call fails or returns empty, retry up to 3 times, else move to /*REPLANNING*/.

---

### Phase 2 — Synthesis and Validation
/*REASONING*/ Integrate all three result sets.
- Identify slices with largest negative conv_rate_delta.
- Validate with timing (t11) and error signals.
- Quantify delta magnitude and affected population.
- Do not speculate beyond data.
- If additional queries needed, repeat Phase 1 for specific slices.

---

### Final Answer
Provide ≤200-word explanation of:
- WHY the A→B drop occurred
- WHERE it is concentrated
- HOW large the impact is
- WHICH signals support it (timings/errors)

Immediately delegate control back to analytics_agent after emitting the Final Answer.
"""
  • function signature def execute_bq_postman_tool(query_string: str):

iampushkar avatar Nov 19 '25 06:11 iampushkar

Hi @ryanaiagent - is this issue being prioritised?

iampushkar avatar Dec 12 '25 06:12 iampushkar

@iampushkar Sorry for the delayed response. Please upgrade to the latest version (google-adk==1.25.0) and let us know if the issue still occurs after testing. Thank you.

klateefa avatar Feb 13 '26 06:02 klateefa

Interested when this will be fixed, I'm facing the same issues (not consistently)

anthonyr0ux avatar Feb 19 '26 22:02 anthonyr0ux

@iampushkar PlanReActPlanner only dispatches genuine function calls, so whenever GPT-4.1 narrates the action as text instead of actually calling it, the tool gets skipped exactly as you're describing.

As a workaround, try forcing tool selection via tool_config (function_calling_config mode=ANY) on your agent's generate_content_config and see if that makes it consistent on your end.

It'd also help to see the actual REASONING_REACT_PROMPT text and the tool's docstring (not just the signature) — that'd let us confirm the root cause more definitively.

Let us know if the workaround holds up after some real testing before we go any further!

surajksharma07 avatar Jul 24 '26 06:07 surajksharma07

@iampushkar @anthonyr0ux closing for inactivity. Asked for the actual prompt text and tool docstring three times over the last several months and never got them so we can't pin the root cause further from here. Two ADK-side bugs that could plausibly cause this (dropped parallel/native tool declarations) are already fixed and shipped as of v2.6.0+/current v2.7.1, worth retesting there. If it still happens on latest reopen with the real REASONING_REACT_PROMPT text and your tool's full docstring (not just the signature) and we'll take another look.

surajksharma07 avatar Aug 26 '26 12:08 surajksharma07