Skip to content
Closed
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 @@ -181,7 +181,7 @@ def execute_code(
{
'name': f.name,
'content': f.content,
'mimeType': f.mime_type,
'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 @@ -355,6 +355,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