Files
cleveragents-core/benchmarks/automation_profile_bench.py
T
CoreRasurae 007af498b8
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 17s
CI / helm (pull_request) Successful in 33s
CI / lint (pull_request) Successful in 3m42s
CI / security (pull_request) Successful in 4m8s
CI / quality (pull_request) Successful in 4m9s
CI / typecheck (pull_request) Successful in 4m20s
CI / integration_tests (pull_request) Successful in 7m2s
CI / unit_tests (pull_request) Successful in 7m55s
CI / docker (pull_request) Successful in 1m19s
CI / coverage (pull_request) Successful in 8m46s
CI / e2e_tests (pull_request) Successful in 16m1s
CI / status-check (pull_request) Successful in 1s
CI / build (push) Successful in 17s
CI / helm (push) Successful in 22s
CI / quality (push) Successful in 31s
CI / lint (push) Successful in 3m28s
CI / typecheck (push) Successful in 3m54s
CI / benchmark-regression (push) Has been skipped
CI / security (push) Successful in 4m5s
CI / integration_tests (push) Successful in 6m13s
CI / unit_tests (push) Successful in 6m28s
CI / docker (push) Successful in 1m34s
CI / coverage (push) Successful in 12m5s
CI / e2e_tests (push) Successful in 18m47s
CI / status-check (push) Successful in 1s
CI / benchmark-publish (push) Successful in 28m0s
CI / benchmark-regression (pull_request) Successful in 59m48s
refactor(autonomy): rename automation profile task flags to spec names
Renamed all 11 task-type confidence threshold fields in AutomationProfile
from phase-transition semantics to spec-defined task-type semantics.
Updated all 8 built-in profiles, CLI formatting, YAML schema, services,
and all Behave/Robot tests referencing the old field names.

Post-review fixes:
- Fixed 24 stale old field names in M6 fixture files
  (automation_profiles.json, autonomy_guardrails.json)
- Added model_validator(mode='before') to detect legacy field names
  and raise actionable ValueError with rename mapping
- Added semantic bridge comments in PlanLifecycleService mapping
  task-type thresholds to phase-transition gates
- Added threshold_field to structured log messages for observability
- Restored categorised CLI automation-profile show output to match
  spec (Phase Transitions / Decision Automation / Self-Repair /
  Execution Controls) instead of flat list
- Added missing access_network field to spec show output examples
  (Rich, Plain, JSON, YAML variants)
- Aligned ADR-017 profile fields table to all 11 fields with
  descriptions matching spec Automatable Tasks table
- Aligned automation_profiles.md threshold descriptions with spec
- Added spec section references in phase_reversion.md, error_recovery.md,
  and plan_execute.md for field naming context
- Extended repository roundtrip test to assert all 11 threshold fields
- Fixed benchmark _make_profile() passing safety fields as top-level
  kwargs instead of via SafetyProfile sub-model (incompatible with
  extra="forbid")
- Aligned CLI JSON/YAML output structure for automation-profile show
  with the specification grouped format (phase_transitions,
  decision_automation, self_repair, execution_controls)
- Moved safety boolean fields into the Execution Controls section
  of Rich output per spec examples
- Reverted auto profile description to "Fully automatic except apply"
  per specification (line 16703, line 28406)
- Improved bridge comments in test steps with semantic context for
  threshold-to-gate mappings

ISSUES CLOSED: #902
2026-03-30 13:18:07 +01:00

196 lines
6.3 KiB
Python

"""ASV benchmarks for AutomationProfile validation, serialization, and guards.
Measures the performance of:
- AutomationProfile model construction (Pydantic validation)
- AutomationProfile.model_dump() serialization
- AutomationProfile.from_config() factory
- Built-in profile lookup via get_builtin_profile()
- BUILTIN_PROFILES iteration
- AutomationGuard check_guard() enforcement overhead
"""
from __future__ import annotations
import sys
from pathlib import Path
try:
from cleveragents.domain.models.core.automation_guard import (
AutomationGuard,
)
from cleveragents.domain.models.core.automation_profile import (
BUILTIN_PROFILES,
AutomationProfile,
get_builtin_profile,
)
from cleveragents.domain.models.core.safety_profile import SafetyProfile
except ModuleNotFoundError:
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))
from cleveragents.domain.models.core.automation_guard import (
AutomationGuard,
)
from cleveragents.domain.models.core.automation_profile import (
BUILTIN_PROFILES,
AutomationProfile,
get_builtin_profile,
)
from cleveragents.domain.models.core.safety_profile import SafetyProfile
def _make_profile() -> AutomationProfile:
"""Create a fully-populated profile for benchmarking."""
return AutomationProfile(
name="bench/test-profile",
description="Benchmark profile",
decompose_task=0.7,
create_tool=0.5,
select_tool=1.0,
edit_code=0.6,
execute_command=0.8,
create_file=0.3,
delete_content=0.9,
access_network=0.4,
install_dependency=0.7,
modify_config=0.1,
approve_plan=0.5,
safety=SafetyProfile(
require_sandbox=True,
require_checkpoints=True,
allow_unsafe_tools=False,
),
)
class ProfileValidationSuite:
"""Benchmark AutomationProfile construction."""
def time_profile_construction(self) -> None:
"""Benchmark fully-populated profile creation."""
_make_profile()
def time_profile_minimal_construction(self) -> None:
"""Benchmark minimal profile creation."""
AutomationProfile(name="bench/minimal")
def time_profile_all_thresholds_max(self) -> None:
"""Benchmark profile with all thresholds at 1.0."""
AutomationProfile(
name="bench/max",
decompose_task=1.0,
create_tool=1.0,
select_tool=1.0,
edit_code=1.0,
execute_command=1.0,
create_file=1.0,
delete_content=1.0,
access_network=1.0,
install_dependency=1.0,
modify_config=1.0,
approve_plan=1.0,
)
class ProfileSerializationSuite:
"""Benchmark AutomationProfile serialization."""
def setup(self) -> None:
"""Create objects for serialization benchmarks."""
self.profile = _make_profile()
def time_profile_model_dump(self) -> None:
"""Benchmark model_dump() serialization."""
self.profile.model_dump()
def time_profile_model_dump_json(self) -> None:
"""Benchmark model_dump_json() JSON serialization."""
self.profile.model_dump_json()
class ProfileFromConfigSuite:
"""Benchmark AutomationProfile.from_config() factory."""
def setup(self) -> None:
"""Prepare config dicts for benchmarks."""
self.config = {
"name": "bench/from-config",
"description": "Config benchmark",
"decompose_task": 0.7,
"create_tool": 0.5,
"select_tool": 1.0,
}
def time_profile_from_config(self) -> None:
"""Benchmark from_config()."""
AutomationProfile.from_config(self.config)
class BuiltinProfileSuite:
"""Benchmark built-in profile operations."""
def time_get_builtin_profile(self) -> None:
"""Benchmark get_builtin_profile() lookup."""
get_builtin_profile("cautious")
def time_iterate_all_builtins(self) -> None:
"""Benchmark iterating all built-in profiles."""
for name in BUILTIN_PROFILES:
_ = BUILTIN_PROFILES[name]
class GuardCheckSuite:
"""Benchmark AutomationGuard check_guard() operations."""
def setup(self) -> None:
"""Create profiles with various guard configurations."""
self.no_guard_profile = AutomationProfile(name="bench/no-guard")
self.guarded_profile = AutomationProfile(
name="bench/guarded",
guards=AutomationGuard(
max_tool_calls_per_step=10,
max_total_cost=100.0,
tool_denylist=["dangerous_tool"],
tool_allowlist=["safe_tool", "read_file", "list_dir"],
require_approval_for_writes=True,
require_approval_for_apply=True,
),
)
self.minimal_guard = AutomationProfile(
name="bench/minimal-guard",
guards=AutomationGuard(max_tool_calls_per_step=50),
)
def time_check_guard_no_guards(self) -> None:
"""Benchmark check_guard with no guards configured."""
self.no_guard_profile.check_guard("any_tool")
def time_check_guard_allowed(self) -> None:
"""Benchmark check_guard when tool is allowed."""
self.guarded_profile.check_guard("safe_tool", calls_so_far=5)
def time_check_guard_denied(self) -> None:
"""Benchmark check_guard when tool is on denylist."""
self.guarded_profile.check_guard("dangerous_tool")
def time_check_guard_write(self) -> None:
"""Benchmark check_guard with write flag."""
self.guarded_profile.check_guard("safe_tool", is_write=True)
def time_check_guard_cost(self) -> None:
"""Benchmark check_guard with cost check."""
self.guarded_profile.check_guard(
"safe_tool",
cost_so_far=50.0,
)
def time_check_guard_minimal(self) -> None:
"""Benchmark check_guard with minimal guard config."""
self.minimal_guard.check_guard("tool", calls_so_far=10)
def time_guard_construction(self) -> None:
"""Benchmark AutomationGuard model construction."""
AutomationGuard(
max_tool_calls_per_step=10,
max_total_cost=100.0,
tool_denylist=["tool_a", "tool_b"],
)