Make dbn-legal-agent-v3 checker context-aware; wire into LegalAnalysisAgent
Three fixes: 1. bootstrap.php dbnToolsRunLegalCheck(): prepend first 350 chars of synthesis text to the v3 user message so it validates actual content, not just general law. 2. BvjAnalyzerAgent: fix engine guard — was skipping check for claude_sonnet/haiku; now skips only when dbn_legal_v3 is the synthesis model (it already IS the check). 3. LegalAnalysisAgent: add post-synthesis dbnToolsRunLegalCheck() call after Pass 3; add 'legal_check' key to runFullAnalysis() return. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -958,9 +958,10 @@ PROMPT;
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6b: dbn-legal-agent targeted legal Q&A check (azure + gpu engines only;
|
// Step 6b: dbn-legal-agent targeted legal Q&A check.
|
||||||
// skipped when dbn_legal_v3 is the synthesis engine — it already IS the legal model).
|
// Skipped only when dbn_legal_v3 is the synthesis engine — it already IS the legal model.
|
||||||
if (in_array($engine, ['azure_mini', 'azure_full', 'gpu'], true)) {
|
// All other engines (azure_mini, azure_full, gpu, claude_sonnet, claude_haiku) get the check.
|
||||||
|
if ($engine !== 'dbn_legal_v3') {
|
||||||
$checkFindings = dbnToolsRunLegalCheck(
|
$checkFindings = dbnToolsRunLegalCheck(
|
||||||
(string)($json['advocacy_brief'] ?? ''),
|
(string)($json['advocacy_brief'] ?? ''),
|
||||||
$docType
|
$docType
|
||||||
|
|||||||
@@ -362,6 +362,15 @@ PROMPT;
|
|||||||
$emit('progress', ['step' => 'synthesising', 'detail' => 'Synthesising overall assessment…']);
|
$emit('progress', ['step' => 'synthesising', 'detail' => 'Synthesising overall assessment…']);
|
||||||
$synth = $this->synthesise($answered, $language, $docType);
|
$synth = $this->synthesise($answered, $language, $docType);
|
||||||
|
|
||||||
|
// Post-synthesis legal check — dbn-legal-agent-v3 validates the overall assessment
|
||||||
|
$legalCheck = [];
|
||||||
|
try {
|
||||||
|
$legalCheck = dbnToolsRunLegalCheck(
|
||||||
|
mb_strimwidth($synth['overall_assessment'], 0, 800),
|
||||||
|
$docType
|
||||||
|
);
|
||||||
|
} catch (Throwable) {}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'ok' => true,
|
'ok' => true,
|
||||||
'issues' => $answered,
|
'issues' => $answered,
|
||||||
@@ -370,6 +379,7 @@ PROMPT;
|
|||||||
'disclaimer' => $synth['disclaimer'],
|
'disclaimer' => $synth['disclaimer'],
|
||||||
'doc_type' => $docType,
|
'doc_type' => $docType,
|
||||||
'model' => self::LEGAL_MODEL,
|
'model' => self::LEGAL_MODEL,
|
||||||
|
'legal_check' => $legalCheck,
|
||||||
'latency_ms' => (int)round(microtime(true) * 1000) - $startMs,
|
'latency_ms' => (int)round(microtime(true) * 1000) - $startMs,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1175,12 +1175,19 @@ function dbnToolsRunLegalCheck(string $brief, string $docType): array
|
|||||||
|
|
||||||
$sysMsg = 'Du er en ekspert på norsk barnevernsloven og EMD-praksis. Svar alltid på norsk med korrekt juridisk terminologi. Bruk terskler fra barnevernsloven 2021: § 4-25 krever «klar nødvendighet». Strand Lobben mot Norge (37283/13) setter krav om rehabiliteringsplan før adopsjon. Aldri oppfinn paragrafnumre, saksnumre eller dommernavn.';
|
$sysMsg = 'Du er en ekspert på norsk barnevernsloven og EMD-praksis. Svar alltid på norsk med korrekt juridisk terminologi. Bruk terskler fra barnevernsloven 2021: § 4-25 krever «klar nødvendighet». Strand Lobben mot Norge (37283/13) setter krav om rehabiliteringsplan før adopsjon. Aldri oppfinn paragrafnumre, saksnumre eller dommernavn.';
|
||||||
|
|
||||||
|
// Prepend a short snippet of the actual synthesis text so v3 answers in context,
|
||||||
|
// not just as a general law quiz. Strip HTML tags and cap at 350 chars.
|
||||||
|
$snippet = mb_strimwidth(strip_tags($brief), 0, 350, '…');
|
||||||
|
$userMsg = $snippet !== ''
|
||||||
|
? "Tekst fra dokumentet:\n{$snippet}\n\n{$question}"
|
||||||
|
: $question;
|
||||||
|
|
||||||
$text = '';
|
$text = '';
|
||||||
try {
|
try {
|
||||||
$response = dbnToolsCallGpuLlm(
|
$response = dbnToolsCallGpuLlm(
|
||||||
[
|
[
|
||||||
['role' => 'system', 'content' => $sysMsg],
|
['role' => 'system', 'content' => $sysMsg],
|
||||||
['role' => 'user', 'content' => $question],
|
['role' => 'user', 'content' => $userMsg],
|
||||||
],
|
],
|
||||||
$opts
|
$opts
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user