Skip to content

fix(agents): subgraphWithTask & subtask missing tool results in prompt if other tools where requested along with finish tool#1971

Merged
EugeneTheDev merged 4 commits intodevelopfrom
eugenethedev/fix-subgraphwithtask-misssing-tool-results
May 8, 2026
Merged

fix(agents): subgraphWithTask & subtask missing tool results in prompt if other tools where requested along with finish tool#1971
EugeneTheDev merged 4 commits intodevelopfrom
eugenethedev/fix-subgraphwithtask-misssing-tool-results

Conversation

@EugeneTheDev
Copy link
Copy Markdown
Collaborator

In subgraphWithTask models can sometimes request other tools along with the finish tool. Previously, other tool results were ignored and not added to prompt, which led to error, since prompts can't have tool calls without matching tool results. Updated the subgraphWithTask logic to append all tool results when the finish tool was called

… tools where requested along with finish tool
@EugeneTheDev EugeneTheDev marked this pull request as ready for review May 8, 2026 13:23
result(toolCall.id, toolCall.tool, toolCall.content)
}
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think removing this might need more attention

  • executeFinishTool is called from AIAgentFunctionalContextBaseCommon.executeMultipleToolsHacked
  • which is called from two places: subtaskWithSingleToolMode and subtaskWithMultiToolMode

Both of these return immediately when the finish result is available:

// this happens in subtaskWithMultiToolMode
toolResults.firstOrNull { it.tool == finishTool.descriptor.name }
    ?.let { finishResult ->
        return finishResult.toSafeResult(finishTool, config.serializer).asSuccessful().result
    }

They don't have their version of finalizeTask that would append to prompt before returning, appending happened in this removed part here (so for these two scenarios we would end up with Tool.Call but without Tool.Result)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks, I will address it

Copy link
Copy Markdown
Collaborator Author

@EugeneTheDev EugeneTheDev May 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated subtasks in functional context too, added tests to verify

@EugeneTheDev EugeneTheDev changed the title fix(agents): subgraphWithTask missing tool results in prompt if other tools where requested along with finish tool fix(agents): subgraphWithTask & subtask missing tool results in prompt if other tools where requested along with finish tool May 8, 2026
Copy link
Copy Markdown
Collaborator

@Amaneusz Amaneusz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@EugeneTheDev EugeneTheDev merged commit 24f6695 into develop May 8, 2026
22 of 23 checks passed
@EugeneTheDev EugeneTheDev deleted the eugenethedev/fix-subgraphwithtask-misssing-tool-results branch May 8, 2026 21:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants