-
Notifications
You must be signed in to change notification settings - Fork 54
Migrate act() to conversation-based architecture with Speaker pattern and add caching v2 features. #236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
philipph-askui
wants to merge
39
commits into
main
Choose a base branch
from
chore/act_conversation_with_caching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Migrate act() to conversation-based architecture with Speaker pattern and add caching v2 features. #236
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
7f2770c
refactor: migrate act to conversation-based architecture and update c…
philipph-askui d79a5cd
feat: add caching_v2 features and fix otel dependency for tracing
philipph-askui 835860a
feat: change default of `is_cacheable` flag to False
philipph-askui 08a1a0e
fix: update prompts to state of caching_v02
philipph-askui ec8e82b
fix: format, typechecking, liniting issues
philipph-askui 16983b4
fix: sanitizes messages before sending to API as we need to remove pr…
philipph-askui d6932f2
removes old 'llm_provider` field in CacheWritingSettings
philipph-askui 297b5e3
fix: add default cache directory (.askui_cache) to gitignore
philipph-askui cc47181
chore: change logging outputs to INFO
philipph-askui 6e3a52f
fix: removes old cache_writer and makes code use the new cache_manager
philipph-askui 57b887d
fix: handles problems due to tools now having uuid suffixes
philipph-askui 35d6149
fix: adds missing cache parameter handling
philipph-askui 6f08bce
fix: update outdated tests
philipph-askui 76daa92
feat: add method to truncate content for html reports to prevent floo…
philipph-askui 16257dd
fix: migrate caching to conversation-based architecture and add missi…
philipph-askui a4c6449
fix: bug in visual validation during cached execution
philipph-askui ac2caf1
chore: change default value for `visual_validation_threshold` to 10
philipph-askui 586aee3
fix: add explicit conversion to int of mouse move coordinats, as the …
philipph-askui aa93ff7
chore: change log message from warning to info
philipph-askui f04f1c9
fix: remove unnecessary files
philipph-askui 908d55d
fix: duplicate clipping of coordinates
philipph-askui 7f4b95f
fix: multiple bugs and code quality issues
philipph-askui 0b9e13b
fix: change default value of `delay_time_between_actions` from 0.5 to…
philipph-askui b60d1bf
feat: add usage statistics of caching to html reporter
philipph-askui f99082f
fix: bug where cached executions were reported as success when they w…
philipph-askui fdece1d
fix: change name of caching strategies to match new pattern from cach…
philipph-askui 6d961f8
fix: coding quality issue
philipph-askui 1c266ae
chore: add pydantic model for VisualValidationMetadata
philipph-askui ee78cbf
chore: move conversation to models/shared
philipph-askui 4029647
chore: refactor control loop and delete legacy code (custom_agent and…
philipph-askui d135838
feat: add callback system comparable to pytorch lightning
philipph-askui dfc9068
fix: bug in html report that led to a crash for non-cached executions
philipph-askui 19ab09c
feat: add new speaker handoff pattern that is more scalable and gener…
philipph-askui 9e3672b
feat: add conversation_id to conversation
philipph-askui 908b5ce
feat: add on_speaker_switch callback
philipph-askui 1650ff7
chore: resolve joint callback method into methods that handle them in…
philipph-askui 6d17375
chore: refactor usage tracking to integrate via callback
philipph-askui f8b416a
chore: change name of caching strategy `both` to `auto`
philipph-askui 33c72bf
Merge branch 'main' into chore/act_conversation_with_caching
philipph-askui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -169,5 +169,6 @@ reports/ | |
| /askui_chat.db-shm | ||
| /askui_chat.db-wal | ||
| .cache/ | ||
| .askui_cache/* | ||
|
|
||
| bom.json | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Callbacks | ||
|
|
||
| Callbacks provide hooks into the agent's conversation lifecycle, similar to PyTorch Lightning's callback system. Use them for logging, monitoring, custom metrics, or extending agent behavior. | ||
|
|
||
| ## Usage | ||
|
|
||
| Subclass `ConversationCallback` and override the hooks you need: | ||
|
|
||
| ```python | ||
| from askui import ComputerAgent, ConversationCallback | ||
|
|
||
| class MetricsCallback(ConversationCallback): | ||
| def on_step_start(self, conversation, step_index): | ||
| print(f"Step {step_index} starting...") | ||
|
|
||
| def on_step_end(self, conversation, step_index, result): | ||
| print(f"Step {step_index} finished: {result.status}") | ||
|
|
||
| with ComputerAgent(callbacks=[MetricsCallback()]) as agent: | ||
| agent.act("Open the settings menu") | ||
| ``` | ||
|
|
||
| ## Available Hooks | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing switch_callback |
||
|
|
||
| | Hook | When Called | Parameters | | ||
| |------|-------------|------------| | ||
| | `on_conversation_start` | After setup, before control loop | `conversation` | | ||
| | `on_conversation_end` | After control loop, before cleanup | `conversation` | | ||
| | `on_control_loop_start` | Before the iteration loop begins | `conversation` | | ||
| | `on_control_loop_end` | After the iteration loop ends | `conversation` | | ||
| | `on_step_start` | Before each step execution | `conversation`, `step_index` | | ||
| | `on_step_end` | After each step execution | `conversation`, `step_index`, `result` | | ||
| | `on_tool_execution_start` | Before tools are executed | `conversation`, `tool_names` | | ||
| | `on_tool_execution_end` | After tools are executed | `conversation`, `tool_names` | | ||
|
|
||
| ### Parameters | ||
|
|
||
| - **`conversation`**: The `Conversation` instance with access to messages, settings, and state | ||
| - **`step_index`**: Zero-based index of the current step | ||
| - **`result`**: `SpeakerResult` containing `status`, `messages_to_add`, and `usage` | ||
| - **`tool_names`**: List of tool names being executed | ||
|
|
||
| ## Example: Timing Callback | ||
|
|
||
| ```python | ||
| import time | ||
| from askui import ComputerAgent, ConversationCallback | ||
|
|
||
| class TimingCallback(ConversationCallback): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice Example |
||
| def __init__(self): | ||
| self.start_time = None | ||
| self.step_times = [] | ||
|
|
||
| def on_conversation_start(self, conversation): | ||
| self.start_time = time.time() | ||
|
|
||
| def on_step_start(self, conversation, step_index): | ||
| self._step_start = time.time() | ||
|
|
||
| def on_step_end(self, conversation, step_index, result): | ||
| elapsed = time.time() - self._step_start | ||
| self.step_times.append(elapsed) | ||
| print(f"Step {step_index}: {elapsed:.2f}s") | ||
|
|
||
| def on_conversation_end(self, conversation): | ||
| total = time.time() - self.start_time | ||
| print(f"Total: {total:.2f}s across {len(self.step_times)} steps") | ||
|
|
||
| with ComputerAgent(callbacks=[TimingCallback()]) as agent: | ||
| agent.act("Search for documents") | ||
| ``` | ||
|
|
||
| ## Multiple Callbacks | ||
|
|
||
| Pass multiple callbacks to combine behaviors: | ||
|
|
||
| ```python | ||
| with ComputerAgent(callbacks=[TimingCallback(), MetricsCallback()]) as agent: | ||
| agent.act("Complete the form") | ||
| ``` | ||
|
|
||
| Callbacks are called in the order they are provided. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.