mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
refactor: replace 'convo' naming with 'conversation' (#10473)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -171,7 +171,7 @@ async def test_set_agent_state(mock_agent_with_stats, mock_event_stream):
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -192,7 +192,7 @@ async def test_on_event_message_action(mock_agent_with_stats, mock_event_stream)
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -214,7 +214,7 @@ async def test_on_event_change_agent_state_action(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -238,7 +238,7 @@ async def test_react_to_exception(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
status_callback=mock_status_callback,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
@@ -263,7 +263,7 @@ async def test_react_to_content_policy_violation(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
status_callback=mock_status_callback,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
@@ -450,7 +450,7 @@ async def test_max_iterations_extension(mock_agent_with_stats, mock_event_stream
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -481,7 +481,7 @@ async def test_max_iterations_extension(mock_agent_with_stats, mock_event_stream
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -522,7 +522,7 @@ async def test_step_max_budget(mock_agent_with_stats, mock_event_stream):
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
budget_per_task_delta=10,
|
||||
sid='test',
|
||||
@@ -553,7 +553,7 @@ async def test_step_max_budget_headless(mock_agent_with_stats, mock_event_stream
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
budget_per_task_delta=10,
|
||||
sid='test',
|
||||
@@ -598,7 +598,7 @@ async def test_budget_reset_on_continue(mock_agent_with_stats, mock_event_stream
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
budget_per_task_delta=initial_budget,
|
||||
sid='test',
|
||||
@@ -654,7 +654,7 @@ async def test_reset_with_pending_action_no_observation(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -707,7 +707,7 @@ async def test_reset_with_pending_action_stopped_state(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -760,7 +760,7 @@ async def test_reset_with_pending_action_existing_observation(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -806,7 +806,7 @@ async def test_reset_without_pending_action(mock_agent_with_stats, mock_event_st
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -840,7 +840,7 @@ async def test_reset_with_pending_action_no_metadata(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -972,7 +972,7 @@ async def test_notify_on_llm_retry(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
status_callback=mock_status_callback,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
@@ -1484,7 +1484,7 @@ async def test_action_metrics_copy(mock_agent_with_stats):
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -1599,7 +1599,7 @@ async def test_condenser_metrics_included(mock_agent_with_stats, test_event_stre
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=test_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -1658,7 +1658,7 @@ async def test_first_user_message_with_identical_content(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=test_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -1726,7 +1726,7 @@ async def test_agent_controller_processes_null_observation_with_cause(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test-session',
|
||||
)
|
||||
@@ -1802,7 +1802,7 @@ def test_agent_controller_should_step_with_null_observation_cause_zero(
|
||||
controller = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
sid='test-session',
|
||||
)
|
||||
@@ -1828,7 +1828,7 @@ def test_system_message_in_event_stream(mock_agent_with_stats, test_event_stream
|
||||
_ = AgentController(
|
||||
agent=mock_agent,
|
||||
event_stream=test_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
)
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ async def test_delegation_flow(
|
||||
parent_controller = AgentController(
|
||||
agent=mock_parent_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=1, # Add the required iteration_delta parameter
|
||||
sid='parent',
|
||||
confirmation_mode=False,
|
||||
@@ -250,7 +250,9 @@ async def test_delegation_flow(
|
||||
) # verify local metrics are accessible via snapshot
|
||||
|
||||
# Check that the conversation stats has the combined metrics (parent + delegate)
|
||||
combined_metrics = delegate_controller.state.convo_stats.get_combined_metrics()
|
||||
combined_metrics = (
|
||||
delegate_controller.state.conversation_stats.get_combined_metrics()
|
||||
)
|
||||
assert (
|
||||
combined_metrics.accumulated_cost
|
||||
== 6 # Make sure delegate tracks global cost (2 from parent + 4 from delegate)
|
||||
@@ -303,7 +305,7 @@ async def test_delegate_step_different_states(
|
||||
controller = AgentController(
|
||||
agent=mock_parent_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=1, # Add the required iteration_delta parameter
|
||||
sid='test',
|
||||
confirmation_mode=False,
|
||||
@@ -394,7 +396,7 @@ async def test_delegate_hits_global_limits(
|
||||
parent_controller = AgentController(
|
||||
agent=mock_parent_agent,
|
||||
event_stream=mock_event_stream,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=1, # Add the required iteration_delta parameter
|
||||
sid='parent',
|
||||
confirmation_mode=False,
|
||||
|
||||
@@ -86,7 +86,7 @@ async def test_agent_session_start_with_no_state(
|
||||
sid='test-session',
|
||||
file_store=file_store,
|
||||
llm_registry=mock_llm_registry,
|
||||
convo_stats=mock_conversation_stats,
|
||||
conversation_stats=mock_conversation_stats,
|
||||
)
|
||||
|
||||
# Create a mock runtime and set it up
|
||||
@@ -178,7 +178,7 @@ async def test_agent_session_start_with_restored_state(
|
||||
sid='test-session',
|
||||
file_store=file_store,
|
||||
llm_registry=mock_llm_registry,
|
||||
convo_stats=mock_conversation_stats,
|
||||
conversation_stats=mock_conversation_stats,
|
||||
)
|
||||
|
||||
# Create a mock runtime and set it up
|
||||
@@ -276,7 +276,7 @@ async def test_metrics_centralization_via_conversation_stats(
|
||||
sid='test-session',
|
||||
file_store=file_store,
|
||||
llm_registry=mock_llm_registry,
|
||||
convo_stats=mock_conversation_stats,
|
||||
conversation_stats=mock_conversation_stats,
|
||||
)
|
||||
|
||||
# Create a mock runtime and set it up
|
||||
@@ -324,14 +324,16 @@ async def test_metrics_centralization_via_conversation_stats(
|
||||
)
|
||||
|
||||
# Verify that the ConversationStats is properly set up
|
||||
assert session.controller.state.convo_stats is mock_conversation_stats
|
||||
assert session.controller.state.conversation_stats is mock_conversation_stats
|
||||
|
||||
# Add some metrics to the agent's LLM (simulating LLM usage)
|
||||
test_cost = 0.05
|
||||
session.controller.agent.llm.metrics.add_cost(test_cost)
|
||||
|
||||
# Verify that the cost is reflected in the combined metrics from the conversation stats
|
||||
combined_metrics = session.controller.state.convo_stats.get_combined_metrics()
|
||||
combined_metrics = (
|
||||
session.controller.state.conversation_stats.get_combined_metrics()
|
||||
)
|
||||
assert combined_metrics.accumulated_cost == test_cost
|
||||
|
||||
# Add more cost to simulate additional LLM usage
|
||||
@@ -339,7 +341,9 @@ async def test_metrics_centralization_via_conversation_stats(
|
||||
session.controller.agent.llm.metrics.add_cost(additional_cost)
|
||||
|
||||
# Verify the combined metrics reflect the total cost
|
||||
combined_metrics = session.controller.state.convo_stats.get_combined_metrics()
|
||||
combined_metrics = (
|
||||
session.controller.state.conversation_stats.get_combined_metrics()
|
||||
)
|
||||
assert combined_metrics.accumulated_cost == test_cost + additional_cost
|
||||
|
||||
# Reset the agent and verify that combined metrics are preserved
|
||||
@@ -347,7 +351,7 @@ async def test_metrics_centralization_via_conversation_stats(
|
||||
|
||||
# Combined metrics should still be preserved after agent reset
|
||||
assert (
|
||||
session.controller.state.convo_stats.get_combined_metrics().accumulated_cost
|
||||
session.controller.state.conversation_stats.get_combined_metrics().accumulated_cost
|
||||
== test_cost + additional_cost
|
||||
)
|
||||
|
||||
@@ -366,7 +370,7 @@ async def test_budget_control_flag_syncs_with_metrics(
|
||||
sid='test-session',
|
||||
file_store=file_store,
|
||||
llm_registry=mock_llm_registry,
|
||||
convo_stats=mock_conversation_stats,
|
||||
conversation_stats=mock_conversation_stats,
|
||||
)
|
||||
|
||||
# Create a mock runtime and set it up
|
||||
@@ -466,7 +470,7 @@ def test_override_provider_tokens_with_custom_secret(
|
||||
sid='test-session',
|
||||
file_store=file_store,
|
||||
llm_registry=mock_llm_registry,
|
||||
convo_stats=mock_conversation_stats,
|
||||
conversation_stats=mock_conversation_stats,
|
||||
)
|
||||
|
||||
# Create test data
|
||||
|
||||
@@ -431,7 +431,7 @@ async def test_session_preserves_env_mcp_config(monkeypatch):
|
||||
config=config,
|
||||
sio=AsyncMock(),
|
||||
llm_registry=LLMRegistry(config=OpenHandsConfig()),
|
||||
convo_stats=ConversationStats(None, 'test-sid', None),
|
||||
conversation_stats=ConversationStats(None, 'test-sid', None),
|
||||
)
|
||||
|
||||
# Create empty settings
|
||||
|
||||
@@ -38,7 +38,7 @@ class MockLLM:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def convo_stats():
|
||||
def conversation_stats():
|
||||
return ConversationStats(None, 'convo-id', None)
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ class MockAgent(Agent):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_tool_timeout_error_handling(convo_stats):
|
||||
async def test_mcp_tool_timeout_error_handling(conversation_stats):
|
||||
"""Test that verifies MCP tool timeout errors are properly handled and returned as observations."""
|
||||
# Create a mock MCPClient
|
||||
mock_client = mock.MagicMock(spec=MCPClient)
|
||||
@@ -100,7 +100,7 @@ async def test_mcp_tool_timeout_error_handling(convo_stats):
|
||||
controller = AgentController(
|
||||
agent=agent,
|
||||
event_stream=event_stream,
|
||||
convo_stats=convo_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
budget_per_task_delta=None,
|
||||
sid='test-session',
|
||||
@@ -150,7 +150,7 @@ async def test_mcp_tool_timeout_error_handling(convo_stats):
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mcp_tool_timeout_agent_continuation(convo_stats):
|
||||
async def test_mcp_tool_timeout_agent_continuation(conversation_stats):
|
||||
"""Test that verifies the agent can continue processing after an MCP tool timeout."""
|
||||
# Create a mock MCPClient
|
||||
mock_client = mock.MagicMock(spec=MCPClient)
|
||||
@@ -189,7 +189,7 @@ async def test_mcp_tool_timeout_agent_continuation(convo_stats):
|
||||
controller = AgentController(
|
||||
agent=agent,
|
||||
event_stream=event_stream,
|
||||
convo_stats=convo_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
iteration_delta=10,
|
||||
budget_per_task_delta=None,
|
||||
sid='test-session',
|
||||
|
||||
@@ -612,7 +612,7 @@ async def test_conversation_instructions_plumbed_to_memory(
|
||||
sid='test-session',
|
||||
file_store=file_store,
|
||||
llm_registry=mock_llm_registry,
|
||||
convo_stats=ConversationStats(file_store, 'test-session', None),
|
||||
conversation_stats=ConversationStats(file_store, 'test-session', None),
|
||||
)
|
||||
|
||||
# Create a mock runtime and set it up
|
||||
|
||||
@@ -65,7 +65,7 @@ async def test_notify_on_llm_retry(
|
||||
file_store=InMemoryFileStore({}),
|
||||
config=config,
|
||||
llm_registry=llm_registry,
|
||||
convo_stats=conversation_stats,
|
||||
conversation_stats=conversation_stats,
|
||||
sio=mock_sio,
|
||||
user_id='..uid..',
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user