-
Notifications
You must be signed in to change notification settings - Fork 2.8k
fix:Bug #4133: AutomaticFunctionCallingConfig Settings Ignored #4137
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
base: main
Are you sure you want to change the base?
Conversation
…dling - Implement tests to verify behavior when AFC is disabled, including stopping the loop after the first response. - Validate that maximum_remote_calls configuration is respected, including edge cases for zero and negative values. - Ensure planner hooks are called correctly with various AFC settings. - Test AFC behavior in live streaming mode, confirming that configurations are enforced as expected. - Cover scenarios with parallel function calls and their impact on AFC limits.
Summary of ChangesHello @sajanlamsal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug where Automatic Function Calling (AFC) configuration settings, such as disabling AFC or limiting the number of remote calls, were being ignored. The fix introduces robust checks throughout the LLM flow to ensure these settings are respected, preventing unintended function executions and potential infinite loops. This change significantly improves the reliability and predictability of AFC behavior, aligning it with the intended API specification. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses the bug where Automatic Function Calling (AFC) settings were being ignored. The introduction of the _should_stop_afc_loop helper function is a good approach to centralize the control logic, and the pre-execution checks are correctly placed in the post-processing methods. The new test suite is comprehensive and provides excellent coverage for the fix. I have a couple of suggestions to further improve code readability and maintainability.
|
/gemini review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request effectively addresses Bug #4133 by correctly enforcing AutomaticFunctionCallingConfig settings and introduces a robust guardrail mechanism to prevent infinite loops in Automatic Function Calling (AFC). The changes are well-structured, thoroughly tested with comprehensive unit tests for both AFC configuration and guardrail functionality, and include detailed logging for observability. The implementation demonstrates careful consideration of edge cases and maintains backward compatibility. This is a significant improvement to the stability and predictability of the AFC system.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1. Link to an existing issue:
AutomaticFunctionCallingConfig(disable=True)is ignored - Planner hook bypassed #41332. Description of change:
Problem:
The Automatic Function Calling (AFC) loop ignored
AutomaticFunctionCallingConfig:disable=Truehad no effect and AFC continued runningmaximum_remote_callswas not enforcedSolution:
This PR implements two fixes:
AFC Configuration Enforcement
disable=Truenow prevents AFC execution and stops further AFC iterationsmaximum_remote_callsis enforced in bothrun_async()andrun_live()modesmaximum_remote_callsGuardrail Mechanism (Async Mode)
Real-world example:
An LLM searches for "unicorn startups in Antarctica". The tool returns empty results, but the LLM keeps retrying with variations. Without the guardrail: infinite loop. With the guardrail: after 3 refused calls, a final response such as "I couldn't find any unicorn startups in Antarctica" is returned and the loop ends.
Testing Plan
Unit Tests:
Coverage:
test_afc_config.py(20 tests): AFC disable flag andmaximum_remote_callsenforcement in async and live modestest_guardrail.py(12 tests): guardrail triggering, tool removal, AFC disabling, and final-response enforcementResults:
Manual End-to-End Tests:
Scenario 1:
disable=True✅ PASS
Scenario 2:
maximum_remote_calls=3(Previously: 20+ events due to infinite loop)
✅ PASS
Scenario 3: Guardrail triggered (persistent FCs)
✅ PASS
Checklist
Additional context
maximum_remote_callscounts LLM response events containing function calls, not individual tool invocations._should_stop_afc_loop()semantics and guardrail cleanup inrun_async().