Skip to content

API Reference parrot_tools.contracts.flow

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_tools.contracts.flow

View source

The fixed, executable contracts answer flow (FEAT-539 M10).

This is a runner, not an inspection artifact: ContractsAnswerFlow.run actually executes the stages and returns an audited answer, which is what API, A2A and the scheduled report jobs call. (The legal librarian's crew builder is a precedent for the shape of the stages, not a promise that a crew object is executable — so this module does not depend on one.)

Stages, in order:

triage -> retrieve -> dossier -> draft -> verify -> audit -> release

Only draft involves a model, exactly once, statelessly, from an enumerated dossier that lists the ONLY citable evidence for the turn. Denied, clarification and handoff outcomes short-circuit before the draft, so an empty or refused request never spends a model call.

Class ContractsAnswerFlow

Executable fixed answer flow for API, A2A and scheduled reports.

Parameter Type Default Description
service ContractsAnswerService The shared answer service (gate, verifier, audit).
producer Optional[ContractsDraftProducer] None The draft producer; defaults to a stateless one built from adapter.
adapter Any None Structured-output adapter for the single draft call.

Method ContractsAnswerFlow.run

Execute the fixed flow once and return an audited outcome.

run(question: str, *, request_context: RequestContext) -> FlowRun

Parameter Type Default Description
question str The question to answer.
request_context RequestContext The trusted request context.

Returns: FlowRun — class:FlowRun recording the stages that executed, how many draft calls were spent and the released outcome (an class:AnswerOutcome or a typed clarification).

Method ContractsAnswerFlow.answer

Convenience entrypoint returning just the released outcome.

answer(question: str, *, request_context: RequestContext) -> Any

Parameter Type Default Description
question str
request_context RequestContext

Returns: Any

Class ContractsDraftProducer

The service's :class:AnswerProducer, backed by one stateless call.

Parameter Type Default Description
adapter Any None A PageIndexLLMAdapter-shaped structured-output client, or None for a deterministic evidence-only draft.
max_entries int 20 Hard bound on the enumerated dossier.

Attributes:

Attribute Type Description
last_dossier list[DossierEntry]

Method ContractsDraftProducer.enumerate_dossier

Enumerate the ONLY evidence this turn may cite.

Obligation patterns use their retrieved clauses. Other patterns prioritize relevant field provenance and may include card obligations; historical questions use the selected immutable version snapshots.

enumerate_dossier(result: RetrievalResult, dossier: Sequence[ContractCard], *, max_entries: int = 20) -> list[DossierEntry]

Parameter Type Default Description
result RetrievalResult
dossier Sequence[ContractCard]
max_entries int 20

Returns: list[DossierEntry]

Method ContractsDraftProducer.render

Render the enumerated dossier prompt.

render(question: str, entries: Sequence[DossierEntry], as_of: date) -> str

Parameter Type Default Description
question str
entries Sequence[DossierEntry]
as_of date

Returns: str

Method ContractsDraftProducer.draft

Produce one draft from the enumerated dossier.

Exactly one stateless structured call; no conversation history is read or written. Without an adapter the draft is built deterministically from the evidence itself.

draft(question: str, result: RetrievalResult, dossier: Sequence[ContractCard]) -> AnswerDraft

Parameter Type Default Description
question str
result RetrievalResult
dossier Sequence[ContractCard]

Returns: AnswerDraft

Attribute DRAFT_SYSTEM_PROMPT

Class DossierEntry

One enumerated, citable piece of evidence for this turn.

Fields:

Field Type Default Description
evidence_id str
contract_id str
title str
node_id str
quote str
page Optional[int] None
version_n int 1
source_sha256 str ''

Method DossierEntry.citation

Build the citation this entry authorises.

citation() -> Citation

Returns: Citation

Class DraftClaim

One claim the model proposes, citing dossier evidence ids.

Fields:

Field Type Default Description
text str ''
evidence_ids list[str]

Attribute FLOW_STAGES

Type: tuple[str, ...]

Class FlowDraft

Structured output of the single draft call.

Fields:

Field Type Default Description
claims list[DraftClaim]

Class FlowRun

What one runner invocation actually did.

Fields:

Field Type Default Description
stages list[str]
draft_calls int 0
dossier_size int 0
outcome Optional[Any] None

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally