Description
AgentEngineSandboxCodeExecutor does not work with any Gemini 2.x model (gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash). All models produce MALFORMED_FUNCTION_CALL errors when attempting code execution.
Root Cause
Gemini 2.x models always emit code as executable_code parts (native code execution format). However, the Gemini API rejects these parts with MALFORMED_FUNCTION_CALL because code_execution is not included in the tools configuration.
AgentEngineSandboxCodeExecutor expects the model to output code in markdown blocks (```python), which it can then parse and route to the Agent Engine sandbox. But Gemini 2.x models never use markdown blocks — they always use the native format.
Meanwhile, BuiltInCodeExecutor works correctly because it adds types.Tool(code_execution=types.ToolCodeExecution()) to the model's tool config, allowing the model to emit executable_code parts that the API accepts.
Steps to Reproduce
- Create an agent with
AgentEngineSandboxCodeExecutor and any Gemini 2.x model
- Deploy to Agent Engine
- Ask the agent to execute Python code (e.g., "Use Python code execution to compute 7 * 8 + 3 ** 4")
- Response returns
MALFORMED_FUNCTION_CALL error
Expected Behavior
AgentEngineSandboxCodeExecutor should add code_execution to the model's tool config (like BuiltInCodeExecutor does), then intercept the resulting executable_code parts and route them to the Agent Engine sandbox instead of letting the model execute them natively.
Note: CodeExecutionUtils.extract_code_and_truncate_content in ADK 1.29.0 already handles executable_code parts correctly — it just never gets a chance to run because the API rejects the model's response before ADK processes it.
Environment
- ADK version: 1.28.1 and 1.29.0
- Models tested:
gemini-2.5-pro, gemini-2.5-flash, gemini-2.0-flash
- Platform: Agent Engine (Vertex AI)
Description
AgentEngineSandboxCodeExecutordoes not work with any Gemini 2.x model (gemini-2.5-pro,gemini-2.5-flash,gemini-2.0-flash). All models produceMALFORMED_FUNCTION_CALLerrors when attempting code execution.Root Cause
Gemini 2.x models always emit code as
executable_codeparts (native code execution format). However, the Gemini API rejects these parts withMALFORMED_FUNCTION_CALLbecausecode_executionis not included in the tools configuration.AgentEngineSandboxCodeExecutorexpects the model to output code in markdown blocks (```python), which it can then parse and route to the Agent Engine sandbox. But Gemini 2.x models never use markdown blocks — they always use the native format.Meanwhile,
BuiltInCodeExecutorworks correctly because it addstypes.Tool(code_execution=types.ToolCodeExecution())to the model's tool config, allowing the model to emitexecutable_codeparts that the API accepts.Steps to Reproduce
AgentEngineSandboxCodeExecutorand any Gemini 2.x modelMALFORMED_FUNCTION_CALLerrorExpected Behavior
AgentEngineSandboxCodeExecutorshould addcode_executionto the model's tool config (likeBuiltInCodeExecutordoes), then intercept the resultingexecutable_codeparts and route them to the Agent Engine sandbox instead of letting the model execute them natively.Note:
CodeExecutionUtils.extract_code_and_truncate_contentin ADK 1.29.0 already handlesexecutable_codeparts correctly — it just never gets a chance to run because the API rejects the model's response before ADK processes it.Environment
gemini-2.5-pro,gemini-2.5-flash,gemini-2.0-flash