Add Attorney AI agent (substantive strategy memo)

- fl.attorney.agent (AbstractModel): manual-only substantive analysis fired from
  the case AI tab. Builds a full case context (parties, children, financials,
  issue tags, prior analyses) plus candidate statute/caselaw lists, and asks
  Claude to author a strategy memo, draft arguments/counterarguments, write a
  risk narrative, and assess substantial change (FL 61.30(1)(b))
- Grounds output in the real library: the model may only pick statutes/case law
  from the supplied candidates, which are then resolved back to records and
  linked (fl.analysis.cited_statute_ids / matched_caselaw_ids, case.caselaw_ids)
- Rule-based fallback produces a usable memo (complexity, statutes by category,
  caselaw by tag, risk flags) when the API is unavailable — never a raw error
- fl.analysis: add analysis_type, strategy_memo (Html), risk_narrative,
  cited_statute_ids; surface them in the analysis views
- fl.case: add attorney_memo_id + related memo/risk display; action_run_attorney_agent
  opens the memo; "Generate Attorney Strategy Memo" button on the AI tab (admin)
- Refactor fl_ai_engine: extract shared call_claude_json(system, user) +
  _extract_json so both agents and the engine share one Claude/JSON path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-05-29 00:12:20 +00:00
parent 23c54b1b9f
commit 465c049251
7 changed files with 441 additions and 13 deletions

View File

@@ -434,6 +434,19 @@ class FlCase(models.Model):
string='Latest Analysis',
compute='_compute_latest_analysis', store=True
)
attorney_memo_id = fields.Many2one(
'fl.analysis',
string='Attorney Strategy Memo',
help='Current strategy memo produced by the Attorney agent.'
)
attorney_memo_html = fields.Html(
string='Strategy Memo',
related='attorney_memo_id.strategy_memo'
)
attorney_risk_narrative = fields.Text(
string='Risk Narrative',
related='attorney_memo_id.risk_narrative'
)
attorney_referral_flag = fields.Boolean(
string='Attorney Referral Recommended',
compute='_compute_attorney_referral_flag', store=True
@@ -1159,3 +1172,15 @@ class FlCase(models.Model):
'sticky': False,
},
}
def action_run_attorney_agent(self):
self.ensure_one()
memo = self.env['fl.attorney.agent'].generate_strategy_memo(self)
return {
'type': 'ir.actions.act_window',
'name': 'Attorney Strategy Memo',
'res_model': 'fl.analysis',
'res_id': memo.id,
'view_mode': 'form',
'target': 'current',
}