Add exclude_params
feature to function_tool
for hidden parameter injection
#795
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds an
exclude_params
feature tofunction_tool
andfunction_schema
, allowing developers to hide specific parameters from the LLM while still making them available to the function with their default values.Motivation
When building AI agents for production systems, there's often a need to pass context-sensitive parameters (like timestamps, user IDs, or environment flags) to function tools without exposing these implementation details to the LLM. This is particularly important for evaluation scenarios where you want to ensure the agent behaves authentically without being influenced by "meta" parameters.
Use Case: Incident Response Bot Evaluation
Our primary use case is an incident response bot that reacts to PagerDuty alerts and investigates root causes using tools like
search_slack
. During evaluation, we run the bot against historical incidents to measure its performance. However, we face a critical challenge:The Problem:
The Solution:
We need to pass a
timestamp
parameter tosearch_slack
to filter results to only show messages available at incident time. However:Example Implementation:
With
exclude_params=['timestamp']
, the LLM only sees:The agent calls
search_slack("API errors in payment service")
while the function receives bothquery
and the pre-configuredtimestamp
.Implementation Details
exclude_params
parameter to bothfunction_schema()
andfunction_tool()
decoratorFiles Changed
src/agents/function_schema.py
: Core schema generation logicsrc/agents/tool.py
: function_tool decorator implementationdocs/tools.md
: Documentation and examplestests/test_function_schema.py
: Schema generation teststests/test_function_tool.py
: function_tool decorator testsBenefits