Skip to content

Commit 9d94a7b

Browse files
philipph-askuiprogramminx-askui
authored andcommitted
chore(caching): distributes responsibilities between CacheWriter and ParameterHandler more consistently and renames placeholder to caching_parameter.
1 parent 42928c6 commit 9d94a7b

15 files changed

+787
-783
lines changed

docs/caching.md

Lines changed: 63 additions & 63 deletions
Large diffs are not rendered by default.

src/askui/models/shared/settings.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
COMPUTER_USE_20251124_BETA_FLAG = "computer-use-2025-11-24"
1919

2020
CACHING_STRATEGY = Literal["read", "write", "both", "no"]
21-
PLACEHOLDER_IDENTIFICATION_STRATEGY = Literal["llm", "preset"]
21+
CACHE_PARAMETER_IDENTIFICATION_STRATEGY = Literal["llm", "preset"]
2222

2323

2424
class MessageSettings(BaseModel):
@@ -43,8 +43,8 @@ class CachedExecutionToolSettings(BaseModel):
4343

4444

4545
class CacheWriterSettings(BaseModel):
46-
placeholder_identification_strategy: PLACEHOLDER_IDENTIFICATION_STRATEGY = "llm"
47-
llm_placeholder_id_api_provider: AnthropicApiProvider = "askui"
46+
parameter_identification_strategy: CACHE_PARAMETER_IDENTIFICATION_STRATEGY = "llm"
47+
llm_parameter_id_api_provider: AnthropicApiProvider = "askui"
4848

4949

5050
class CachingSettings(BaseModel):
@@ -81,4 +81,4 @@ class CacheFile(BaseModel):
8181

8282
metadata: CacheMetadata
8383
trajectory: list[ToolUseBlockParam]
84-
placeholders: dict[str, str] = Field(default_factory=dict)
84+
cache_parameters: dict[str, str] = Field(default_factory=dict)

src/askui/prompts/caching.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919
" - If execution fails partway, you'll see exactly where it failed "
2020
"and can decide how to proceed\n"
2121
"\n"
22-
" PLACEHOLDERS:\n"
23-
" - Trajectories may contain dynamic placeholders like "
22+
" CACHING_PARAMETERS:\n"
23+
" - Trajectories may contain dynamic parameters like "
2424
"{{current_date}} or {{user_name}}\n"
2525
" - When executing a trajectory, check if it requires "
26-
"placeholder values\n"
27-
" - Provide placeholder values using the placeholder_values "
26+
"parameter values\n"
27+
" - Provide parameter values using the parameter_values "
2828
"parameter as a dictionary\n"
2929
" - Example: ExecuteCachedTrajectory(trajectory_file='test.json', "
30-
"placeholder_values={'current_date': '2025-12-11'})\n"
31-
" - If required placeholders are missing, execution will fail with "
30+
"parameter_values={'current_date': '2025-12-11'})\n"
31+
" - If required parameters are missing, execution will fail with "
3232
"a clear error message\n"
3333
"\n"
3434
" NON-CACHEABLE STEPS:\n"
@@ -49,7 +49,7 @@
4949
" - Provide the same trajectory file and the step index where "
5050
"execution should continue\n"
5151
" - Example: ExecuteCachedTrajectory(trajectory_file='test.json', "
52-
"start_from_step_index=5, placeholder_values={...})\n"
52+
"start_from_step_index=5, parameter_values={...})\n"
5353
" - The tool will execute remaining steps from that index onwards\n"
5454
"\n"
5555
" FAILURE HANDLING:\n"
@@ -83,8 +83,8 @@
8383
" </TRAJECTORY DETAILS>\n"
8484
)
8585

86-
PLACEHOLDER_IDENTIFIER_SYSTEM_PROMPT = """You are analyzing UI automation trajectories \
87-
to identify values that should be parameterized as placeholders.
86+
CACHING_PARAMETER_IDENTIFIER_SYSTEM_PROMPT = """You are analyzing UI automation \
87+
trajectories to identify values that should be parameterized as parameters.
8888
8989
Identify values that are likely to change between executions, such as:
9090
- Dates and timestamps (e.g., "2025-12-11", "10:30 AM", "2025-12-11T14:30:00Z")
@@ -94,22 +94,22 @@
9494
- File paths with user-specific or time-specific components
9595
- Temporary or generated identifiers
9696
97-
DO NOT mark as placeholders:
97+
DO NOT mark as parameters:
9898
- UI element coordinates (x, y positions)
9999
- Fixed button labels or static UI text
100100
- Configuration values that don't change (e.g., timeouts, retry counts)
101101
- Generic action names like "click", "type", "scroll"
102102
- Tool names
103103
- Boolean values or common constants
104104
105-
For each placeholder, provide:
105+
For each parameter, provide:
106106
1. A descriptive name in snake_case (e.g., "current_date", "user_email")
107107
2. The actual value found in the trajectory
108108
3. A brief description of what it represents
109109
110110
Return your analysis as a JSON object with this structure:
111111
{
112-
"placeholders": [
112+
"parameters": [
113113
{
114114
"name": "current_date",
115115
"value": "2025-12-11",
@@ -118,4 +118,4 @@
118118
]
119119
}
120120
121-
If no placeholders are found, return an empty placeholders array."""
121+
If no parameters are found, return an empty parameters array."""

src/askui/tools/caching_tools.py

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88

99
from ..models.shared.settings import CachedExecutionToolSettings
1010
from ..models.shared.tools import Tool, ToolCollection
11+
from ..utils.cache_parameter_handler import CacheParameterHandler
1112
from ..utils.caching.cache_execution_manager import CacheExecutionManager
1213
from ..utils.caching.cache_manager import CacheManager
1314
from ..utils.caching.cache_writer import CacheWriter
14-
from ..utils.placeholder_handler import PlaceholderHandler
1515

1616
if TYPE_CHECKING:
1717
from ..models.shared.agent_message_param import ToolUseBlockParam
@@ -149,14 +149,14 @@ def __init__(
149149
"trajectory files are available\n"
150150
"2. Select the appropriate trajectory file path from the "
151151
"returned list\n"
152-
"3. If the trajectory contains placeholders (e.g., "
152+
"3. If the trajectory contains parameters (e.g., "
153153
"{{current_date}}), provide values for them in the "
154-
"placeholder_values parameter\n"
154+
"parameter_values parameter\n"
155155
"4. Pass the full file path to this tool\n\n"
156-
"Placeholders allow dynamic values to be injected during "
156+
"Cache parameters allow dynamic values to be injected during "
157157
"execution. For example, if a trajectory types "
158158
"'{{current_date}}', you must provide "
159-
"placeholder_values={'current_date': '2025-12-11'}.\n\n"
159+
"parameter_values={'current_date': '2025-12-11'}.\n\n"
160160
"To continue from a specific step (e.g., after manually "
161161
"handling a non-cacheable step), use the start_from_step_index "
162162
"parameter. By default, execution starts from the beginning "
@@ -188,12 +188,12 @@ def __init__(
188188
),
189189
"default": 0,
190190
},
191-
"placeholder_values": {
191+
"parameter_values": {
192192
"type": "object",
193193
"description": (
194-
"Optional dictionary mapping placeholder names to "
194+
"Optional dictionary mapping parameter names to "
195195
"their values. Required if the trajectory contains "
196-
"placeholders like {{variable}}. Example: "
196+
"parameters like {{variable}}. Example: "
197197
"{'current_date': '2025-12-11', 'user_name': 'Alice'}"
198198
),
199199
"additionalProperties": {"type": "string"},
@@ -265,33 +265,33 @@ def _validate_step_index(
265265
return error_msg
266266
return None
267267

268-
def _validate_placeholders(
268+
def _validate_parameters(
269269
self,
270270
trajectory: list["ToolUseBlockParam"],
271-
placeholder_values: dict[str, str],
272-
cache_placeholders: dict[str, str],
271+
parameter_values: dict[str, str],
272+
cache_parameters: dict[str, str],
273273
) -> str | None:
274-
"""Validate placeholder values.
274+
"""Validate parameter values.
275275
276276
Args:
277277
trajectory: The cached trajectory
278-
placeholder_values: User-provided placeholder values
279-
cache_placeholders: Placeholders defined in cache file
278+
parameter_values: User-provided parameter values
279+
cache_parameters: Parameters defined in cache file
280280
281281
Returns:
282282
Error message if validation fails, None otherwise
283283
"""
284-
logger.debug("Validating placeholder values")
285-
is_valid, missing = PlaceholderHandler.validate_placeholders(
286-
trajectory, placeholder_values
284+
logger.debug("Validating parameter values")
285+
is_valid, missing = CacheParameterHandler.validate_parameters(
286+
trajectory, parameter_values
287287
)
288288
if not is_valid:
289289
error_msg = (
290-
f"Missing required placeholder values: {', '.join(missing)}\n"
291-
f"The trajectory contains the following placeholders: "
292-
f"{', '.join(cache_placeholders.keys())}\n"
293-
f"Please provide values for all placeholders in the "
294-
f"placeholder_values parameter."
290+
f"Missing required parameter values: {', '.join(missing)}\n"
291+
f"The trajectory contains the following parameters: "
292+
f"{', '.join(cache_parameters.keys())}\n"
293+
f"Please provide values for all parameters in the "
294+
f"parameter_values parameter."
295295
)
296296
logger.error(error_msg)
297297
return error_msg
@@ -300,14 +300,14 @@ def _validate_placeholders(
300300
def _create_executor(
301301
self,
302302
cache_file: "CacheFile",
303-
placeholder_values: dict[str, str],
303+
parameter_values: dict[str, str],
304304
start_from_step_index: int,
305305
) -> "TrajectoryExecutor":
306306
"""Create and configure trajectory executor.
307307
308308
Args:
309309
cache_file: The cache file to execute
310-
placeholder_values: Placeholder values to use
310+
parameter_values: Parameter values to use
311311
start_from_step_index: Index to start execution from
312312
313313
Returns:
@@ -324,7 +324,7 @@ def _create_executor(
324324
executor = TrajectoryExecutor(
325325
trajectory=cache_file.trajectory,
326326
toolbox=self._toolbox,
327-
placeholder_values=placeholder_values,
327+
parameter_values=parameter_values,
328328
delay_time=self._settings.delay_time_between_action,
329329
)
330330

@@ -342,15 +342,15 @@ def _format_success_message(
342342
trajectory_file: str,
343343
trajectory_length: int,
344344
start_from_step_index: int,
345-
placeholder_count: int,
345+
parameter_count: int,
346346
) -> str:
347347
"""Format success message.
348348
349349
Args:
350350
trajectory_file: Path to trajectory file
351351
trajectory_length: Total steps in trajectory
352352
start_from_step_index: Starting step index
353-
placeholder_count: Number of placeholders used
353+
parameter_count: Number of parameters used
354354
355355
Returns:
356356
Formatted success message
@@ -369,8 +369,8 @@ def _format_success_message(
369369
f"Will execute {remaining_steps} remaining cached steps."
370370
)
371371

372-
if placeholder_count > 0:
373-
success_msg += f" Using {placeholder_count} placeholder value(s)."
372+
if parameter_count > 0:
373+
success_msg += f" Using {parameter_count} parameter value(s)."
374374

375375
return success_msg
376376

@@ -380,7 +380,7 @@ def __call__(
380380
self,
381381
trajectory_file: str,
382382
start_from_step_index: int = 0,
383-
placeholder_values: dict[str, str] | None = None,
383+
parameter_values: dict[str, str] | None = None,
384384
) -> str:
385385
"""Activate cache execution mode for the agent.
386386
@@ -390,8 +390,8 @@ def __call__(
390390
Returns:
391391
Success message indicating cache mode has been activated
392392
"""
393-
if placeholder_values is None:
394-
placeholder_values = {}
393+
if parameter_values is None:
394+
parameter_values = {}
395395

396396
logger.info(
397397
"Activating cache execution mode: %s (start_from_step=%d)",
@@ -417,9 +417,9 @@ def __call__(
417417
cache_file = CacheWriter.read_cache_file(Path(trajectory_file))
418418

419419
logger.debug(
420-
"Cache loaded: %d steps, %d placeholders, valid=%s",
420+
"Cache loaded: %d steps, %d parameters, valid=%s",
421421
len(cache_file.trajectory),
422-
len(cache_file.placeholders),
422+
len(cache_file.cache_parameters),
423423
cache_file.metadata.is_valid,
424424
)
425425

@@ -439,15 +439,15 @@ def __call__(
439439
):
440440
return error
441441

442-
# Validate placeholders
443-
if error := self._validate_placeholders(
444-
cache_file.trajectory, placeholder_values, cache_file.placeholders
442+
# Validate parameters
443+
if error := self._validate_parameters(
444+
cache_file.trajectory, parameter_values, cache_file.cache_parameters
445445
):
446446
return error
447447

448448
# Create and configure executor
449449
executor = self._create_executor(
450-
cache_file, placeholder_values, start_from_step_index
450+
cache_file, parameter_values, start_from_step_index
451451
)
452452

453453
# Store executor and cache info in agent state
@@ -462,7 +462,7 @@ def __call__(
462462
trajectory_file,
463463
len(cache_file.trajectory),
464464
start_from_step_index,
465-
len(placeholder_values),
465+
len(parameter_values),
466466
)
467467
logger.info(success_msg)
468468
return success_msg
@@ -483,7 +483,7 @@ def __init__(self) -> None:
483483
"- Execution statistics (attempts, last execution time)\n"
484484
"- Validity status and invalidation reason (if invalid)\n"
485485
"- Failure history with timestamps and error messages\n"
486-
"- Placeholders and trajectory step count\n\n"
486+
"- Parameters and trajectory step count\n\n"
487487
"Use this tool to debug cache issues or understand why a cache "
488488
"might be failing or invalidated."
489489
),
@@ -556,10 +556,10 @@ def __call__(self, trajectory_file: str) -> str:
556556
lines.append("")
557557
lines.append("--- Trajectory Info ---")
558558
lines.append(f"Total Steps: {len(cache_file.trajectory)}")
559-
lines.append(f"Placeholders: {len(cache_file.placeholders)}")
560-
if cache_file.placeholders:
559+
lines.append(f"Parameters: {len(cache_file.cache_parameters)}")
560+
if cache_file.cache_parameters:
561561
lines.append(
562-
f"Placeholder Names: {', '.join(cache_file.placeholders.keys())}"
562+
f"Parameter Names: {', '.join(cache_file.cache_parameters.keys())}"
563563
)
564564

565565
if metadata.failures:

0 commit comments

Comments
 (0)