Approve context

This commit is contained in:
2024-11-02 19:17:27 +01:00
parent 96d14fc46d
commit 2a15708145
9 changed files with 296 additions and 149 deletions

View File

@@ -1,4 +1,3 @@
import asyncio
from typing import Optional, List, Callable
from sia.web_agent import WebAgentState
@@ -21,35 +20,34 @@ class MockWebAgent:
def add_response_change_handler(self, handler):
self._response_handlers.append(handler)
def set_input(self, input_text):
pass
async def _notify_state_handlers(self, new_state: WebAgentState):
def _notify_state_handlers(self, new_state: WebAgentState):
"""Notify all state handlers of a state change."""
for handler in self._state_handlers:
await handler(new_state)
handler(new_state)
async def _notify_response_handlers(self, response: str):
def _notify_response_handlers(self, response: str):
"""Notify all response handlers of a response change."""
for handler in self._response_handlers:
await handler(response)
handler(response)
async def _set_response(self, response: str):
def _set_response(self, response: str):
"""Set response and notify handlers."""
self.response = response
await self._notify_response_handlers(response)
self._notify_response_handlers(response)
async def approve_context(self):
def approve_context(self):
"""Handle context approval with immediate state updates."""
# Change to INFERENCE state and notify
self._current_state = WebAgentState.INFERENCE
for handler in self._state_handlers:
await handler(WebAgentState.INFERENCE)
self._notify_state_handlers(WebAgentState.INFERENCE)
# Set response and notify
self.response = "<reasoning>test</reasoning>"
for handler in self._response_handlers:
await handler(self.response)
self._set_response("<reasoning>test</reasoning>")
# Change to RESPONSE_APPROVAL state and notify
self._current_state = WebAgentState.RESPONSE_APPROVAL
for handler in self._state_handlers:
await handler(WebAgentState.RESPONSE_APPROVAL)
self._notify_state_handlers(WebAgentState.RESPONSE_APPROVAL)