Skip to content

Fix: Prevent empty additional_args from being added to agent prompt #1566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jokokojote
Copy link
Contributor

@jokokojote jokokojote commented Jul 16, 2025

Description

Fixes empty additional_args dictionaries being added to agent prompts unnecessarily. The current implementation checks if additional_args is not None, but doesn't verify if the dictionary actually contains any items.

Problem

  1. Empty dictionaries were being added to prompts, unnecessarily increasing token usage
  2. ToolCallingAgent was receiving Python arguments instructions despite not being able to execute Python code

Example prompt when using a nested multi agent strcuture like CodeAgent -> ToolCallingAgent (Managed Agent)

You're a helpful agent named 'web_agent'.
You have been submitted this task by your manager.
---
Task:
Find at least 3 notable Batman filming locations around the world. For each location, provide the city and country.
---
You're helping your manager solve a wider task: so make sure to not provide a one-line answer, but give as much information as possible to give them a clear understanding of the answer.

Your final_answer WILL HAVE to contain these parts:
### 1. Task outcome (short version):
### 2. Task outcome (extremely detailed version):
### 3. Additional context (if relevant):

Put all these in your final_answer tool, everything that you do not pass as an argument to final_answer will be lost.
And even if your task resolution is not successful, please return as much context as possible, so that your manager can act upon this feedback.
You have been provided with these additional arguments, that you can access using the keys as variables in your python code:
{}.

Solution

Changed the condition from if additional_args is not None to if additional_args to only add the additional arguments message when the dictionary is both not None and not empty.




Edit: Quality / format checks and tests run suscessfully.

This increased context size could lead to confusion, especially as ToolCallingAgents cannot execute Python code anyway, but nevertheless the line was added to the prompt.
Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

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

Thanks! Good catch!

@albertvillanova albertvillanova merged commit dc27c4a into huggingface:main Jul 16, 2025
3 checks passed
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.

2 participants