Skip to content

PlanReActPlanner keeps only the first function call when a response starts with parallel calls #990

Closed

Description

@nniiovoo

Describe the bug
When a model response starts with several function calls, PlanReActPlanner.processPlanningResponse keeps only the first one. The other calls are dropped, so those tools do not run and the model gets no result for them. When text comes before the same calls, all of them are kept.

The check at plan_re_act_planner.ts#L69 is if (firstFcPartIndex > 0). Index 0 is a valid position (-1 means no call), but > 0 excludes it, so the loop that collects the following calls is skipped.

adk-python changed the same check to >= 0 in 054da5d. In this repo, #948 noted the difference and left the check as it was, because that PR was not meant to change what the planner classes do. The planners guide lists this behaviour under Limitations for SSE streaming, where the function calls arrive in a separate response. I think adk-js should follow current adk-python here.

To Reproduce
No API key needed; the model is a stub that returns two function calls.

  1. npm install @google/adk@2.2.0
  2. Save as repro.mjs:
import {
  BaseLlm,
  FunctionTool,
  InMemoryRunner,
  LlmAgent,
  PlanReActPlanner,
} from '@google/adk';

const calls = () =>
  ['get_weather', 'get_time'].map((name) => ({functionCall: {name, args: {}}}));
const callNames = (parts = []) =>
  parts.filter((part) => part.functionCall).map((p) => p.functionCall.name);

class StubLlm extends BaseLlm {
  constructor(replies) {
    super({model: 'stub'});
    this.replies = replies;
  }
  async *generateContentAsync() {
    yield {content: {role: 'model', parts: this.replies.shift()}};
  }
  async connect() {
    throw new Error('not used');
  }
}

async function run(label, firstReply) {
  const executed = [];
  const tool = (name) =>
    new FunctionTool({
      name,
      description: name,
      execute: async () => ({order: executed.push(name)}),
    });
  const agent = new LlmAgent({
    name: 'assistant',
    model: new StubLlm([firstReply, [{text: 'done'}]]),
    planner: new PlanReActPlanner(),
    tools: [tool('get_weather'), tool('get_time')],
  });
  const runner = new InMemoryRunner({agent, appName: 'repro'});
  const ids = {appName: 'repro', userId: 'u'};
  const session = await runner.sessionService.createSession(ids);
  console.log(label);
  console.log('  calls the model returned:', callNames(firstReply));
  for await (const event of runner.runAsync({
    userId: 'u',
    sessionId: session.id,
    newMessage: {role: 'user', parts: [{text: 'Weather and time in Paris?'}]},
  })) {
    const kept = callNames(event.content?.parts);
    if (kept.length) console.log('  calls in the event:      ', kept);
  }
  console.log('  tools executed:          ', executed);
}

await run('response starts with a function call', calls());
await run('text before the function calls', [{text: 'Plan.'}, ...calls()]);
  1. node repro.mjs
  2. Output:
response starts with a function call
  calls the model returned: [ 'get_weather', 'get_time' ]
  calls in the event:       [ 'get_weather' ]
  tools executed:           [ 'get_weather' ]
text before the function calls
  calls the model returned: [ 'get_weather', 'get_time' ]
  calls in the event:       [ 'get_weather', 'get_time' ]
  tools executed:           [ 'get_weather', 'get_time' ]

Expected behavior
The first case should give the same result as the second:

response starts with a function call
  calls the model returned: [ 'get_weather', 'get_time' ]
  calls in the event:       [ 'get_weather', 'get_time' ]
  tools executed:           [ 'get_weather', 'get_time' ]

Desktop (please complete the following information):

  • OS: macOS 26.4.1 (Apple M5)
  • TS version/environment: Node.js v26.8.2
  • ADK version: @google/adk 2.2.0 from npm; the same check is on main

Additional context
Changing > 0 to >= 0 fixes it. One unit test expects the old behaviour and the planners guide describes it, so both need updating. I have this ready with tests and can open a PR.

Activity

  1. Varun-S10 commented on Oct 6, 2026

    @Varun-S10
    Contributor

    Hi @nniiovoo, thank you for raising the issue and for submitting PR to fix it. We have reproduced the issue, and the PR will be reviewed. Thank you for your patience and understanding.

  2. added
    bug
    needs review
    on Oct 6, 2026
  3. added theissue type on Oct 6, 2026
  4. github-actions commented on Oct 6, 2026

    @github-actions

    Are you satisfied with the resolution of your issue?
    Yes
    No

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

Metadata

Metadata

Assignees

Labels

bugneeds review

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions