๐ Contract Testing Agent Specification¶
๐ฏ Purpose¶
The Contract Testing Agent is responsible for:
Consumer-driven contract validation, backward compatibility verification, and Pact-style contract testing across microservice boundaries โ ensuring that API producers never break their consumers, and that every contract change is verified before deployment.
In a distributed microservice architecture, each service exposes APIs consumed by other services. The Contract Testing Agent guarantees that:
- โ API contracts between producers and consumers are formally defined and verified
- ๐ Breaking changes are detected before deployment, not after
- ๐ Consumer expectations are captured as executable contract test suites
- ๐งช Every API update triggers automated compatibility validation
- ๐ Results are traceable, observable, and integrated into CI/CD quality gates
๐งฑ What Sets It Apart from Other QA Agents?¶
| Agent | Primary Role |
|---|---|
| ๐งช Test Automation Engineer | Executes tests across roles, editions, and environments |
| ๐ Test Coverage Validator | Measures static and dynamic test coverage |
| ๐ Bug Investigator | Diagnoses root causes of test failures |
| ๐ Contract Testing Agent | Validates API contracts between producers and consumers at build time |
| ๐ E2E Testing Agent | Tests complete user journeys across the full stack |
๐งญ Role in Platform¶
The Contract Testing Agent sits at the boundary between API design and service deployment, ensuring that changes to producer APIs are safe for all registered consumers.
๐ Positioning Diagram¶
flowchart LR
APIDesigner[API Designer Agent]
Backend[Backend Developer Agent]
Contract[Contract Testing Agent]
TestAuto[Test Automation Engineer Agent]
QA[QA Engineer Agent]
DevOps[DevOps Engineer Agent]
APIDesigner --> Contract
Backend --> Contract
Contract --> TestAuto
Contract --> QA
Contract --> DevOps
The Contract Testing Agent validates that producer changes are compatible with all registered consumer expectations before any deployment proceeds.
๐ง Why It Exists¶
Without this agent, the factory would suffer from:
- Silent breaking changes โ producer API updates break downstream consumers undetected
- Integration test fragility โ end-to-end tests catch contract issues too late and too expensively
- Deployment rollbacks โ incompatible services deployed together cause cascading failures
- Consumer drift โ consumers assume API shapes that no longer exist
- Untraceable compatibility โ no audit trail of which consumer depends on which contract
This agent makes API compatibility verified, enforced, and traceable by design.
๐ Triggering Events¶
The Contract Testing Agent activates in response to the following platform events:
| Event | Description |
|---|---|
api_contract_updated |
An OpenAPI spec, gRPC proto, or AsyncAPI document was modified by the API Designer Agent |
microservice_deployed |
A producer service was deployed โ triggers verification against all consumer contracts |
consumer_registration_changed |
A new consumer registered interest in a producer API, or an existing consumer updated |
pull_request_with_api_changes |
A PR includes changes to API controllers, DTOs, or route definitions |
schema_migration_detected |
Database or message schema changes that may affect API response shapes |
๐ Responsibilities and Deliverables¶
โ Core Responsibilities¶
| Responsibility | Description |
|---|---|
| Generate Consumer Contract Tests | Creates Pact-style contract tests from consumer expectations and producer OpenAPI/proto definitions |
| Validate Producer Compatibility | Verifies that producer API changes satisfy all registered consumer contracts |
| Detect Breaking Changes | Identifies removed endpoints, changed response schemas, modified status codes, or renamed fields |
| Maintain Contract Registry | Tracks all producer-consumer contract pairs with versioning and dependency graphs |
| Emit Compatibility Reports | Produces detailed reports showing which contracts pass/fail and why |
| Enforce Backward Compatibility Policies | Blocks deployments when breaking changes are detected unless explicitly overridden |
| Support Schema Evolution Strategies | Validates additive-only changes, deprecation patterns, and versioned endpoint migrations |
| Integrate with CI/CD Quality Gates | Fails pipelines when contract violations are detected, emits results to PR annotations |
| Track Contract Coverage | Measures which producer endpoints have consumer contracts and identifies coverage gaps |
Emit ContractValidationCompleted Event |
Signals downstream agents that contract verification is finished with pass/fail status |
๐ค Output Deliverables¶
| Output Type | Format | Description |
|---|---|---|
contract-test-suite |
.cs, .json, .yaml |
Generated Pact-style contract tests for each consumer-producer pair |
compatibility-report |
.md, .json |
Detailed breakdown of contract validation results per endpoint |
contract-registry.yaml |
.yaml |
Registry of all active contracts, versions, and consumer dependencies |
breaking-change-alert |
.json |
Structured alert identifying specific breaking changes detected |
execution-metadata.json |
.json |
Trace-tagged metadata of the contract validation run |
๐ Example: compatibility-report.md¶
### ๐ Contract Compatibility Report โ BookingService v2.3.1
๐ Trace: contract-2026-0329-booking
๐ท๏ธ Producer: BookingService
๐ Consumers: NotificationService, BillingService, MobileGateway
โ
Passed:
- GET /api/bookings/{id} โ all consumer expectations met
- POST /api/bookings โ response schema compatible
โ Failed:
- DELETE /api/bookings/{id} โ **endpoint removed**, consumed by NotificationService
Breaking change: consumer expects 204 No Content response
๐ Action Required: Restore endpoint or negotiate deprecation with consumer
๐ค Collaboration Patterns¶
๐ Direct Agent Collaborations¶
| Collaborating Agent | Interaction Summary |
|---|---|
| ๐จ API Designer Agent | Provides OpenAPI/AsyncAPI specs; notified when contracts are updated or new versions published |
| ๐ง Backend Developer Agent | Produces the API implementations that must satisfy contracts; receives breaking change alerts |
| โ๏ธ Test Automation Engineer Agent | Executes generated contract test suites as part of CI/CD pipelines |
| ๐ค QA Engineer Agent | Reviews contract coverage reports and approves contract-related quality gates |
| ๐ง DevOps Engineer Agent | Receives deployment-blocking signals when contract violations are detected |
| ๐ฆ Documentation Writer Agent | Consumes contract registry data to generate API compatibility documentation |
๐ฌ Events Emitted & Consumed¶
| Event Name | Role |
|---|---|
api_contract_updated |
๐ Consumed โ triggers contract test regeneration and validation |
microservice_deployed |
๐ Consumed โ triggers post-deployment contract verification |
consumer_registration_changed |
๐ Consumed โ updates contract registry and re-validates |
ContractValidationCompleted |
โ Emitted โ signals pass/fail to CI/CD, QA, and DevOps agents |
BreakingChangeDetected |
โ Emitted โ blocks deployment, notifies API Designer and consumers |
๐งญ Coordination Flow¶
sequenceDiagram
participant APIDesigner as API Designer Agent
participant Contract as Contract Testing Agent
participant TestAuto as Test Automation Engineer
participant DevOps as DevOps Engineer Agent
participant Studio as Studio Agent
APIDesigner->>Contract: api_contract_updated
Contract->>Contract: Generate contract tests
Contract->>Contract: Validate producer compatibility
Contract->>TestAuto: Execute contract test suite
Contract->>DevOps: Emit ContractValidationCompleted
Contract->>Studio: Publish compatibility report
๐ง Memory and Knowledge¶
The Contract Testing Agent maintains a persistent knowledge base to support:
- ๐ Historical contract versions and evolution tracking
- ๐ Reuse of contract patterns across similar service topologies
- ๐ Contract coverage metrics over time
- ๐ง Semantic understanding of API schemas for intelligent diff analysis
๐งฉ Memory Components¶
| Memory Store | Content |
|---|---|
| ๐ Contract Registry | All active producer-consumer contract pairs, versions, and dependency graphs |
| ๐ Contract Version History | Historical snapshots of contracts enabling diff and evolution tracking |
| ๐ง Schema Embedding Index | Vector embeddings of API schemas for similarity search and drift detection |
| ๐ Compatibility Result Cache | Past validation results indexed by producer version and consumer contract version |
| ๐ Breaking Change Pattern DB | Known patterns of breaking changes (field removal, type change, enum restriction) |
๐ Example Memory Entry¶
{
"producerId": "booking-service",
"producerVersion": "2.3.1",
"consumerId": "notification-service",
"contractVersion": "1.2.0",
"status": "Compatible",
"validatedAt": "2026-03-29T10:15:00Z",
"traceId": "contract-2026-0329-booking",
"endpointsCovered": 5,
"breakingChanges": []
}
โ Validation Mechanisms¶
๐ What Is Validated?¶
| Component | Validation Criteria |
|---|---|
| Response Schema | All fields expected by consumers must be present with correct types and nullability |
| Status Codes | Producer must return status codes that consumers handle; removed codes are flagged |
| Endpoint Availability | All endpoints consumed must still exist; removed or renamed endpoints are breaking changes |
| Request Schema | Changes to required request fields that consumers send must be backward-compatible |
| Header Contracts | Required headers (auth, content-type, custom) must remain consistent |
| Event/Message Contracts | AsyncAPI message schemas must satisfy subscriber expectations |
| Deprecation Compliance | Deprecated endpoints must have migration paths documented and sunset dates respected |
๐งช Validation Workflow¶
flowchart TD
Start[API Contract Change Detected]
LoadRegistry[Load Consumer Contracts from Registry]
GenerateTests[Generate Pact-Style Tests per Consumer]
ExecuteTests[Execute Contract Tests Against Producer]
CompareSchemas[Compare Response Schemas]
CheckEndpoints[Verify Endpoint Availability]
StatusCheck{All Contracts Satisfied?}
EmitSuccess[Emit ContractValidationCompleted โ
]
EmitFailure[Emit BreakingChangeDetected โ]
Start --> LoadRegistry --> GenerateTests --> ExecuteTests
ExecuteTests --> CompareSchemas --> CheckEndpoints --> StatusCheck
StatusCheck -->|Yes| EmitSuccess
StatusCheck -->|No| EmitFailure
๐ Example Validation Report (JSON)¶
{
"traceId": "contract-2026-0329-booking",
"producerId": "booking-service",
"producerVersion": "2.3.1",
"status": "Failed",
"consumers": [
{
"consumerId": "notification-service",
"contractVersion": "1.2.0",
"result": "Failed",
"violations": [
{
"type": "EndpointRemoved",
"endpoint": "DELETE /api/bookings/{id}",
"severity": "Critical",
"message": "Consumer expects 204 No Content; endpoint no longer exists"
}
]
},
{
"consumerId": "billing-service",
"contractVersion": "1.0.3",
"result": "Passed",
"violations": []
}
]
}
๐ Process Flow¶
flowchart TD
Start([Contract Testing Agent Activated])
LoadContracts[Load consumer contracts from registry]
FetchProducerSpec[Fetch latest producer API specification]
DiffSchemas[Diff producer spec against consumer expectations]
GenerateTests[Generate contract test cases per consumer]
ExecuteTests[Execute tests against producer mock or live instance]
AnalyzeResults[Analyze results and classify violations]
EmitReport[Generate compatibility report]
EmitEvent[Emit ContractValidationCompleted or BreakingChangeDetected]
UpdateMemory[Update contract registry and version history]
End([Finish])
Start --> LoadContracts --> FetchProducerSpec --> DiffSchemas
DiffSchemas --> GenerateTests --> ExecuteTests --> AnalyzeResults
AnalyzeResults --> EmitReport --> EmitEvent --> UpdateMemory --> End
๐ Agent Contract¶
agentId: contract-testing
role: "Consumer-Driven Contract Validator"
category: "Quality Assurance, API Compatibility, Testing"
description: >
Validates API contracts between microservice producers and consumers using
Pact-style consumer-driven contract testing. Detects breaking changes,
enforces backward compatibility, and maintains a contract registry.
triggers:
- api_contract_updated
- microservice_deployed
- consumer_registration_changed
inputs:
- OpenAPI/AsyncAPI/Proto specifications
- Consumer contract definitions
- Contract registry (producer-consumer pairs)
- Producer deployment metadata
outputs:
- contract-test-suite
- compatibility-report
- contract-registry.yaml (updated)
- breaking-change-alert
- execution-metadata.json
- Event: ContractValidationCompleted
- Event: BreakingChangeDetected
skills:
- GenerateContractTests
- ValidateProducerCompatibility
- DetectBreakingChanges
- UpdateContractRegistry
- EmitCompatibilityReport
- EnforceDeprecationPolicy
- TrackContractCoverage
memory:
scope: [traceId, producerId, consumerId, contractVersion]
stores:
- contractRegistry
- contractVersionHistory
- schemaEmbeddingIndex
- compatibilityResultCache
validations:
- All consumer contracts satisfied by producer
- No breaking changes without explicit override
- Contract registry is up-to-date
- execution-metadata.json generated
version: "1.0.0"
status: active
๐ Summary¶
The Contract Testing Agent is the API compatibility guardian of the ConnectSoft AI Software Factory. It ensures that:
- ๐ Every microservice API change is validated against all consumer contracts
- ๐ Breaking changes are detected and blocked before deployment
- ๐งช Contract tests are generated, executed, and reported automatically
- ๐ A living contract registry tracks all producer-consumer dependencies
- ๐ง Historical contract knowledge enables intelligent evolution and drift detection
Without this agent, microservice deployments become a game of chance. With it, API compatibility is guaranteed, traceable, and continuously enforced.