Skip to content

[PRE-446] Add named quality schema support - #21

Merged
joshgillies merged 2 commits into
mainfrom
pre-446-add-named-quality-schema-support-to-the-python-core-sdk
Aug 4, 2026
Merged

[PRE-446] Add named quality schema support #21
joshgillies merged 2 commits into
mainfrom
pre-446-add-named-quality-schema-support-to-the-python-core-sdk

Conversation

@joshgillies

@joshgillies joshgillies commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Replace the single quality_schema/quality_payload model with named quality schemas and keyed payloads to match the updated API:

Schema registration:

  • SchemaRegistry.register_quality_schema() now takes a required name and stores entries in a list, emitting quality_schemas (array) in to_agent_schema_version() instead of quality_schema (single object)
  • Multiple quality schemas can be registered with unique names
  • merge() detects duplicate quality schema name conflicts

HTTP models:

  • QualitySchemaForCreate gains a required name field
  • QualitySchemaDetails gains a required name field
  • AgentSchemaVersionForRegister: quality_schema → quality_schemas (list[QualitySchemaForCreate])
  • AgentInstance: quality_payload → quality_payloads (dict[str, dict]), quality_summary → quality_summaries (dict[str, str])
  • AgentInstanceForUpdate → AgentInstanceRecordQuality with name and payload fields

HTTP endpoints:

  • AgentInstanceClient.update() → record_quality() hitting POST /api/v1/agent_instance/{id}/record_quality with {name, payload}

Core client/manager:

  • PrefactorCoreClient.update_agent_instance() → record_quality()
  • AgentInstanceManager.update() → record_quality()
  • AgentInstanceHandle.update() → record_quality()
  • OperationType.UPDATE_AGENT_INSTANCE → RECORD_QUALITY

Summary by CodeRabbit

  • New Features

    • Added support for registering multiple named quality schemas.
    • Added named quality recording with optional per-schema payloads.
    • Agent instances now expose quality payloads and summaries by schema.
    • Added idempotency support for quality-recording requests.
  • Bug Fixes

    • Improved validation for duplicate schema names, request parameters, and response contracts.
  • Documentation

    • Refreshed Quick Start and client examples with clearer formatting.
  • Tests

    • Added coverage for quality schemas, registration, merging, recording, validation, and API responses.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1cb6778c-39ef-4c18-a755-43a66439baf0

📥 Commits

Reviewing files that changed from the base of the PR and between 2184e98 and d67a801.

📒 Files selected for processing (4)
  • packages/core/src/prefactor_core/client.py
  • packages/core/src/prefactor_core/managers/agent_instance.py
  • packages/core/tests/test_schema_registry.py
  • packages/http/src/prefactor_http/models/agent_instance.py
🚧 Files skipped from review as they are similar to previous changes (4)
  • packages/core/tests/test_schema_registry.py
  • packages/core/src/prefactor_core/client.py
  • packages/core/src/prefactor_core/managers/agent_instance.py
  • packages/http/src/prefactor_http/models/agent_instance.py

📝 Walkthrough

Walkthrough

The SDK now supports named quality schemas, per-schema payloads, RECORD_QUALITY operations, and the record_quality API across the core and HTTP packages. README examples also receive formatting-only updates.

Changes

Named quality recording

Layer / File(s) Summary
Named schema contracts and registry
packages/core/src/prefactor_core/models.py, packages/core/src/prefactor_core/schema_registry.py, packages/core/tests/test_schema_registry.py, packages/http/src/prefactor_http/models/agent_instance.py, packages/http/tests/test_models.py
Quality schemas now require names and support multiple entries. Agent instances expose named payload and summary maps. Registry serialization and merging use quality_schemas.
HTTP record-quality API
packages/http/src/prefactor_http/endpoints/agent_instance.py, packages/http/src/prefactor_http/models/*, packages/http/src/prefactor_http/__init__.py, packages/http/tests/test_endpoints.py
The HTTP client replaces update with record_quality, sends named payloads to /record_quality, preserves idempotency handling, and validates responses.
Core record-quality operation flow
packages/core/src/prefactor_core/operations.py, packages/core/src/prefactor_core/client.py, packages/core/src/prefactor_core/managers/agent_instance.py
Core APIs replace update with record_quality and queue or process RECORD_QUALITY operations containing the instance ID, schema name, and payload.
Documentation example formatting
README.md, packages/core/README.md, packages/http/README.md, packages/langchain/README.md
Examples receive line-break, blank-line, and inline-comment spacing updates without behavior changes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AgentInstanceHandle
  participant AgentInstanceManager
  participant PrefactorCoreClient
  participant AgentInstanceClient
  AgentInstanceHandle->>AgentInstanceManager: record_quality(name, payload)
  AgentInstanceManager->>PrefactorCoreClient: queue RECORD_QUALITY operation
  PrefactorCoreClient->>AgentInstanceClient: send named quality data
  AgentInstanceClient-->>PrefactorCoreClient: return updated instance
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding support for named quality schemas.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pre-446-add-named-quality-schema-support-to-the-python-core-sdk

Comment @coderabbitai help to get the list of available commands.

@joshgillies joshgillies changed the title [PRE-446]: Add named quality schema support [PRE-446] Add named quality schema support Aug 4, 2026
Replace the single quality_schema/quality_payload model with named
quality schemas and keyed payloads to match the updated API:

Schema registration:
- SchemaRegistry.register_quality_schema() now takes a required name
  and stores entries in a list, emitting quality_schemas (array) in
  to_agent_schema_version() instead of quality_schema (single object)
- Multiple quality schemas can be registered with unique names
- merge() detects duplicate quality schema name conflicts

HTTP models:
- QualitySchemaForCreate gains a required name field
- QualitySchemaDetails gains a required name field
- AgentSchemaVersionForRegister: quality_schema → quality_schemas
  (list[QualitySchemaForCreate])
- AgentInstance: quality_payload → quality_payloads (dict[str, dict]),
  quality_summary → quality_summaries (dict[str, str])
- AgentInstanceForUpdate → AgentInstanceRecordQuality with name and
  payload fields

HTTP endpoints:
- AgentInstanceClient.update() → record_quality() hitting
  POST /api/v1/agent_instance/{id}/record_quality with {name, payload}

Core client/manager:
- PrefactorCoreClient.update_agent_instance() → record_quality()
- AgentInstanceManager.update() → record_quality()
- AgentInstanceHandle.update() → record_quality()
- OperationType.UPDATE_AGENT_INSTANCE → RECORD_QUALITY

Co-authored-by: Cursor <cursoragent@cursor.com>
@joshgillies
joshgillies force-pushed the pre-446-add-named-quality-schema-support-to-the-python-core-sdk branch from 1948032 to 2184e98 Compare August 4, 2026 00:55
@joshgillies
joshgillies marked this pull request as ready for review August 4, 2026 01:12

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
packages/core/src/prefactor_core/managers/agent_instance.py (1)

192-218: 🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win

Preserve idempotency across queued quality-record retries.

A quality record can be retried after the server accepted an earlier attempt. Without a stable idempotency key, that retry can overwrite a newer payload for the same schema name.

  • packages/core/src/prefactor_core/managers/agent_instance.py#L192-L218: generate an idempotency key when creating the RECORD_QUALITY operation and store it in payload.
  • packages/core/src/prefactor_core/client.py#L336-L340: pass the stored key to AgentInstanceClient.record_quality.
Proposed fix
-            payload={
+            payload={
                 "instance_id": instance_id,
                 "name": name,
                 "payload": payload,
+                "idempotency_key": generate_idempotency_key(),
             },

                 await self._http.agent_instances.record_quality(
                     agent_instance_id=operation.payload["instance_id"],
                     name=operation.payload["name"],
                     payload=operation.payload.get("payload"),
+                    idempotency_key=operation.payload["idempotency_key"],
                 )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/core/src/prefactor_core/managers/agent_instance.py` around lines 192
- 218, Preserve idempotency for queued quality records by generating a stable
idempotency key when record_quality creates the RECORD_QUALITY Operation and
storing it in the operation payload; update
packages/core/src/prefactor_core/managers/agent_instance.py lines 192-218
accordingly. In packages/core/src/prefactor_core/client.py lines 336-340, pass
the stored key to AgentInstanceClient.record_quality.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/core/tests/test_schema_registry.py`:
- Around line 1-4: Add from __future__ import annotations immediately after the
module docstring in the test module and before the pytest and SchemaRegistry
imports.

In `@packages/http/src/prefactor_http/models/agent_instance.py`:
- Around line 126-137: Update the docstrings for QualitySchemaForCreate,
QualitySchemaDetails, and AgentInstanceRecordQuality to describe quality_schemas
as a list rather than a map, and revise the name attribute description to
identify it as the unique identifier of a quality schema entry.

---

Outside diff comments:
In `@packages/core/src/prefactor_core/managers/agent_instance.py`:
- Around line 192-218: Preserve idempotency for queued quality records by
generating a stable idempotency key when record_quality creates the
RECORD_QUALITY Operation and storing it in the operation payload; update
packages/core/src/prefactor_core/managers/agent_instance.py lines 192-218
accordingly. In packages/core/src/prefactor_core/client.py lines 336-340, pass
the stored key to AgentInstanceClient.record_quality.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 532cec36-ad3f-4e13-b9b9-668d733bd66a

📥 Commits

Reviewing files that changed from the base of the PR and between f4b06fb and 2184e98.

📒 Files selected for processing (16)
  • README.md
  • packages/core/README.md
  • packages/core/src/prefactor_core/client.py
  • packages/core/src/prefactor_core/managers/agent_instance.py
  • packages/core/src/prefactor_core/models.py
  • packages/core/src/prefactor_core/operations.py
  • packages/core/src/prefactor_core/schema_registry.py
  • packages/core/tests/test_schema_registry.py
  • packages/http/README.md
  • packages/http/src/prefactor_http/__init__.py
  • packages/http/src/prefactor_http/endpoints/agent_instance.py
  • packages/http/src/prefactor_http/models/__init__.py
  • packages/http/src/prefactor_http/models/agent_instance.py
  • packages/http/tests/test_endpoints.py
  • packages/http/tests/test_models.py
  • packages/langchain/README.md

Comment thread packages/core/tests/test_schema_registry.py
Comment thread packages/http/src/prefactor_http/models/agent_instance.py
- Add from __future__ import annotations to test_schema_registry.py
- Correct docstrings: name is the unique identifier of a quality
  schema entry, not 'key in the quality_schemas map'
- Add idempotency key to RECORD_QUALITY operation for retry safety,
  matching the pattern used by start/finish operations
@joshgillies
joshgillies merged commit b4c72dc into main Aug 4, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant