Skip to content

[BUG]: Inifinite loop when using code_executor #3921

@yuval-k

Description

@yuval-k

Describe the bug
When the LLM returns a code block to execute, it goes to an infinite loop and never returns. This used to work in v1.16.0 and doesn't work on main.

To Reproduce

Run this agent:

from google.adk import Agent
from google.adk.code_executors import UnsafeLocalCodeExecutor

root_agent = Agent(
    model='gemini-2.0-flash',
    name='hello_world_agent',
    description=(
        'hello world agent.'
    ),
    instruction="""
      you are an agent that knows how to produce python code.
    """,
  code_executor=UnsafeLocalCodeExecutor(),
)

and give a prompt that would make it return a code block. For example:

write python code that computes 2+2.

You will see this repeats ∞ times in the logs.

2025-12-15 13:50:54,034 - INFO - _client.py:1740 - HTTP Request: POST https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent "HTTP/1.1 200 OK"
2025-12-15 13:50:54,034 - INFO - google_llm.py:246 - Response received from the model.
2025-12-15 13:50:54,076 - INFO - google_llm.py:181 - Sending out request, model: gemini-2.0-flash, backend: GoogleLLMVariant.GEMINI_API, stream: False
2025-12-15 13:50:54,077 - INFO - models.py:7039 - AFC is enabled with max remote calls: 10.
2025-12

Expected behavior

Agent returns the executed code.

Screenshots
N/A

Desktop (please complete the following information):

  • OS: Linux Fedora 43, Docker (python:3.13-slim)
  • Python Python 3.14.2 and 3.13
  • ADK version: this bug happened when i updated to v1.18. also tested on 1.20 and 1.21.
    Model Information:
  • Are you using LiteLLM: Yes/No
  • Which model is being used(e.g. gemini-2.5-pro)

Additional context
The issue seems to happen because the code execution event from the session doesn't make it back to the LLM when the content is prepared in

. I suspect it gets filtered somehow

Metadata

Metadata

Assignees

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions