Skip to content

Commit fdece1d

Browse files
fix: change name of caching strategies to match new pattern from caching_v02
1 parent f99082f commit fdece1d

4 files changed

Lines changed: 67 additions & 66 deletions

File tree

docs/06_caching.md

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ The caching system works by recording all tool use actions (mouse movements, cli
88

99
## Caching Strategies
1010

11-
The caching mechanism supports four strategies, configured via the `caching_settings` parameter in the `act()` method:
11+
The caching mechanism supports three strategies, configured via the `caching_settings` parameter in the `act()` method:
1212

13-
- **`"no"`** (default): No caching is used. The agent executes normally without recording or replaying actions.
14-
- **`"write"`**: Records all agent actions to a cache file for future replay.
15-
- **`"read"`**: Provides tools to the agent to list and execute previously cached trajectories.
16-
- **`"both"`**: Combines read and write modes - the agent can use existing cached trajectories and will also record new ones.
13+
- **`None`** (default): No caching is used. The agent executes normally without recording or replaying actions.
14+
- **`"record"`**: Records all agent actions to a cache file for future replay.
15+
- **`"execute"`**: Provides tools to the agent to list and execute previously cached trajectories.
16+
- **`"both"`**: Combines execute and record modes - the agent can use existing cached trajectories and will also record new ones.
1717

1818
## Configuration
1919

@@ -23,9 +23,9 @@ Caching is configured using the `CachingSettings` class:
2323
from askui.models.shared.settings import CachingSettings, CachedExecutionToolSettings
2424

2525
caching_settings = CachingSettings(
26-
strategy="write", # One of: "read", "write", "both", "no"
26+
strategy="record", # One of: "execute", "record", "both", or None
2727
cache_dir=".cache", # Directory to store cache files
28-
filename="my_test.json", # Filename for the cache file (optional for write mode)
28+
filename="my_test.json", # Filename for the cache file (optional for record mode)
2929
execute_cached_trajectory_tool_settings=CachedExecutionToolSettings(
3030
delay_time_between_actions=0.5 # Delay in seconds between each cached action
3131
)
@@ -34,9 +34,9 @@ caching_settings = CachingSettings(
3434

3535
### Parameters
3636

37-
- **`strategy`**: The caching strategy to use (`"read"`, `"write"`, `"both"`, or `"no"`).
37+
- **`strategy`**: The caching strategy to use (`"execute"`, `"record"`, `"both"`, or `None`).
3838
- **`cache_dir`**: Directory where cache files are stored. Defaults to `".cache"`.
39-
- **`filename`**: Name of the cache file to write to or read from. If not specified in write mode, a timestamped filename will be generated automatically (format: `cached_trajectory_YYYYMMDDHHMMSSffffff.json`).
39+
- **`filename`**: Name of the cache file to write to or read from. If not specified in record mode, a timestamped filename will be generated automatically (format: `cached_trajectory_YYYYMMDDHHMMSSffffff.json`).
4040
- **`execute_cached_trajectory_tool_settings`**: Configuration for the trajectory execution tool (optional). See [Execution Settings](#execution-settings) below.
4141

4242
### Execution Settings
@@ -61,7 +61,7 @@ You can adjust this value based on your application's responsiveness:
6161

6262
## Usage Examples
6363

64-
### Writing a Cache (Recording)
64+
### Recording a Cache
6565

6666
Record agent actions to a cache file for later replay:
6767

@@ -73,7 +73,7 @@ with ComputerAgent() as agent:
7373
agent.act(
7474
goal="Fill out the login form with username 'admin' and password 'secret123'",
7575
caching_settings=CachingSettings(
76-
strategy="write", # you could also use "both" here
76+
strategy="record", # you could also use "both" here
7777
cache_dir=".cache",
7878
filename="login_test.json"
7979
)
@@ -82,7 +82,7 @@ with ComputerAgent() as agent:
8282

8383
After execution, a cache file will be created at `.cache/login_test.json` containing all the tool use actions performed by the agent.
8484

85-
### Reading from Cache (Replaying)
85+
### Executing from Cache (Replaying)
8686

8787
Provide the agent with access to previously recorded trajectories:
8888

@@ -94,13 +94,13 @@ with ComputerAgent() as agent:
9494
agent.act(
9595
goal="Fill out the login form",
9696
caching_settings=CachingSettings(
97-
strategy="read", # you could also use "both" here
97+
strategy="execute", # you could also use "both" here
9898
cache_dir=".cache"
9999
)
100100
)
101101
```
102102

103-
When using `strategy="read"`, the agent receives two additional tools:
103+
When using `strategy="execute"`, the agent receives two additional tools:
104104

105105
1. **`retrieve_available_trajectories_tool`**: Lists all available cache files in the cache directory
106106
2. **`execute_cached_executions_tool`**: Executes a specific cached trajectory
@@ -109,7 +109,7 @@ The agent will automatically check if a relevant cached trajectory exists and us
109109

110110
### Referencing Cache Files in Goal Prompts
111111

112-
When using `strategy="read"` or `strategy="both"`, **you need to inform the agent about which cache files are available and when to use them**. This is done by including cache file information directly in your goal prompt.
112+
When using `strategy="execute"` or `strategy="both"`, **you need to inform the agent about which cache files are available and when to use them**. This is done by including cache file information directly in your goal prompt.
113113

114114
#### Explicit Cache File References
115115

@@ -126,7 +126,7 @@ with ComputerAgent() as agent:
126126
If the cache file "open_website_in_chrome.json" is available, please use it
127127
for this execution. It will open a new window in Chrome and navigate to the website.""",
128128
caching_settings=CachingSettings(
129-
strategy="read",
129+
strategy="execute",
130130
cache_dir=".cache"
131131
)
132132
)
@@ -149,7 +149,7 @@ with ComputerAgent() as agent:
149149
Check if a cache file named "{test_id}.json" exists. If it does, use it to
150150
replay the test actions, then verify the results.""",
151151
caching_settings=CachingSettings(
152-
strategy="read",
152+
strategy="execute",
153153
cache_dir="test_cache"
154154
)
155155
)
@@ -171,7 +171,7 @@ with ComputerAgent() as agent:
171171
Choose the most recent one if multiple are available, as it likely contains
172172
the most up-to-date interaction sequence.""",
173173
caching_settings=CachingSettings(
174-
strategy="read",
174+
strategy="execute",
175175
cache_dir=".cache"
176176
)
177177
)
@@ -195,7 +195,7 @@ with ComputerAgent() as agent:
195195
196196
After each cached execution, verify the step completed successfully before proceeding.""",
197197
caching_settings=CachingSettings(
198-
strategy="read",
198+
strategy="execute",
199199
cache_dir=".cache"
200200
)
201201
)
@@ -219,7 +219,7 @@ with ComputerAgent() as agent:
219219
agent.act(
220220
goal="Fill out the login form",
221221
caching_settings=CachingSettings(
222-
strategy="read",
222+
strategy="execute",
223223
cache_dir=".cache",
224224
execute_cached_trajectory_tool_settings=CachedExecutionToolSettings(
225225
delay_time_between_actions=1.0 # Wait 1 second between each action
@@ -323,7 +323,7 @@ The delay between actions can be customized using `CachedExecutionToolSettings`
323323
## Limitations
324324

325325
- **UI State Sensitivity**: Cached trajectories assume the UI is in the same state as when they were recorded. If the UI has changed, the replay may fail or produce incorrect results.
326-
- **No on_message Callback**: When using `strategy="write"` or `strategy="both"`, you cannot provide a custom `on_message` callback, as the caching system uses this callback to record actions.
326+
- **No on_message Callback**: When using `strategy="record"` or `strategy="both"`, you cannot provide a custom `on_message` callback, as the caching system uses this callback to record actions.
327327
- **Verification Required**: After executing a cached trajectory, the agent should verify that the results are correct, as UI changes may cause partial failures.
328328

329329
## Example: Complete Test Workflow
@@ -340,7 +340,7 @@ with ComputerAgent() as agent:
340340
agent.act(
341341
goal="Navigate to the login page and log in with username 'testuser' and password 'testpass123'",
342342
caching_settings=CachingSettings(
343-
strategy="write",
343+
strategy="record",
344344
cache_dir="test_cache",
345345
filename="user_login.json"
346346
)
@@ -356,7 +356,7 @@ with ComputerAgent() as agent:
356356
the login sequence. It contains the steps to navigate to the login page and
357357
authenticate with the test credentials.""",
358358
caching_settings=CachingSettings(
359-
strategy="read",
359+
strategy="execute",
360360
cache_dir="test_cache",
361361
execute_cached_trajectory_tool_settings=CachedExecutionToolSettings(
362362
delay_time_between_actions=1.0

src/askui/agent_base.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,15 @@ def act(
135135
Overrides the agent's default model if provided.
136136
on_message (OnMessageCb | None, optional): Callback for new messages. If
137137
it returns `None`, stops and does not add the message. Cannot be used
138-
with caching_settings strategy "write" or "both".
138+
with caching_settings strategy "record" or "both".
139139
tools (list[Tool] | ToolCollection | None, optional): The tools for the
140140
agent. Defaults to default tools depending on the selected model.
141141
caching_settings (CachingSettings | None, optional): The caching settings
142142
for the act execution. Controls recording and replaying of action
143-
sequences (trajectories). Available strategies: "no" (default, no
144-
caching), "write" (record actions to cache file), "read" (replay from
145-
cached trajectories), "both" (read and write). Defaults to no caching.
143+
sequences (trajectories). Available strategies: None (default, no
144+
caching), "record" (record actions to cache file), "execute" (replay
145+
from cached trajectories), "both" (execute and record). Defaults to
146+
no caching.
146147
147148
Returns:
148149
None
@@ -152,7 +153,7 @@ def act(
152153
defined in the agent settings.
153154
ModelRefusalError: If the model refuses to process the request.
154155
ValueError: If on_message callback is provided with caching strategy
155-
"write" or "both".
156+
"record" or "both".
156157
157158
Example:
158159
Basic usage without caching:
@@ -177,14 +178,14 @@ def act(
177178
"username 'admin' and password 'secret123'"
178179
),
179180
caching_settings=CachingSettings(
180-
strategy="write",
181+
strategy="record",
181182
cache_dir=".cache",
182183
filename="login_flow.json"
183184
)
184185
)
185186
```
186187
187-
Replaying cached actions:
188+
Executing cached actions:
188189
```python
189190
from askui import ComputerAgent
190191
from askui.models.shared.settings import CachingSettings
@@ -193,14 +194,14 @@ def act(
193194
agent.act(
194195
goal="Log in to the application",
195196
caching_settings=CachingSettings(
196-
strategy="read",
197+
strategy="execute",
197198
cache_dir=".cache"
198199
)
199200
)
200201
# Agent will automatically find and use "login_flow.json"
201202
```
202203
203-
Using both read and write modes:
204+
Using both execute and record modes:
204205
```python
205206
from askui import ComputerAgent
206207
from askui.models.shared.settings import CachingSettings
@@ -287,8 +288,8 @@ def _patch_act_with_cache(
287288
cached_execution_tool: ExecuteCachedTrajectory | None = None
288289
cache_manager: CacheManager | None = None
289290

290-
# Setup read mode: add caching tools and modify system prompt
291-
if caching_settings.strategy in ["read", "both"]:
291+
# Setup execute mode: add caching tools and modify system prompt
292+
if caching_settings.strategy in ["execute", "both"]:
292293
# Create CacheExecutor with execution settings and add to speakers
293294
cache_executor = CacheExecutor(caching_settings.execution_settings)
294295
self._conversation.speakers.add_speaker(cache_executor)
@@ -315,8 +316,8 @@ def _patch_act_with_cache(
315316
else:
316317
tools = caching_tools
317318

318-
# Setup write mode: create cache manager for recording
319-
if caching_settings.strategy in ["write", "both"]:
319+
# Setup record mode: create cache manager for recording
320+
if caching_settings.strategy in ["record", "both"]:
320321
cache_writer_settings = (
321322
caching_settings.writing_settings or CacheWritingSettings()
322323
)

src/askui/models/shared/settings.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class Resolution(NamedTuple):
3434
DEFAULT_LOCATE_RESOLUTION = Resolution(1280, 800)
3535
DEFAULT_GET_RESOLUTION = Resolution(1280, 800)
3636

37-
CACHING_STRATEGY = Literal["read", "write", "both", "no"]
37+
CACHING_STRATEGY = Literal["execute", "record", "both"]
3838
CACHE_PARAMETER_IDENTIFICATION_STRATEGY = Literal["llm", "preset"]
3939
CACHING_VISUAL_VERIFICATION_METHOD = Literal["phash", "ahash", "none"]
4040

@@ -259,18 +259,18 @@ class CachingSettings(BaseModel):
259259
performance optimization.
260260
261261
Args:
262-
strategy (CACHING_STRATEGY): Caching mode. Options:
263-
- "no": Caching disabled (default)
264-
- "read": Replay actions from cache
265-
- "write": Record actions to cache
266-
- "both": Read from cache if available, otherwise record
262+
strategy (CACHING_STRATEGY | None): Caching mode. Options:
263+
- None: Caching disabled (default)
264+
- "execute": Replay actions from cache
265+
- "record": Record actions to cache
266+
- "both": Execute from cache if available, otherwise record
267267
cache_dir (str): Directory path for storing cache files.
268268
Default: ".askui_cache".
269-
writing_settings: Settings for cache recording (used in "write"/"both" modes)
270-
execution_settings: Settings for cache playback (used in "read"/"both" modes)
269+
writing_settings: Settings for cache recording (used in "record"/"both" modes)
270+
execution_settings: Settings for cache playback (used in "execute"/"both" modes)
271271
"""
272272

273-
strategy: CACHING_STRATEGY = "no"
273+
strategy: CACHING_STRATEGY | None = None
274274
cache_dir: str = ".askui_cache"
275275
writing_settings: CacheWritingSettings | None = None
276276
execution_settings: CacheExecutionSettings | None = None

0 commit comments

Comments
 (0)