Skip to content

Commit 3466aa5

Browse files
authored
🐛 optimize content in step output
2 parents a320e92 + b9b6b08 commit 3466aa5

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

sdk/nexent/core/agents/core_agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def _step_stream(self, memory_step: ActionStep) -> Generator[Any]:
196196
raise AgentExecutionError(error_msg, self.logger)
197197

198198
truncated_output = truncate_content(str(output))
199-
observation += "Last output from code snippet:\n" + truncated_output
199+
if output is not None:
200+
observation += "Last output from code snippet:\n" + truncated_output
200201
memory_step.observations = observation
201202

202203
execution_outputs_console += [

test/sdk/core/agents/test_core_agent.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,6 +965,45 @@ def test_step_stream_execution_error_without_print_outputs(core_agent_instance):
965965
list(core_agent_instance._step_stream(mock_memory_step))
966966

967967

968+
def test_step_stream_execution_with_none_output(core_agent_instance):
969+
"""Test _step_stream method when execution returns None output."""
970+
# Setup
971+
mock_memory_step = MagicMock()
972+
mock_chat_message = MagicMock()
973+
mock_chat_message.content = "```<RUN>\nprint('hello')\n```<END_CODE>"
974+
975+
# Set all required attributes on the instance
976+
core_agent_instance.agent_name = "test_agent"
977+
core_agent_instance.step_number = 1
978+
core_agent_instance.grammar = None
979+
core_agent_instance.logger = MagicMock()
980+
core_agent_instance.memory = MagicMock()
981+
core_agent_instance.memory.steps = []
982+
983+
with patch.object(core_agent_module, 'parse_code_blobs', return_value="print('hello')"), \
984+
patch.object(core_agent_module, 'fix_final_answer_code', return_value="print('hello')"):
985+
986+
# Mock the methods directly on the instance
987+
core_agent_instance.write_memory_to_messages = MagicMock(
988+
return_value=[])
989+
core_agent_instance.model = MagicMock(return_value=mock_chat_message)
990+
# Mock python_executor to return None output
991+
core_agent_instance.python_executor = MagicMock(
992+
return_value=(None, "Execution logs", False))
993+
994+
# Execute
995+
result = list(core_agent_instance._step_stream(mock_memory_step))
996+
997+
# Assertions
998+
# Should yield None when is_final_answer is False
999+
assert result[0] is None
1000+
assert mock_memory_step.observations is not None
1001+
# Check that observations was set but should not contain "Last output from code snippet"
1002+
# since output is None
1003+
observations_str = str(mock_memory_step.observations)
1004+
assert "Execution logs:" in observations_str
1005+
assert "Last output from code snippet:" not in observations_str
1006+
9681007
# ----------------------------------------------------------------------------
9691008
# Tests for run method (lines 229-263)
9701009
# ----------------------------------------------------------------------------

0 commit comments

Comments
 (0)