Add context info in ui

This commit is contained in:
2026-01-10 19:13:08 +01:00
parent 5821391309
commit 7014bba178
10 changed files with 141 additions and 16 deletions

View File

@@ -45,6 +45,7 @@ class WebAgent(BaseAgent):
self._state_change_handlers: List[Callable[[AgentState], None]] = []
self._selected_llm_change_handlers: List[Callable[[str], None]] = []
self._context_change_handlers: List[Callable[[Dict], None]] = []
self._update_compiled_context()
self._working_memory.add_change_handler(self._update_compiled_context)
@@ -81,6 +82,13 @@ class WebAgent(BaseAgent):
def add_state_change_handler(self, handler: Callable[[AgentState], None]) -> None:
self._state_change_handlers.append(handler)
@property
def context_info(self) -> Dict:
return dict(self._compiled_context.attrib)
def add_context_change_handler(self, handler: Callable[[Dict], None]) -> None:
self._context_change_handlers.append(handler)
def run_inference(self) -> None:
"""Start inference on specified LLM"""
if self._state != AgentState.IDLE:
@@ -132,4 +140,15 @@ class WebAgent(BaseAgent):
handler(state)
def _update_compiled_context(self):
self._compiled_context = self._compile_context(self._llms[self.active_llm])
self._compiled_context = self._compile_context(self._llms[self.active_llm])
self._notify_context_change()
def _notify_context_change(self):
"""Notify all context change handlers."""
for handler in self._context_change_handlers:
handler(self.context_info)
def _notify_selected_llm_change(self):
"""Notify all selected LLM change handlers."""
for handler in self._selected_llm_change_handlers:
handler(self._selected_llm)