Conversation
| def thread( | ||
| self, | ||
| *, | ||
| name: str | None = None, |
There was a problem hiding this comment.
Now we have a Thread.name and an Agent.name. I think we should remove Agent.name as we don't use it anywhere and it can cause confusion with Thread.name.
| self._default_rows_limit = rows_limit | ||
|
|
||
| self._lazy_mode = lazy | ||
| self._name = name or f"thread-{uuid.uuid4()!s}" |
There was a problem hiding this comment.
We should probably expose the name publicly as well, like we have with Agent.name.
| self._cache = self._agent.cache.scoped(self._name) | ||
| state = self._cache.get("state", default=None) | ||
| if state: | ||
| if overwrite: | ||
| self._cache.put("state", {}) | ||
| print(f"Overwrote existing state for thread {self._name}. History is empty.") | ||
| else: | ||
| print(f"Loaded existing state for thread {self._name}.\nOperations:") | ||
| self._opas = state.get("operations", []) | ||
| self._opas_processed_count = len(self._opas) | ||
| messages = state.get("messages", []) | ||
| self._meta = {"messages": messages} | ||
| counter = 1 | ||
| for opa_group in self._opas: | ||
| for opa in opa_group: | ||
| print(f"- Op {counter}: {opa.query}") | ||
| counter += 1 | ||
| self._data_result = self._agent.executor.get_result(messages) | ||
|
|
There was a problem hiding this comment.
I find it strange to assume the existence of these cache keys in Thread, as I would assume that they are specific to an Executor. Maybe it would be cleaner to have a thread-specific cache scope and an Executor specific cache scope instead. That way, the Thread cache would save _opas and _data_result without relying on Executor.
| self._graph_recursion_limit = 50 | ||
|
|
||
| def _process_opas(self, opas: list[Opa], cache: Cache) -> list[Any]: | ||
| def _process_opas(self, opas: list[Opa], cache: Cache) -> dict[str, Any]: |
There was a problem hiding this comment.
I think these changes break ReactDuckDBExecutor
| """Update message history in cache with final messages from graph execution.""" | ||
| if final_messages: | ||
| cache.put("state", {"messages": final_messages}) | ||
| def _update_message_history(self, cache: Cache, state: dict[str, Any]) -> None: |
There was a problem hiding this comment.
I would rename the method name now to something like _save_state
Implemented simplest use case for cache: