Migrate act() to conversation-based architecture with Speaker pattern and add caching v2 features.#236
Conversation
…ache settings to new format
…oprietary fields first (e.g. usage_param)
…ding with base64 image strings
…ng caching features
…agent occasionaly provides the values as strigns
… 1.0 to give UIs time to materialize
|
|
||
| # Create switch_speaker tool with valid speaker names | ||
| handoff_speakers = [ | ||
| speaker.get_name() for speaker in self.speakers if speaker.get_description() |
There was a problem hiding this comment.
The user of creating new Speakers is an developer. Instead of a silent filter, we should make it eather a
-
warning, that we filtered it out
-
or we throwting a Exception
- and it would be nice to do the check during init-method of the Speaker class.
And I would prefere the Exception.
| ) | ||
|
|
||
| @tracer.start_as_current_span("handle_result_status") | ||
| def _handle_result_status(self, result: SpeakerResult) -> bool: |
src/askui/speaker/agent_speaker.py
Outdated
| # Determine status based on whether there are tool calls | ||
| # If there are tool calls, conversation will execute them and loop back | ||
| # If no tool calls, conversation is done | ||
| has_tool_calls = self._has_tool_calls(response) | ||
| status = "continue" if has_tool_calls else "done" |
There was a problem hiding this comment.
is the status then not mor a request_loop_to
| return isinstance(exception, (APIConnectionError, APITimeoutError, APIError)) | ||
|
|
||
|
|
||
| def _sanitize_message_for_api(message: MessageParam) -> dict[str, Any]: |
There was a problem hiding this comment.
| def _sanitize_message_for_api(message: MessageParam) -> dict[str, Any]: | |
| def from_MessageParam(message: MessageParam) -> BetaMessageParam: | |
| if instance(message.content ) is str; | |
| continue | |
| message.content = [from_toolluseblock(ToolUseBlock ) for block in message.content if instance(block) == ToolUseBlock else block] | |
| retrun message | |
There was a problem hiding this comment.
addressed in 7998ac0
Can you please take a look again if that is how you meant it @programminx-askui ?
src/askui/speaker/agent_speaker.py
Outdated
| # Log response | ||
| logger.debug("Agent response: %s", response.model_dump(mode="json")) | ||
|
|
||
| except Exception: |
There was a problem hiding this comment.
API Exceptions: https://platform.claude.com/docs/en/api/messages/create#raw_message_stream_event
Content Parsing Erros: retry -> throw to user
5** HTTP Execeptions: -> Retry and then fail -> Move to HTTP Client
4** HTTP Exceptions: -> throw to user
- 401 Unauthorized: -> ??
Network Layer Errors: -> throw to user
-> We remove catch of the exception.
src/askui/speaker/agent_speaker.py
Outdated
| # Log response | ||
| logger.debug("Agent response: %s", response.model_dump(mode="json")) | ||
|
|
||
| except Exception: |
There was a problem hiding this comment.
General rule. Only Tool Call error can be recovered, but no LLM calls.
src/askui/speaker/agent_speaker.py
Outdated
| # Log response | ||
| logger.debug("Agent response: %s", response.model_dump(mode="json")) | ||
|
|
||
| except Exception: |
…and enforce that they are not empty
| if isinstance(block, ToolUseBlockParam): | ||
| return cast( | ||
| "BetaContentBlockParam", | ||
| block.model_dump(exclude={"visual_representation"}), |
There was a problem hiding this comment.
This is better. I'm still unsute, what happens when the visual_representation field does not exists.
Did you tested it?
But do we not want to include all BetaContentBlockParam fields`? Then we don't have to exclue the ToolUseBlockParams?
There was a problem hiding this comment.
If visual_representation is not present, it will just dump the rest of the model.
I don't understand the second comment
… tokens when recording the cache file
This PR merges two key concepts from the feat/conversation_based_architecture and the feat/caching_v02 branches and makes them ready for main:
-- visual validation using imagehash (phash/ahash)
-- cache invalidation or validation, Parameters in cache files (identified through LLM)
-- non-cacheable tools through is_cacheable flag
-- usage params in reports
all adapted to the new act() architecture
Things that might be worth testing that should work:
and: sorry for yet another massive PR...
For design docs that outline the concept please see here:
Here is a minimal example to test: