Start in context approval state
This commit is contained in:
@@ -45,14 +45,14 @@ class WebAgent(BaseAgent):
|
||||
Initialize web agent with required components.
|
||||
"""
|
||||
super().__init__(action_schema, working_memory, system_metrics, llm, validator, parser)
|
||||
self.context = ""
|
||||
self.response = ""
|
||||
self._system_prompt = system_prompt
|
||||
self._current_state = WebAgentState.UPDATE
|
||||
self._current_state = WebAgentState.CONTEXT_APPROVAL
|
||||
self._validation_error: Optional[str] = None
|
||||
self._state_change_handlers: List[Callable[[WebAgentState], None]] = []
|
||||
self._response_change_handlers: List[Callable[[str], None]] = []
|
||||
self._command_result: Optional[CommandResult] = None
|
||||
self.context = self._compile_context()
|
||||
|
||||
|
||||
@property
|
||||
|
||||
@@ -59,6 +59,12 @@ class WebAgentTest(unittest.TestCase):
|
||||
|
||||
self.mock_metrics.generate_context.side_effect = generate_context
|
||||
|
||||
# Mock LLM response generator
|
||||
def mock_infer(prompt: str, context: str):
|
||||
yield "<reasoning>test reasoning</reasoning>"
|
||||
|
||||
self.mock_llm.infer.side_effect = mock_infer
|
||||
|
||||
# Create agent with all components
|
||||
self.agent = WebAgent(
|
||||
system_prompt="test prompt",
|
||||
@@ -87,9 +93,9 @@ class WebAgentTest(unittest.TestCase):
|
||||
|
||||
def test_initialization(self):
|
||||
"""Test initial state of web agent."""
|
||||
self.assertEqual(self.agent.current_state, WebAgentState.UPDATE)
|
||||
self.assertEqual(self.agent.context, "")
|
||||
self.assertEqual(self.agent.current_state, WebAgentState.CONTEXT_APPROVAL)
|
||||
self.assertEqual(self.agent.response, "")
|
||||
self.assertIsNotNone(self.agent.context)
|
||||
self.assertIsNone(self.agent._validation_error)
|
||||
self.assertEqual(len(self.agent._state_change_handlers), 0)
|
||||
self.assertEqual(len(self.agent._response_change_handlers), 0)
|
||||
@@ -112,7 +118,10 @@ class WebAgentTest(unittest.TestCase):
|
||||
self.assertEqual(len(self.agent._response_change_handlers), 1)
|
||||
|
||||
def test_approve_context_state_error(self):
|
||||
"""Test approving context in wrong state raises error."""
|
||||
"""Test approving context in wrong state."""
|
||||
# Force agent into UPDATE state
|
||||
self.agent._current_state = WebAgentState.UPDATE
|
||||
|
||||
with self.assertRaises(Exception) as context:
|
||||
self.agent.approve_context()
|
||||
self.assertIn("Not in CONTEXT_APPROVAL state", str(context.exception))
|
||||
@@ -230,4 +239,4 @@ class WebAgentTest(unittest.TestCase):
|
||||
def tearDown(self):
|
||||
"""Clean up resources."""
|
||||
if hasattr(self, 'agent'):
|
||||
del self.agent
|
||||
del self.agent
|
||||
|
||||
Reference in New Issue
Block a user