Skip to content

API Reference parrot_tools.contracts.agent

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

parrot_tools.contracts.agent

View source

The ReAct contracts agent for chat and MCP (FEAT-539 M10).

The agent explores with the contracts toolkit and proposes an answer — but it never releases one. Whatever the model produces is a draft; the released answer always comes from the same :class:~parrot_tools.contracts.service.ContractsAnswerService the fixed flow uses, with the same authorization, citation verification and audit.

Consequences worth stating explicitly:

  • a tool result or a model reply that invents a clause cannot escape, because the citation gate re-checks every quote against archived evidence;
  • an error anywhere (tool, provider, service) never degrades to "answer with the raw model text"; it degrades to a refusal;
  • streaming buffers the substantive answer until the gate has finished.

Attribute CONTRACTS_SYSTEM_PROMPT

Class ContractsAgent

ReAct agent over the contracts toolkit, gated by the shared service.

Parameter Type Default Description
*args Any ()
service ContractsAnswerService The shared answer service (the only release path).
request_context RequestContext The trusted request context.
library Any None Optional contract library for section reads.
**kwargs Any {} Forwarded to :class:~parrot.bots.Agent.

Attributes:

Attribute Type Description
agent_id str
temperature float

Method ContractsAgent.agent_tools

Expose the contracts toolkit's tools to the ReAct loop.

agent_tools() -> list[Any]

Returns: list[Any]

Method ContractsAgent.answer_question

Answer through the shared gate.

The model's reply is only ever a draft: authorization, citation verification and audit all happen in the service.

answer_question(question: str, *, request_context: Optional[RequestContext] = None) -> AnswerOutcome | Clarification

Parameter Type Default Description
question str The user's question.
request_context Optional[RequestContext] None Overrides the agent's trusted context.

Returns: AnswerOutcome | Clarification — class:AnswerOutcome or a typed :class:Clarification.

Raises:

  • ServiceUnavailable — When the outcome could not be audited.

Method ContractsAgent.stream_answer

Stream a verified answer; nothing substantive escapes early.

stream_answer(question: str, *, request_context: Optional[RequestContext] = None) -> AsyncIterator[str]

Parameter Type Default Description
question str
request_context Optional[RequestContext] None

Returns: AsyncIterator[str]

Method ContractsAgent.ask

Refuse: use :meth:answer_question, which passes the gate.

ask(*args: Any, **kwargs: Any) -> Any

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Returns: Any

Method ContractsAgent.ask_stream

Refuse: use :meth:stream_answer, which passes the gate.

ask_stream(*args: Any, **kwargs: Any) -> Any

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Returns: Any

Method ContractsAgent.invoke

Refuse: use :meth:answer_question, which passes the gate.

invoke(*args: Any, **kwargs: Any) -> Any

Parameter Type Default Description
*args Any ()
**kwargs Any {}

Returns: Any

Method ContractsAgent.released_answer

Return the released answer of an outcome, if there is one.

released_answer(outcome: AnswerOutcome | Clarification) -> Optional[ContractAnswer]

Parameter Type Default Description
outcome AnswerOutcome | Clarification

Returns: Optional[ContractAnswer]

Class ContractsAgentProducer

Adapts a ReAct agent to the service's AnswerProducer protocol.

Parameter Type Default Description
agent Any Anything exposing async ask(...) (or question(...)) — a :class:~parrot.bots.Agent, or a test double.
max_claims int 20 Hard bound on the claims taken from one reply.
today Any None

Attributes:

Attribute Type Description
last_reply Optional[str]

Method ContractsAgentProducer.draft

Ask the agent for a draft over the request-scoped dossier.

The reply is split into claims and paired with the evidence the deterministic retrieval already authorized. Nothing here releases anything: the service verifies every claim afterwards.

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

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

Returns: AnswerDraft

Class UngatedAnswerRefused

An unverified answer was requested through an ungated entrypoint.

The contracts agent only ever drafts. Releasing a draft requires the service gate (authorization, citation verification against archived evidence, retirement suppression and an audit record), so the generic bot entrypoints refuse rather than return unverified prose.

Parameter Type Default Description
entrypoint str

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