Keep repair context across agent retries
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-08-27 20:02:47 +02:00
parent e90db58194
commit dd86d8cd2d
3 changed files with 64 additions and 4 deletions

View File

@@ -43,6 +43,21 @@ schema/semantics, and fix SQL-generation guidance rather than rewriting one unkn
to another guessed column. TenantDatabaseService records the explicit source type in
database.connections.<connection>.tenant_type; use that metadata instead of database-name
patterns or heuristics.
"""
sql_semantics = ''
if report.category in {'incorrect_answer', 'sql_execution'}:
sql_semantics = """
SQL repair guidance:
When the SQL is syntactically valid but uses the wrong business calculation, prefer adding or
correcting tracked domain knowledge in config/*_semantics.php so the schema prompt teaches the
model the right joins, filters, and formula. Do not hardcode one user's question or article ID
in SQLGeneratorService, and do not add post-generation replacement of guessed SQL.
For regression coverage of prompt guidance, expose the relevant protected schema/business-
context builder through a test subclass and assert that its real output contains the required
formula and rules. Do not mock AIService to return the known-bad SQL and then expect prompt
guidance to rewrite that mocked response. Keep database fixture tests only when production code
itself deterministically builds and executes the SQL under test.
"""
return f"""You are fixing failure report #{report.id} in the Laravel AI Chat repository.
@@ -80,15 +95,18 @@ Observed error:
Generated SQL, if relevant:
{sql or '[not available]'}
{tenant_scope}
{sql_semantics}
Run focused tests while working. Leave the repository with the fix and regression test applied.
"""
def build_retry_task(exception: Exception) -> str:
def build_retry_task(report: FailureReport, exception: Exception) -> str:
failure = redact(str(exception))[-6_000:]
return f"""The previous implementation failed isolated validation.
return build_task(report) + f"""
The previous implementation failed isolated validation.
Correct the existing changes using this test output:

View File

@@ -57,6 +57,7 @@ class AutomationWorker:
attempt,
)
task = build_retry_task(
report,
RuntimeError(
"No file changes were applied. Make the smallest concrete code and regression-test edits now."
)
@@ -76,7 +77,7 @@ class AutomationWorker:
report.id,
attempt,
)
task = build_retry_task(exception)
task = build_retry_task(report, exception)
summary = workspace.summary()
metadata["changes"] = asdict(summary)