[PRE-446] Add named quality schema support - #21
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (4)
📝 WalkthroughWalkthroughThe SDK now supports named quality schemas, per-schema payloads, ChangesNamed quality recording
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
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
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>
1948032 to
2184e98
Compare
There was a problem hiding this comment.
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 winPreserve 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 theRECORD_QUALITYoperation and store it inpayload.packages/core/src/prefactor_core/client.py#L336-L340: pass the stored key toAgentInstanceClient.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
📒 Files selected for processing (16)
README.mdpackages/core/README.mdpackages/core/src/prefactor_core/client.pypackages/core/src/prefactor_core/managers/agent_instance.pypackages/core/src/prefactor_core/models.pypackages/core/src/prefactor_core/operations.pypackages/core/src/prefactor_core/schema_registry.pypackages/core/tests/test_schema_registry.pypackages/http/README.mdpackages/http/src/prefactor_http/__init__.pypackages/http/src/prefactor_http/endpoints/agent_instance.pypackages/http/src/prefactor_http/models/__init__.pypackages/http/src/prefactor_http/models/agent_instance.pypackages/http/tests/test_endpoints.pypackages/http/tests/test_models.pypackages/langchain/README.md
- 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
Replace the single quality_schema/quality_payload model with named quality schemas and keyed payloads to match the updated API:
Schema registration:
HTTP models:
HTTP endpoints:
Core client/manager:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation
Tests