agentdebugx 0.2.8__tar.gz → 0.2.9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/PKG-INFO +1 -1
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/23_status_v0_2.md +2 -2
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/pyproject.toml +1 -1
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/__init__.py +5 -1
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/recovery.py +281 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/LICENSE +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/README.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/00_overview.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/01_literature_survey.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/02_architecture.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/03_taxonomy.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/04_trace_schema.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/05_adapters.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/06_detectors.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/07_attribution.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/08_recovery.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/09_error_database.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/10_taxonomy_induction.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/11_multimodal.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/12_ui_dashboard.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/13_class_design.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/14_api_reference.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/15_roadmap.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/16_governance.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/17_claude_code_design_patterns.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/18_comparison_codex_vs_design.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/19_error_hub.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/20_deep_debug.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/21_integrations.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/22_industry_track_paper_eval_plan.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/ERROR_TAXONOMY.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/OPEN_SOURCE_DEVELOPMENT_PLAN.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/README.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/RESEARCH_SURVEY.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/benchmarks/e2e_v0_2_3.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/benchmarks/e2e_v0_2_4.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/benchmarks/v0_1_smoke.json +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/benchmarks/v0_1_smoke.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/docs/benchmarks/who_when_v0_2_6_leaderboard.md +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/adapters/__init__.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/adapters/base.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/adapters/crewai.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/adapters/langgraph.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/adapters/otel.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/adapters/raw.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/analyzers.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/attribution.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/cli.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/deep.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/detectors.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/events.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/hub/__init__.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/hub/backend_base.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/hub/backends.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/hub/bundle.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/hub/scrub.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/instrumentation.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/integrations/__init__.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/integrations/claude_skill.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/integrations/openhands.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/judges.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/llm.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/models.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/recorder.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/storage.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/taxonomy.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/traceback.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/ui/__init__.py +0 -0
- {agentdebugx-0.2.8 → agentdebugx-0.2.9}/src/agentdebug/ui/server.py +0 -0
|
@@ -25,6 +25,8 @@ the forward-looking plan; this doc is the rear-view mirror.
|
|
|
25
25
|
| Attribution | `agentdebug.attribution.SBFLAttributor` (Tarantula / Ochiai / DStar) | ✅ **new 0.2.8** | signature design + ranking on synthetic corpus + 3 formulas + dual fallback + edge cases. Model-free: zero LLM cost at inference. |
|
|
26
26
|
| Recovery | `agentdebug.recovery.ReflexionSuggestion` | ✅ stable | per-finding + empty |
|
|
27
27
|
| Recovery | `agentdebug.recovery.CriticRecoverer` + `VerifierSpec` registry | ✅ **new 0.2.3** | 5 family-matched verifier templates; dedup + custom-override |
|
|
28
|
+
| Recovery | `agentdebug.recovery.SelfRefineLoop` | ✅ **new 0.2.9** | scripted-LLM happy + silent-LLM safe + multi-iter; per-finding generator→critic→refiner |
|
|
29
|
+
| Recovery | `agentdebug.recovery.AutoManualRules` (+ `apply()`) | ✅ **new 0.2.9** | no-LLM fallback + LLM rule-distill + idempotent apply + multi-rule append |
|
|
28
30
|
| DeepDebug | `agentdebug.deep.DeepDebugAnalyzer` | ✅ stable | full loop + silent LLM |
|
|
29
31
|
| Cascade view | `agentdebug.traceback.format_traceback` | ✅ stable | cascade + step-order + ANSI + empty |
|
|
30
32
|
| Detectors | `agentdebug.detectors.RepeatedToolCall / RepeatedState / StepCountLimit` | ✅ **new 0.2.2** | threshold + window + budget |
|
|
@@ -53,8 +55,6 @@ across 32 source files.
|
|
|
53
55
|
| [07_attribution.md](./07_attribution.md) | `SBFLAttributor` — *corpus* | shipped in 0.2.8 (`tarantula`/`ochiai`/`dstar`); awaiting paired-trace adoption to gather a useful corpus in production | corpus tooling deferred to v0.4 |
|
|
54
56
|
| [07_attribution.md](./07_attribution.md) | `DeltaDebugAttributor` (Zeller) | same replay constraint | v0.3 |
|
|
55
57
|
| [07_attribution.md](./07_attribution.md) | `EnsembleAttributor` | trivial once Counterfactual lands; awaits Counterfactual | v0.3 |
|
|
56
|
-
| [08_recovery.md](./08_recovery.md) | `SelfRefineLoop` | small but needs a generator-critic-refiner orchestration | v0.3 |
|
|
57
|
-
| [08_recovery.md](./08_recovery.md) | `AutoManualRules` | needs persistent project manual + injection into next-run prompts | v0.3 |
|
|
58
58
|
| [08_recovery.md](./08_recovery.md) | `LangGraphRewind` | depends on LangGraph checkpointer; ships when we have a real LangGraph user | v0.3 |
|
|
59
59
|
| [08_recovery.md](./08_recovery.md) | `SagaRollback` | needs compensation registry on tool definitions; new schema | v0.3 |
|
|
60
60
|
| [08_recovery.md](./08_recovery.md) | `MCTSBranchExploration` (LATS) | heavy; v2 feature | v2.0 |
|
|
@@ -43,10 +43,12 @@ from agentdebug.models import (
|
|
|
43
43
|
from agentdebug.recorder import AgentDebug, TraceSession
|
|
44
44
|
from agentdebug.recovery import (
|
|
45
45
|
DEFAULT_VERIFIERS,
|
|
46
|
+
AutoManualRules,
|
|
46
47
|
CriticRecoverer,
|
|
47
48
|
FixProposal,
|
|
48
49
|
Recoverer,
|
|
49
50
|
ReflexionSuggestion,
|
|
51
|
+
SelfRefineLoop,
|
|
50
52
|
VerifierSpec,
|
|
51
53
|
)
|
|
52
54
|
from agentdebug.traceback import CascadeFrame, build_cascade, format_traceback
|
|
@@ -63,6 +65,7 @@ __all__ = [
|
|
|
63
65
|
'Attributor',
|
|
64
66
|
'Blame',
|
|
65
67
|
'BusEvent',
|
|
68
|
+
'AutoManualRules',
|
|
66
69
|
'BinarySearchAttributor',
|
|
67
70
|
'CascadeFrame',
|
|
68
71
|
'CounterfactualAttributor',
|
|
@@ -73,6 +76,7 @@ __all__ = [
|
|
|
73
76
|
'RepeatedStateDetector',
|
|
74
77
|
'RepeatedToolCallDetector',
|
|
75
78
|
'SBFLAttributor',
|
|
79
|
+
'SelfRefineLoop',
|
|
76
80
|
'StepByStepAttributor',
|
|
77
81
|
'StepCountLimitDetector',
|
|
78
82
|
'VerifierSpec',
|
|
@@ -100,4 +104,4 @@ __all__ = [
|
|
|
100
104
|
'get_failure_mode',
|
|
101
105
|
]
|
|
102
106
|
|
|
103
|
-
__version__ = '0.2.
|
|
107
|
+
__version__ = '0.2.9'
|
|
@@ -304,11 +304,292 @@ class CriticRecoverer:
|
|
|
304
304
|
)
|
|
305
305
|
|
|
306
306
|
|
|
307
|
+
_SELF_REFINE_CRITIC_PROMPT = """You are AgentDebugX-SelfRefine acting as the
|
|
308
|
+
CRITIC. You will be shown the goal of a failed agent run and a single
|
|
309
|
+
failure finding (mode + step + evidence).
|
|
310
|
+
|
|
311
|
+
Your job: in 2-4 short sentences, explain WHAT went wrong at that step and
|
|
312
|
+
WHY it caused the failure. Do not propose a fix yet — that's the next round.
|
|
313
|
+
Be concrete; reference the evidence.
|
|
314
|
+
|
|
315
|
+
Output plain text. No JSON, no markdown."""
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
_SELF_REFINE_REFINER_PROMPT = """You are AgentDebugX-SelfRefine acting as the
|
|
319
|
+
REFINER. You will be shown the goal of a failed agent run, a single failure
|
|
320
|
+
finding, AND the CRITIC's analysis of what went wrong.
|
|
321
|
+
|
|
322
|
+
Your job: produce a single concrete REFINED ACTION the agent should take
|
|
323
|
+
NEXT TIME at that step. 2-4 short sentences. Plain text. Be operational —
|
|
324
|
+
the agent will read this verbatim as guidance.
|
|
325
|
+
|
|
326
|
+
If the failure is in tool args, give the exact corrected arg shape. If the
|
|
327
|
+
failure is in planning, give the next plan step. If the failure is in
|
|
328
|
+
reflection, give the next verification check.
|
|
329
|
+
|
|
330
|
+
Output plain text. No JSON, no markdown."""
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
class SelfRefineLoop:
|
|
334
|
+
"""Self-Refine (Madaan et al., NeurIPS 2023, arXiv:2303.17651) recovery.
|
|
335
|
+
|
|
336
|
+
Suggest-only — we do NOT re-execute the agent. For each finding, run a
|
|
337
|
+
bounded generator-critic-refiner cycle: CRITIC explains what went
|
|
338
|
+
wrong, REFINER proposes a concrete next-attempt action. The cycle can
|
|
339
|
+
iterate ``max_iters`` times; each iteration costs 2 LLM calls.
|
|
340
|
+
|
|
341
|
+
Output is a :class:`FixProposal` whose ``suggestion_text`` contains
|
|
342
|
+
both the critic analysis and the refiner's concrete action. Pair with
|
|
343
|
+
:class:`ReflexionSuggestion` for short verbal hints and
|
|
344
|
+
:class:`CriticRecoverer` for verifier-template recommendations.
|
|
345
|
+
"""
|
|
346
|
+
|
|
347
|
+
id = 'self_refine'
|
|
348
|
+
|
|
349
|
+
def __init__(
|
|
350
|
+
self,
|
|
351
|
+
llm: object,
|
|
352
|
+
*,
|
|
353
|
+
max_iters: int = 1,
|
|
354
|
+
max_tokens: int = 512,
|
|
355
|
+
) -> None:
|
|
356
|
+
# llm is duck-typed to LLMClient (avoid circular import); it must have
|
|
357
|
+
# a `.complete(messages=..., max_tokens=...)` returning .text.
|
|
358
|
+
self.llm = llm
|
|
359
|
+
self.max_iters = max(1, max_iters)
|
|
360
|
+
self.max_tokens = max_tokens
|
|
361
|
+
|
|
362
|
+
def suggest(
|
|
363
|
+
self,
|
|
364
|
+
trajectory: AgentTrajectory,
|
|
365
|
+
report: DiagnosticReport,
|
|
366
|
+
) -> List[FixProposal]:
|
|
367
|
+
if not report.findings:
|
|
368
|
+
return []
|
|
369
|
+
proposals: List[FixProposal] = []
|
|
370
|
+
for finding in report.findings:
|
|
371
|
+
proposal = self._refine_one(trajectory, finding)
|
|
372
|
+
if proposal is not None:
|
|
373
|
+
proposals.append(proposal)
|
|
374
|
+
return proposals
|
|
375
|
+
|
|
376
|
+
def _refine_one(
|
|
377
|
+
self,
|
|
378
|
+
trajectory: AgentTrajectory,
|
|
379
|
+
finding: FailureFinding,
|
|
380
|
+
) -> Optional[FixProposal]:
|
|
381
|
+
evidence_block = '\n'.join(f' - {e}' for e in finding.evidence) or ' (none)'
|
|
382
|
+
finding_block = (
|
|
383
|
+
f'GOAL: {trajectory.goal!r}\n'
|
|
384
|
+
f'FAILURE MODE: {finding.failure_mode.mode_id} '
|
|
385
|
+
f'({finding.failure_mode.name})\n'
|
|
386
|
+
f'AT: agent={finding.agent_name}, step={finding.step_index}\n'
|
|
387
|
+
f'EVIDENCE:\n{evidence_block}'
|
|
388
|
+
)
|
|
389
|
+
last_critic = ''
|
|
390
|
+
last_refined = ''
|
|
391
|
+
try:
|
|
392
|
+
for _ in range(self.max_iters):
|
|
393
|
+
critic_text = self._call(
|
|
394
|
+
system=_SELF_REFINE_CRITIC_PROMPT,
|
|
395
|
+
user=finding_block + (
|
|
396
|
+
f'\n\nPRIOR REFINED ACTION (improve on this if needed):\n'
|
|
397
|
+
f'{last_refined}' if last_refined else ''
|
|
398
|
+
),
|
|
399
|
+
)
|
|
400
|
+
if not critic_text:
|
|
401
|
+
break
|
|
402
|
+
last_critic = critic_text
|
|
403
|
+
refined_text = self._call(
|
|
404
|
+
system=_SELF_REFINE_REFINER_PROMPT,
|
|
405
|
+
user=finding_block + f'\n\nCRITIC ANALYSIS:\n{critic_text}',
|
|
406
|
+
)
|
|
407
|
+
if not refined_text:
|
|
408
|
+
break
|
|
409
|
+
last_refined = refined_text
|
|
410
|
+
except Exception:
|
|
411
|
+
# Defensive: never break the host pipeline on LLM hiccup.
|
|
412
|
+
pass
|
|
413
|
+
if not last_critic and not last_refined:
|
|
414
|
+
return None
|
|
415
|
+
suggestion_text = (
|
|
416
|
+
f'Self-Refine output (after {self.max_iters} iter(s)) for '
|
|
417
|
+
f'{finding.failure_mode.mode_id} at step {finding.step_index}:\n\n'
|
|
418
|
+
f'CRITIC:\n{last_critic or "(no critic output)"}\n\n'
|
|
419
|
+
f'REFINED ACTION:\n{last_refined or "(no refined action)"}'
|
|
420
|
+
)
|
|
421
|
+
return FixProposal(
|
|
422
|
+
proposal_id=new_id('fix'),
|
|
423
|
+
recoverer_id=self.id,
|
|
424
|
+
target_event_id=finding.event_id,
|
|
425
|
+
summary=(
|
|
426
|
+
f'Self-Refine action for {finding.failure_mode.mode_id} '
|
|
427
|
+
f'at step {finding.step_index}'
|
|
428
|
+
),
|
|
429
|
+
rationale=(
|
|
430
|
+
'Self-Refine (Madaan et al., NeurIPS 2023): one LM acts as '
|
|
431
|
+
'critic, then refiner; output is a concrete next-attempt '
|
|
432
|
+
'action the agent reads verbatim.'
|
|
433
|
+
),
|
|
434
|
+
confidence=max(0.3, min(0.9, finding.confidence)),
|
|
435
|
+
suggestion_text=suggestion_text,
|
|
436
|
+
side_effects=[],
|
|
437
|
+
requires_human_approval=False,
|
|
438
|
+
)
|
|
439
|
+
|
|
440
|
+
def _call(self, *, system: str, user: str) -> str:
|
|
441
|
+
messages = [
|
|
442
|
+
{'role': 'system', 'content': system},
|
|
443
|
+
{'role': 'user', 'content': user},
|
|
444
|
+
]
|
|
445
|
+
# Direct attribute access — llm is duck-typed (see __init__ note).
|
|
446
|
+
result = self.llm.complete( # type: ignore[attr-defined]
|
|
447
|
+
messages=messages, max_tokens=self.max_tokens
|
|
448
|
+
)
|
|
449
|
+
text = getattr(result, 'text', '') or ''
|
|
450
|
+
return str(text).strip()
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
class AutoManualRules:
|
|
454
|
+
"""AutoManual-style learned rule extraction (Chen et al., NeurIPS 2024,
|
|
455
|
+
arXiv:2405.16247).
|
|
456
|
+
|
|
457
|
+
Distills each failure finding into a one-line rule. ``suggest()`` returns
|
|
458
|
+
one :class:`FixProposal` per finding whose ``suggestion_text`` holds the
|
|
459
|
+
rule. ``apply()`` appends accepted rules to a per-project Markdown manual
|
|
460
|
+
(``~/.agentdebug/manuals/<project>.md`` by default) which downstream
|
|
461
|
+
runs can prepend to their agent's system prompt to avoid re-hitting the
|
|
462
|
+
same failure.
|
|
463
|
+
|
|
464
|
+
Unlike :class:`ReflexionSuggestion` (short verbal hint per attempt) and
|
|
465
|
+
:class:`SelfRefineLoop` (heavy generator-critic-refiner per finding),
|
|
466
|
+
this is the LONG-TERM memory: small, append-only, surviving across runs.
|
|
467
|
+
Apply is opt-in because it writes to the filesystem.
|
|
468
|
+
"""
|
|
469
|
+
|
|
470
|
+
id = 'auto_manual'
|
|
471
|
+
|
|
472
|
+
DEFAULT_MANUAL_DIR = '~/.agentdebug/manuals'
|
|
473
|
+
|
|
474
|
+
def __init__(
|
|
475
|
+
self,
|
|
476
|
+
*,
|
|
477
|
+
llm: Optional[object] = None,
|
|
478
|
+
manual_dir: Optional[str] = None,
|
|
479
|
+
project: str = 'default',
|
|
480
|
+
max_tokens: int = 256,
|
|
481
|
+
) -> None:
|
|
482
|
+
# llm is optional — if absent, we synthesize a rule from the finding's
|
|
483
|
+
# suggestion template rather than calling out.
|
|
484
|
+
self.llm = llm
|
|
485
|
+
self.manual_dir = manual_dir or self.DEFAULT_MANUAL_DIR
|
|
486
|
+
self.project = project
|
|
487
|
+
self.max_tokens = max_tokens
|
|
488
|
+
|
|
489
|
+
def suggest(
|
|
490
|
+
self,
|
|
491
|
+
trajectory: AgentTrajectory,
|
|
492
|
+
report: DiagnosticReport,
|
|
493
|
+
) -> List[FixProposal]:
|
|
494
|
+
if not report.findings:
|
|
495
|
+
return []
|
|
496
|
+
proposals: List[FixProposal] = []
|
|
497
|
+
for finding in report.findings:
|
|
498
|
+
rule = self._rule_for(trajectory, finding)
|
|
499
|
+
if not rule:
|
|
500
|
+
continue
|
|
501
|
+
proposals.append(FixProposal(
|
|
502
|
+
proposal_id=new_id('fix'),
|
|
503
|
+
recoverer_id=self.id,
|
|
504
|
+
target_event_id=finding.event_id,
|
|
505
|
+
summary=(
|
|
506
|
+
f'Add rule to {self.project} manual: '
|
|
507
|
+
f'"{rule[:80]}{"…" if len(rule) > 80 else ""}"'
|
|
508
|
+
),
|
|
509
|
+
rationale=(
|
|
510
|
+
'AutoManual (Chen et al., NeurIPS 2024): distill the '
|
|
511
|
+
'failure into a one-line rule the next run reads via its '
|
|
512
|
+
'system prompt. Long-term memory complements per-attempt '
|
|
513
|
+
'Reflexion and per-finding Self-Refine.'
|
|
514
|
+
),
|
|
515
|
+
confidence=max(0.4, min(0.9, finding.confidence)),
|
|
516
|
+
suggestion_text=rule,
|
|
517
|
+
side_effects=['manual.write'],
|
|
518
|
+
requires_human_approval=False,
|
|
519
|
+
))
|
|
520
|
+
return proposals
|
|
521
|
+
|
|
522
|
+
def apply(self, proposal: FixProposal) -> str:
|
|
523
|
+
"""Append the proposal's rule to the project manual; return the path."""
|
|
524
|
+
from pathlib import Path
|
|
525
|
+
|
|
526
|
+
target = Path(self.manual_dir).expanduser() / f'{self.project}.md'
|
|
527
|
+
target.parent.mkdir(parents=True, exist_ok=True)
|
|
528
|
+
existing = target.read_text(encoding='utf-8') if target.exists() else ''
|
|
529
|
+
if not existing:
|
|
530
|
+
header = f'# AgentDebugX learned manual — {self.project}\n\n'
|
|
531
|
+
existing = header + '<!-- auto-generated; safe to edit. -->\n\n'
|
|
532
|
+
# Idempotent: skip if the rule is already present (case-insensitive).
|
|
533
|
+
rule = proposal.suggestion_text.strip()
|
|
534
|
+
if rule.lower() in existing.lower():
|
|
535
|
+
return str(target)
|
|
536
|
+
target.write_text(
|
|
537
|
+
existing + f'- {rule}\n',
|
|
538
|
+
encoding='utf-8',
|
|
539
|
+
)
|
|
540
|
+
return str(target)
|
|
541
|
+
|
|
542
|
+
def _rule_for(
|
|
543
|
+
self,
|
|
544
|
+
trajectory: AgentTrajectory,
|
|
545
|
+
finding: FailureFinding,
|
|
546
|
+
) -> Optional[str]:
|
|
547
|
+
# If no LLM, fall back to the finding's suggestion template.
|
|
548
|
+
if self.llm is None:
|
|
549
|
+
if finding.suggestion:
|
|
550
|
+
return str(finding.suggestion)
|
|
551
|
+
if finding.failure_mode.suggestion_templates:
|
|
552
|
+
return str(finding.failure_mode.suggestion_templates[0])
|
|
553
|
+
return None
|
|
554
|
+
prompt_system = (
|
|
555
|
+
'You distill failure findings into ONE-LINE actionable rules for '
|
|
556
|
+
'an agent to follow next time. Output plain text — a single '
|
|
557
|
+
'sentence under 200 characters. No JSON, no markdown, no '
|
|
558
|
+
'preamble. Start with an imperative verb ("Validate ...", '
|
|
559
|
+
'"Always ...", "Before ..."). Be specific to the failure.'
|
|
560
|
+
)
|
|
561
|
+
evidence = '; '.join(finding.evidence) or '(no evidence)'
|
|
562
|
+
prompt_user = (
|
|
563
|
+
f'Goal: {trajectory.goal!r}\n'
|
|
564
|
+
f'Failure mode: {finding.failure_mode.mode_id} '
|
|
565
|
+
f'({finding.failure_mode.name})\n'
|
|
566
|
+
f'Agent: {finding.agent_name} at step {finding.step_index}\n'
|
|
567
|
+
f'Evidence: {evidence}'
|
|
568
|
+
)
|
|
569
|
+
try:
|
|
570
|
+
result = self.llm.complete( # type: ignore[attr-defined]
|
|
571
|
+
messages=[
|
|
572
|
+
{'role': 'system', 'content': prompt_system},
|
|
573
|
+
{'role': 'user', 'content': prompt_user},
|
|
574
|
+
],
|
|
575
|
+
max_tokens=self.max_tokens,
|
|
576
|
+
)
|
|
577
|
+
except Exception:
|
|
578
|
+
return str(finding.suggestion) if finding.suggestion else None
|
|
579
|
+
text = getattr(result, 'text', '') or ''
|
|
580
|
+
rule = str(text).strip().splitlines()[0] if text.strip() else ''
|
|
581
|
+
if not rule:
|
|
582
|
+
return str(finding.suggestion) if finding.suggestion else None
|
|
583
|
+
return rule
|
|
584
|
+
|
|
585
|
+
|
|
307
586
|
__all__ = [
|
|
587
|
+
'AutoManualRules',
|
|
308
588
|
'CriticRecoverer',
|
|
309
589
|
'DEFAULT_VERIFIERS',
|
|
310
590
|
'FixProposal',
|
|
311
591
|
'Recoverer',
|
|
312
592
|
'ReflexionSuggestion',
|
|
593
|
+
'SelfRefineLoop',
|
|
313
594
|
'VerifierSpec',
|
|
314
595
|
]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|