- 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>
98 lines
3.4 KiB
Python
98 lines
3.4 KiB
Python
from odoo import fields, models
|
|
|
|
|
|
class FlAnalysis(models.Model):
|
|
"""AI case analysis record. Written by the Claude API engine (fl.ai.engine)."""
|
|
_name = 'fl.analysis'
|
|
_description = 'AI Case Analysis Result'
|
|
_order = 'create_date desc'
|
|
|
|
case_id = fields.Many2one(
|
|
'fl.case', ondelete='cascade', index=True
|
|
)
|
|
analysis_type = fields.Selection([
|
|
('engine', 'AI Engine Analysis'),
|
|
('attorney', 'Attorney Strategy Memo'),
|
|
], string='Analysis Type', default='engine')
|
|
analysis_date = fields.Datetime(
|
|
string='Analysis Date',
|
|
default=fields.Datetime.now
|
|
)
|
|
model_used = fields.Char(
|
|
string='AI Model',
|
|
default='claude-sonnet-4-20250514'
|
|
)
|
|
|
|
# ── Results (referenced by fl_case related fields) ─────────────────────
|
|
attorney_referral_flag = fields.Boolean(
|
|
string='Attorney Referral Recommended',
|
|
default=False
|
|
)
|
|
attorney_referral_reason = fields.Text(
|
|
string='Attorney Referral Reason'
|
|
)
|
|
plain_english_summary = fields.Text(
|
|
string='Plain English Summary (EN)',
|
|
help='3-5 sentence summary of case analysis — no legal jargon'
|
|
)
|
|
plain_english_summary_es = fields.Text(
|
|
string='Plain English Summary (ES)',
|
|
help='Resumen en español — sin jerga legal'
|
|
)
|
|
|
|
# ── Attorney Strategy Memo ─────────────────────────────────────────────
|
|
strategy_memo = fields.Html(
|
|
string='Strategy Memo',
|
|
help='Substantive strategy memo authored by the Attorney agent.'
|
|
)
|
|
risk_narrative = fields.Text(
|
|
string='Risk Narrative',
|
|
help='Narrative of substantive risks: DV, hidden assets, income '
|
|
'imputation, unrepresented respondent, etc.'
|
|
)
|
|
cited_statute_ids = fields.Many2many(
|
|
'fl.statute',
|
|
'fl_analysis_statute_rel',
|
|
'analysis_id', 'statute_id',
|
|
string='Cited Statutes'
|
|
)
|
|
|
|
# ── Analysis Detail (Phase 5) ──────────────────────────────────────────
|
|
petitioner_arguments = fields.Text(
|
|
string='Petitioner Arguments (JSON)'
|
|
)
|
|
respondent_counterarguments = fields.Text(
|
|
string='Respondent Counter-Arguments (JSON)'
|
|
)
|
|
procedural_risks = fields.Text(
|
|
string='Procedural Risks (JSON)'
|
|
)
|
|
matched_caselaw_ids = fields.Many2many(
|
|
'fl.caselaw',
|
|
'fl_analysis_caselaw_rel',
|
|
'analysis_id', 'caselaw_id',
|
|
string='Matched Case Law'
|
|
)
|
|
confidence_level = fields.Selection([
|
|
('high', 'High'),
|
|
('medium', 'Medium'),
|
|
('low', 'Low'),
|
|
], string='Confidence Level')
|
|
case_complexity = fields.Selection([
|
|
('simple', 'Simple'),
|
|
('moderate', 'Moderate'),
|
|
('complex', 'Complex'),
|
|
], string='Case Complexity')
|
|
raw_response = fields.Text(
|
|
string='Raw AI Response',
|
|
help='Full JSON response from the Claude API — for debugging'
|
|
)
|
|
error_message = fields.Text(
|
|
string='Error (if analysis failed)'
|
|
)
|
|
state = fields.Selection([
|
|
('pending', 'Pending'),
|
|
('complete', 'Complete'),
|
|
('failed', 'Failed'),
|
|
], string='Status', default='pending')
|