feat(phase-2.5): Task 6 cost_kind attribution + fees_eat_alpha threshold CLI
Task 6 del piano Phase 2.5 (deferito → ora completato): - CostRecord: nuovo campo call_kind (default "hypothesis") - CostTracker.record: accetta call_kind opzionale, summary include by_call_kind breakdown (hypothesis vs mutation) - Schema cost_records: aggiunta colonna call_kind TEXT NOT NULL DEFAULT 'hypothesis' + migration soft via ALTER TABLE in init_schema (silently catched per DB pre-Task 6) - Repository.save_cost_record: nuova arg call_kind opzionale - mutate_prompt_llm: accetta cost_tracker/repo/run_id opzionali e logga la call mutator con call_kind="mutation" quando sink presente - weighted_random_mutate, next_generation: propagano cost sink - orchestrator.run_phase1: passa cost_tracker+repo+run_id a next_generation solo se prompt_mutation_weight > 0 Esposto fees_eat_alpha_threshold come parametro AdversarialAgent (default 0.5 = comportamento Phase 1.5 invariato), propagato via RunConfig.fees_eat_alpha_threshold e flag CLI --fees-eat-alpha-threshold. Abilita ablation con soglia 0.7-0.8 senza modificare codice — adversarial finding dominante in tutti i run Phase 2/2.5 (50+ HIGH per run). Tests (+4 → 186 totale): - test_cost_tracker: default call_kind="hypothesis"; breakdown by_call_kind con hypothesis+mutation - test_mutation_prompt_llm: logging mutation cost con sink completo; backward compat senza sink (no errore) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -130,6 +130,9 @@ def mutate_prompt_llm(
|
||||
rng: random.Random,
|
||||
mutator_tier: ModelTier = ModelTier.B,
|
||||
max_tokens: int = 2000,
|
||||
cost_tracker: Any | None = None,
|
||||
repo: Any | None = None,
|
||||
run_id: str | None = None,
|
||||
) -> HypothesisAgentGenome:
|
||||
"""Operatore di mutazione prompt-level via LLM mutator.
|
||||
|
||||
@@ -137,6 +140,9 @@ def mutate_prompt_llm(
|
||||
LLM tier B per ottenere il prompt mutato, valida l'output. Su validation
|
||||
fail (output troppo corto, non-strategia, troppo simile al parent),
|
||||
fallback silenzioso a ``random_mutate``.
|
||||
|
||||
Se ``cost_tracker``, ``repo`` e ``run_id`` sono forniti, la chiamata mutator
|
||||
viene registrata con ``call_kind="mutation"`` per audit budget.
|
||||
"""
|
||||
instruction_key = rng.choice(list(MUTATION_INSTRUCTIONS))
|
||||
instruction = MUTATION_INSTRUCTIONS[instruction_key]
|
||||
@@ -160,6 +166,28 @@ def mutate_prompt_llm(
|
||||
except Exception:
|
||||
return random_mutate(g, rng)
|
||||
|
||||
# Cost tracking call_kind="mutation" se sink fornito.
|
||||
if cost_tracker is not None and repo is not None and run_id is not None:
|
||||
in_tok = getattr(result, "input_tokens", 0)
|
||||
out_tok = getattr(result, "output_tokens", 0)
|
||||
cr = cost_tracker.record(
|
||||
input_tokens=in_tok,
|
||||
output_tokens=out_tok,
|
||||
tier=mutator_tier,
|
||||
run_id=run_id,
|
||||
agent_id=g.id,
|
||||
call_kind="mutation",
|
||||
)
|
||||
repo.save_cost_record(
|
||||
run_id=run_id,
|
||||
agent_id=g.id,
|
||||
tier=mutator_tier.value,
|
||||
input_tokens=in_tok,
|
||||
output_tokens=out_tok,
|
||||
cost_usd=cr.cost_usd,
|
||||
call_kind="mutation",
|
||||
)
|
||||
|
||||
new_prompt = _extract_prompt(getattr(result, "text", ""))
|
||||
if not is_valid_prompt(new_prompt, g.system_prompt):
|
||||
return random_mutate(g, rng)
|
||||
|
||||
Reference in New Issue
Block a user