Skip to content

API Reference parrot.flows.dev_loop.gate_adapter

github-actions[bot] edited this page Dec 2, 2026 · 1 revision

parrot.flows.dev_loop.gate_adapter

View source

Bridge dev-loop ApprovalGate ⇄ generic GateRecord (FEAT-890 M3).

Persisted dev-loop runs carry :class:ApprovalGate objects inside the Redis-streamed gate/opened actions. :class:DevLoopGateAdapter converts them losslessly to and from the generic :class:GateRecord of parrot.bots.flows.core.gates so they survive the gate-host hard cut.

Field mapping (ApprovalGate → GateRecord):

  • gate_id, kind, status, payload_ref, opened_at, expires_at, resolved_by, resolved_at, comment, answers map 1:1 onto the record's top-level fields.
  • title, instructions, questions, on_expiry live in the record's :class:GateSpec; spec.ttl_seconds is derived as round(expires_at - opened_at) when the gate has an expiry. The exact expires_at stays on the record, so the derived TTL never loses data.
  • node_id has no slot in GateRecord (payload_ref already holds the evidence URI and the model is closed). Decision: the adapter does NOT encode it; the caller owns it — it is passed back explicitly to :meth:DevLoopGateAdapter.from_record. Callers that need to recover it from the record alone use the owner convention f"{run_id}:{node_id}" when calling :meth:DevLoopGateAdapter.to_record.

Class DevLoopGateAdapter

Lossless conversion for persisted dev-loop gates.

Method DevLoopGateAdapter.to_record

Convert a dev-loop gate into a generic gate record.

to_record(gate: ApprovalGate, *, owner: str) -> GateRecord

Parameter Type Default Description
gate ApprovalGate The persisted dev-loop gate.
owner str Record owner (by convention f"{run_id}:{node_id}").

Returns: GateRecord — The equivalent :class:GateRecord; gate.node_id is not stored (see the module docstring).

Raises:

  • GateError — UNKNOWN_KIND when gate.kind is not a registered gate kind (call :func:register_devloop_gate_kinds first).

Method DevLoopGateAdapter.from_record

Inverse of :meth:to_record.

from_record(record: GateRecord, *, node_id: str) -> ApprovalGate

Parameter Type Default Description
record GateRecord A gate record produced by :meth:to_record.
node_id str The dev-loop node that opened the gate.

Returns: ApprovalGate — class:ApprovalGate; from_record(to_record(g), node_id=g.node_id) == g.

Raises:

  • GateError — UNKNOWN_KIND when record.kind is not a dev-loop gate kind.
  • pydantic.ValidationError — node_id is not a dev-loop node id.

Function register_devloop_gate_kinds

Register every dev-loop GateKind as a generic string kind (idempotent).

register_devloop_gate_kinds() -> 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