Skip to content

Adapter: record CHAP human-decision events from Pydantic AI tool approvals #2

Description

@brightbeamarsalan

Goal

A small adapter so a Pydantic AI app emits a CHAP human-decision record whenever a human approves, edits, or denies a deferred tool call. A merged adapter is strong evidence CHAP is usable in real agent stacks, and Pydantic AI's typed, approval-gated tools map almost one-to-one onto CHAP's record.

Where it hooks

Pydantic AI handles human-in-the-loop through deferred tools. A tool marked requires_approval=True, or gated by an ApprovalRequiredToolset, ends the run with a DeferredToolRequests output whose approvals list holds the pending ToolCallParts. The caller resolves them into DeferredToolResults using ToolApproved or ToolDenied, either after the run or inline via a handle_deferred_tool_calls hook. The adapter records each decision at that resolution point.

Mapping (Pydantic AI to CHAP)

  • the pending ToolCallPart (tool name, validated args, tool_call_id) is the referenced artifact the human acts on
  • ToolApproved() with no change is an approve, decision kept
  • ToolApproved(override_args=...) is a refining override; original args versus override_args is the diff
  • ToolDenied(message=...) is a reject or escalate, and the message is the rationale
  • DeferredToolResults.metadata[tool_call_id] carries the rationale and the CHAP tags
  • records hash-chain, with an optional transparency-log anchor via the audit-scitt profile

Scope

  • A helper wrapping the approval-resolution step, or a handle_deferred_tool_calls hook, that emits one CHAP record per decision
  • A minimal runnable example: one approval-gated tool, with a human approving, editing args, and denying, producing a valid CHAP chain
  • Emitted records pass the CHAP conformance harness
  • A short README section showing the integration

Out of scope

Changing Pydantic AI itself, or anything in MCP core. This is application-layer and reads from the existing deferred-tools API.

Pointers

CHAP spec and README in this repo; the protocol-neutral record shape (link the shape issue once it exists); the conformance harness; Pydantic AI's deferred-tools and human-in-the-loop docs at ai.pydantic.dev.

Metadata

Metadata

Labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions