Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def execute_code(
input_data['files'] = [
{
'name': f.name,
'contents': f.content,
'mimeType': f.mime_type,
'content': f.content,
'mime_type': f.mime_type,
}
for f in code_execution_input.input_files
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from google.adk.agents.invocation_context import InvocationContext
from google.adk.code_executors.agent_engine_sandbox_code_executor import AgentEngineSandboxCodeExecutor
from google.adk.code_executors.code_execution_utils import CodeExecutionInput
from google.adk.code_executors.code_execution_utils import File
from google.adk.sessions.session import Session
import pytest

Expand Down Expand Up @@ -320,6 +321,54 @@ def test_execute_code_creates_sandbox_if_missing(
input_data={"code": 'print("hello world")'},
)

@patch("vertexai.Client")
def test_execute_code_sends_correct_field_names_for_input_files(
self,
mock_vertexai_client,
mock_invocation_context,
):
"""Input files are sent with 'content' and 'mime_type' keys (not 'contents'/'mimeType')."""
mock_api_client = MagicMock()
mock_vertexai_client.return_value = mock_api_client

mock_response = MagicMock()
mock_json_output = MagicMock()
mock_json_output.mime_type = "application/json"
mock_json_output.data = json.dumps({"msg_out": "", "msg_err": ""}).encode(
"utf-8"
)
mock_json_output.metadata = None
mock_response.outputs = [mock_json_output]
mock_api_client.agent_engines.sandboxes.execute_code.return_value = (
mock_response
)

executor = AgentEngineSandboxCodeExecutor(
sandbox_resource_name="projects/123/locations/us-central1/reasoningEngines/456/sandboxEnvironments/789"
)
code_input = CodeExecutionInput(
code="import pandas as pd; df = pd.read_csv('data.csv')",
input_files=[
File(
name="data.csv", content=b"col1,col2\n1,2", mime_type="text/csv"
)
],
)

executor.execute_code(mock_invocation_context, code_input)

mock_api_client.agent_engines.sandboxes.execute_code.assert_called_once_with(
name="projects/123/locations/us-central1/reasoningEngines/456/sandboxEnvironments/789",
input_data={
"code": "import pandas as pd; df = pd.read_csv('data.csv')",
"files": [{
"name": "data.csv",
"content": b"col1,col2\n1,2",
"mime_type": "text/csv",
}],
},
)

def test_init_with_agent_engine_resource_name(self):
"""Tests init when only agent_engine_resource_name is provided."""
agent_engine_name = (
Expand Down
Loading