Repository navigation
fix(code_executors): emit no empty event from BuiltInCodeExecutor - #7879
Open
adityasingh2400 wants to merge 1 commit into
Open
adityasingh2400 wants to merge 1 commit into
adityasingh2400 wants to merge 1 commit into
Conversation
The built-in branch of the code execution response processor yielded an event even when no image was saved. That event has no content and no actions, yet is_final_response() is True, so every reply was preceded by an empty "final" event, and a run loop that stops at the first final response (google#4138) never saw the model's answer. Only yield the event when it carries an artifact_delta.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
For
BuiltInCodeExecutor, the code execution response processor always yielded anEvent(actions=event_actions). When the response had no image to save, that event had no content and empty actions.is_final_response()still returnedTruefor it, and it was stored in the session.So every reply came with an empty "final" event in front of it. A run loop that stops at the first final response, as
is_final_response()is documented to support, got nothing back (#4138).Solution:
The event is only yielded when
event_actions.artifact_deltais non-empty, i.e. when an image was actually saved as an artifact. The image path is unchanged:artifact_delta.Testing Plan
Unit Tests:
Added
test_builtin_code_executor_emits_no_event_without_imagestotests/unittests/flows/llm_flows/extensions/test_code_execution.py, next totest_builtin_code_executor_image_artifact_creation. A text-only response yields no events, saves no artifact, and leaves the parts unchanged.pre-commit runpasses on the changed files.Manual End-to-End (E2E) Tests:
I ran
InMemoryRunnerwithLlmAgent(code_executor=BuiltInCodeExecutor())and a mock model that answers "The answer is 42.":Checklist
Additional context
#4138 was closed after the reporter worked around this, but the empty event is still emitted on
main.