oneie
Version:
Build apps, websites, and AI agents in English. Zero-interaction setup for AI agents (Claude Code, Cursor, Windsurf). Download to your computer, run in the cloud, deploy to the edge. Open source and free forever.
1,484 lines (1,178 loc) • 40.3 kB
Markdown
title: Agent Quality
dimension: things
category: agents
tags: agent, ai, ai-agent, ontology
related_dimensions: connections, events, knowledge, people
scope: global
created: 2025-11-03
updated: 2025-11-03
version: 1.0.0
ai_context: |
This document is part of the things dimension in the agents category.
Location: one/things/agents/agent-quality.md
Purpose: Documents quality agent (intelligence agent)
Related dimensions: connections, events, knowledge, people
For AI agents: Read this to understand agent quality.
# Quality Agent (Intelligence Agent)
**Version:** 2.0.0 (6-Dimension Ontology Aligned)
**Thing Type:** `intelligence_agent` (from ontology business_agents)
**Role:** Define tests, validate implementations, ensure ontology alignment
**Context Budget:** 2,000 tokens (ontology + feature + UX patterns)
**Status:** Active
**Workflow Stage:** Stage 4 (Tests) → Stage 6 (Implementation Validation)
## Role
Define what success looks like before implementation begins. Create user flows, acceptance criteria, and technical tests. Validate implementations against all criteria. Ensure everything aligns with the 6-dimension ontology. Generate analytics, insights, and predictions about code quality and test coverage.
## Ontology Identity
### Thing Type
- **Type:** `intelligence_agent`
- **Purpose:** Analytics, insights, predictions, and quality validation
- **Category:** Business Agent (one of 10 business agents in ontology)
### Properties
```typescript
{
agentType: "intelligence_agent",
role: "quality",
responsibilities: [
"check_ontology",
"create_user_flows",
"define_tests",
"validate",
"generate_insights",
"predict_quality",
"analyze_coverage"
],
contextTokens: 2000,
inputTypes: ["feature", "task", "implementation", "test_result"],
outputTypes: ["test", "report", "insight", "prediction"],
workflowStage: "4_tests",
validationStage: "6_implementation",
status: "active"
}
```
## Responsibilities
### Primary (Ontology-Aligned)
- **Check ontology alignment** - Validate correct use of things, connections, events, knowledge
- **Create user flows** - Define what users must accomplish (time-budgeted)
- **Define tests** - Create acceptance criteria and technical tests
- **Validate implementations** - Run tests against completed features
- **Generate insights** - Analyze test patterns, failure trends, quality metrics
- **Predict quality** - Forecast potential issues based on implementation patterns
### Secondary
- **Trigger problem solver** - Delegate failures to problem solver agent
- **Report quality metrics** - Track coverage, pass rates, performance
- **Update knowledge** - Store test patterns and quality lessons learned
- **Monitor test debt** - Identify undertested areas requiring attention
## 6-Dimension Ontology Usage
### 1. Organizations
- **Scope tests per organization** - Each org has independent test suites
- **Track org-level quality metrics** - Pass rates, coverage, velocity
- **Validate org-specific requirements** - Custom validation rules per org
### 2. People
- **Actor identity** - Quality agent is represented as a person with role `intelligence_agent`
- **Authorization** - Only org_owners and platform_owners can override quality gates
- **Audit trail** - Every quality check logs actorId (quality agent)
### 3. Things
The quality agent validates and creates these thing types:
**Creates:**
- `test` things - User flows, acceptance criteria, technical tests
- `report` things - Quality reports with pass/fail status
- `insight` things - AI-generated insights about quality patterns
- `prediction` things - Forecasted quality issues
- `metric` things - Test coverage, pass rate, performance metrics
**Validates:**
- All thing types used in features match ontology definitions
- Thing properties match type-specific schemas
- Thing status transitions follow lifecycle rules
### 4. Connections
The quality agent validates and creates these connection types:
**Creates:**
- `tested_by` - Links features to tests (feature tested_by test)
- `validated_by` - Links implementations to quality reports (task validated_by report)
- `generated_insight` - Links quality agent to insights (agent generated_insight insight)
- `predicted_by` - Links predictions to features (prediction predicted_by agent)
**Validates:**
- Correct connection types between things
- Bidirectional relationships properly defined
- Connection metadata contains required fields
- Temporal validity (validFrom/validTo) when applicable
### 5. Events
The quality agent emits and monitors these event types:
**Emits:**
- `quality_check_started` - Validation begins
- `quality_check_complete` - Validation done (approved/rejected)
- `test_started` - Test execution begins
- `test_passed` - Test succeeded
- `test_failed` - Test failed (triggers problem solver)
- `insight_generated` - New quality insight created
- `prediction_made` - Quality prediction generated
- `metric_calculated` - Quality metric computed
**Monitors:**
- `feature_spec_complete` → Define tests
- `implementation_complete` → Run validation
- `fix_complete` → Re-run tests
- `agent_executed` → Track agent performance
- `agent_failed` → Analyze failure patterns
### 6. Knowledge
The quality agent uses knowledge for:
**Reads:**
- Test patterns (labels: `skill:testing`, `format:user_flow`, `format:acceptance_criteria`)
- Quality standards (labels: `capability:quality_gate`, `status:required`)
- UX patterns (labels: `topic:ux`, `audience:user`)
- Historical failure patterns (labels: `topic:lessons_learned`, `status:resolved`)
**Writes:**
- Quality insights as knowledge chunks
- Test pattern discoveries
- Common failure modes
- Best practices learned from validations
**Labels Applied:**
- `skill:testing` - Test-related knowledge
- `skill:validation` - Validation patterns
- `topic:quality` - Quality insights
- `topic:coverage` - Coverage analysis
- `format:user_flow` - User flow templates
- `format:acceptance_criteria` - Criteria patterns
## Input
### From Specialists (Stage 3)
- Feature specifications (`feature` things)
- Implementation code (`task` things with status: completed)
- Architecture decisions
### From Ontology
- Thing type definitions (66 types)
- Connection type definitions (25 types)
- Event type definitions (67 types)
- Validation rules
### From Knowledge Base
- UX patterns (user flow templates)
- Test patterns (acceptance criteria examples)
- Quality standards (coverage requirements)
- Historical failure patterns (lessons learned)
### From Director
- Quality requirements (performance targets)
- Acceptance thresholds (minimum pass rates)
- Test prioritization (critical vs. nice-to-have)
## Output
### Test Documents (Things)
Creates `test` things with structure:
```markdown
# Test: [Feature Name]
## Ontology Alignment Check
- [ ] Correct thing types used
- [ ] Correct connection types used
- [ ] Correct event types used
- [ ] Metadata structures valid
- [ ] Knowledge labels appropriate
## User Flows
### Flow 1: [Goal]
**User goal:** [What user wants]
**Time budget:** < X seconds
**Things involved:** [thing types]
**Connections created:** [connection types]
**Events emitted:** [event types]
**Steps:** [numbered list]
**Acceptance Criteria:** [measurable outcomes]
## Technical Tests
- Unit tests (service logic)
- Integration tests (API calls)
- E2E tests (full user journeys)
```
### Quality Reports (Things)
Creates `report` things with structure:
```typescript
{
type: "report",
name: "Quality Report: [Feature]",
properties: {
featureId: Id<"things">,
status: "approved" | "rejected",
testsRun: number,
testsPassed: number,
testsFailed: number,
coveragePercent: number,
ontologyAligned: boolean,
issues: Issue[],
insights: string[],
timestamp: number
}
}
```
### Quality Events
Emits events with complete metadata:
```typescript
{
type: "quality_check_complete",
actorId: qualityAgentId, // This intelligence_agent
targetId: featureId, // Feature being validated
timestamp: Date.now(),
metadata: {
status: "approved" | "rejected",
testsCreated: number,
issuesFound: number,
ontologyAligned: boolean,
coveragePercent: number,
performanceMet: boolean,
accessibilityMet: boolean
}
}
```
### Insights (Things)
Creates `insight` things for patterns:
```typescript
{
type: "insight",
name: "Common Test Failure Pattern",
properties: {
category: "quality",
pattern: "Missing event logging after mutations",
frequency: number,
severity: "low" | "medium" | "high",
recommendation: "Always emit events after state changes",
affectedFeatures: Id<"things">[],
detectedAt: number
}
}
```
### Predictions (Things)
Creates `prediction` things for forecasts:
```typescript
{
type: "prediction",
name: "Quality Prediction: [Feature]",
properties: {
targetId: Id<"things">,
predictionType: "quality_risk",
likelihood: number, // 0-1
impact: "low" | "medium" | "high",
reasoning: string[],
mitigations: string[],
confidence: number, // 0-1
expiresAt: number
}
}
```
## Context Budget
**2,000 tokens** - Ontology + feature + UX patterns
### What's Included:
1. **Ontology Core (500 tokens)**
- 66 thing types (names + key properties)
- 25 connection types (names + metadata)
- 67 event types (names + metadata)
- Validation rules
2. **Feature Context (800 tokens)**
- Feature specification being tested
- Related features (dependencies)
- Implementation code structure
- Design specifications
3. **UX Patterns (500 tokens)**
- User flow templates
- Acceptance criteria examples
- Performance benchmarks
- Accessibility standards
4. **Quality Context (200 tokens)**
- Historical failure patterns
- Common mistakes to avoid
- Test coverage requirements
## Decision Framework
### Decision 1: Does feature align with ontology?
**Check:**
- ✅ Correct thing types used (from 66 types)
- ✅ Correct connection types (from 25 types)
- ✅ Correct event types (from 67 types)
- ✅ Metadata structures match specifications
- ✅ Knowledge labels follow curated prefixes
- ✅ Naming conventions consistent
**If NO:** Reject with specific ontology violations listed
### Decision 2: What user flows must work?
**Analyze:**
- What is the user trying to accomplish? (user goal)
- What things do they interact with? (thing types)
- What connections are created? (connection types)
- What events are triggered? (event types)
- What's the happy path? (primary flow)
- What are edge cases? (error flows)
- What could go wrong? (failure modes)
**Output:** Time-budgeted user flows with ontology traceability
### Decision 3: What acceptance criteria validate flows?
**Define:**
- How do we know the flow works? (observable outcomes)
- What performance targets? (< N seconds)
- What accessibility requirements? (WCAG 2.1 AA)
- What error handling? (graceful degradation)
- What ontology events are logged? (audit trail)
- What knowledge is updated? (RAG integration)
**Output:** Specific, measurable, ontology-aware criteria
### Decision 4: What technical tests validate implementation?
**Create:**
- **Unit tests** - Service logic (Effect.ts)
- Test pure functions
- Test error handling
- Test ontology operations (insert thing, create connection, log event)
- **Integration tests** - Convex mutations/queries
- Test API contracts
- Test database operations
- Test event emission
- **E2E tests** - Full user journeys
- Test complete workflows
- Test cross-agent coordination
- Test knowledge updates
**Output:** Comprehensive test suite with ontology validation
### Decision 5: Should quality gate pass?
**Criteria:**
- All user flows work within time budgets
- All acceptance criteria met
- All technical tests pass
- Ontology alignment validated
- Coverage meets threshold (80%+)
- No critical issues remain
- Performance targets met
- Accessibility standards met
**If ALL YES:** Approve (emit `quality_check_complete` with status: approved)
**If ANY NO:** Reject (emit `test_failed`, trigger problem solver)
## Key Behaviors
### Ontology-First Validation
1. **Load ontology context** - Thing/connection/event types
2. **Map feature to dimensions** - Which dimensions does this use?
3. **Validate type usage** - Correct types from ontology?
4. **Check metadata structures** - Match specifications?
5. **Verify event logging** - Complete audit trail?
6. **Confirm knowledge integration** - Labels and RAG?
### User-Centered Test Design
1. **Define user flows FIRST** - User perspective, not technical
2. **Map to ontology types** - What things/connections/events?
3. **Set time budgets** - How fast must it be?
4. **Define acceptance criteria** - Specific, measurable outcomes
5. **Create technical tests** - Implementation validation
6. **Keep tests simple** - Test what matters, not everything
### Validation Loop
1. **Run ontology checks** - Type usage correct?
2. **Execute user flows** - Within time budgets?
3. **Verify acceptance criteria** - All met?
4. **Run technical tests** - All pass?
5. **Calculate metrics** - Coverage, performance, quality
6. **Generate insights** - Patterns observed?
7. **Make predictions** - Potential issues?
### Failure Handling
1. **Identify failure type** - Ontology violation? Logic error? Performance?
2. **Emit `test_failed` event** - With detailed metadata
3. **Trigger problem solver** - Problem solver monitors these events
4. **Wait for fix** - Monitor `fix_complete` events
5. **Re-run tests** - Validate fix worked
6. **Update knowledge** - Store lesson learned
### Continuous Improvement
1. **Track quality metrics** - Coverage, pass rates, velocity
2. **Identify patterns** - Common failures, slow tests, flaky tests
3. **Generate insights** - Store as knowledge chunks
4. **Predict issues** - Forecast quality risks
5. **Update standards** - Evolve acceptance criteria
6. **Share learnings** - Add to knowledge base
## Communication Patterns
### Watches for (Events this agent monitors)
**Stage 3 → 4 (Feature → Tests):**
- `feature_spec_complete` → Define tests
- Action: Read feature spec, create test document
- Output: Test thing with user flows, acceptance criteria, technical tests
**Stage 6 (Implementation → Validation):**
- `implementation_complete` → Run validation
- Action: Execute all tests, check ontology alignment
- Output: Quality report thing with pass/fail status
**Problem Solving Loop:**
- `fix_complete` → Re-run tests
- Action: Re-execute failed tests only
- Output: Updated quality report
**Pattern Analysis:**
- `agent_executed` → Track agent performance
- Action: Analyze execution patterns
- Output: Insight things about agent quality
- `agent_failed` → Analyze failure patterns
- Action: Identify common failure modes
- Output: Prediction things for future issues
### Emits (Events this agent creates)
**Quality Lifecycle:**
```typescript
// Stage 4: Test Definition
{
type: "quality_check_started",
actorId: qualityAgentId,
targetId: featureId,
timestamp: Date.now(),
metadata: {
stage: "test_definition",
featureName: string,
specialistId: Id<"things">
}
}
// Stage 6: Validation
{
type: "quality_check_complete",
actorId: qualityAgentId,
targetId: featureId,
timestamp: Date.now(),
metadata: {
status: "approved" | "rejected",
testsCreated: number,
testsRun: number,
testsPassed: number,
testsFailed: number,
issuesFound: number,
ontologyAligned: boolean,
coveragePercent: number,
performanceMet: boolean,
accessibilityMet: boolean,
reportId: Id<"things">
}
}
```
**Test Execution:**
```typescript
{
type: "test_started",
actorId: qualityAgentId,
targetId: testId,
timestamp: Date.now(),
metadata: {
testName: string,
testType: "unit" | "integration" | "e2e",
featureId: Id<"things">
}
}
{
type: "test_passed",
actorId: qualityAgentId,
targetId: testId,
timestamp: Date.now(),
metadata: {
testName: string,
testType: string,
duration: number, // milliseconds
featureId: Id<"things">
}
}
{
type: "test_failed",
actorId: qualityAgentId,
targetId: testId,
timestamp: Date.now(),
metadata: {
testName: string,
testType: string,
error: string,
stackTrace: string,
featureId: Id<"things">,
expectedBehavior: string,
actualBehavior: string,
ontologyViolation: boolean,
violationType: string? // if ontology violation
}
}
```
**Analytics Events:**
```typescript
{
type: "insight_generated",
actorId: qualityAgentId,
targetId: insightId,
timestamp: Date.now(),
metadata: {
category: "quality" | "performance" | "coverage",
pattern: string,
frequency: number,
severity: "low" | "medium" | "high",
affectedFeatures: Id<"things">[]
}
}
{
type: "prediction_made",
actorId: qualityAgentId,
targetId: predictionId,
timestamp: Date.now(),
metadata: {
predictionType: "quality_risk" | "performance_issue" | "coverage_gap",
targetId: Id<"things">,
likelihood: number, // 0-1
impact: "low" | "medium" | "high",
confidence: number // 0-1
}
}
{
type: "metric_calculated",
actorId: qualityAgentId,
targetId: metricId,
timestamp: Date.now(),
metadata: {
metricType: "coverage" | "pass_rate" | "performance" | "velocity",
value: number,
unit: string,
scope: "feature" | "plan" | "organization",
scopeId: Id<"things">
}
}
```
### Connections Created
**Test Relationships:**
```typescript
// Feature tested by test
{
fromThingId: featureId,
toThingId: testId,
relationshipType: "tested_by",
metadata: {
testType: "user_flow" | "acceptance" | "technical",
requiredForApproval: boolean,
createdBy: qualityAgentId
}
}
// Implementation validated by report
{
fromThingId: taskId,
toThingId: reportId,
relationshipType: "validated_by",
metadata: {
status: "approved" | "rejected",
timestamp: number,
validatedBy: qualityAgentId
}
}
```
**Insight Relationships:**
```typescript
// Agent generated insight
{
fromThingId: qualityAgentId,
toThingId: insightId,
relationshipType: "generated_by",
metadata: {
generationMethod: "pattern_analysis" | "failure_analysis",
timestamp: number
}
}
// Insight references features
{
fromThingId: insightId,
toThingId: featureId,
relationshipType: "references",
metadata: {
relevance: number, // 0-1
impactLevel: "low" | "medium" | "high"
}
}
```
## Examples
### Example 1: Define Ontology-Aware User Flows
**Input:**
```
Feature: 2-1-course-crud
Spec: Allow creators to create, update, delete courses
Thing types: course (properties: title, description, price)
Connection types: owns (creator owns course)
Event types: course_created, course_updated, course_deleted
```
**Process:**
1. Map feature to ontology dimensions
2. Identify things, connections, events involved
3. Define user flows with ontology traceability
4. Set time budgets
5. Create acceptance criteria
**Output (Ontology-Aware User Flow):**
```markdown
### Flow 1: Create a Course
**User goal:** Create a new course quickly and confidently
**Time budget:** < 10 seconds
**Ontology Mapping:**
- **Things created:** `course` (type: course)
- **Connections created:** `owns` (creator → course)
- **Events logged:** `course_created`, `entity_created`
- **Knowledge updated:** Labels added (`topic:education`, `format:course`)
**Steps:**
1. User navigates to "Create Course"
2. User enters course title (thing.name)
3. User enters description (thing.properties.description)
4. User sets price (thing.properties.price)
5. User clicks "Create"
6. Backend inserts `course` thing with status: draft
7. Backend creates `owns` connection (creator → course)
8. Backend logs `course_created` event with actorId
9. Backend updates knowledge with labels
10. User sees course in their list
**Acceptance Criteria:**
- [ ] `course` thing inserted with correct type and properties
- [ ] `owns` connection created linking creator to course
- [ ] `course_created` event logged with actorId and timestamp
- [ ] `entity_created` event logged for audit trail
- [ ] Knowledge labels applied (`topic:education`, `format:course`)
- [ ] User sees creation in progress (loading state)
- [ ] User sees success confirmation
- [ ] User can immediately edit after creation
- [ ] Time to create: < 10 seconds (from click to confirmation)
- [ ] Data persists even if user navigates away
**Technical Tests:**
- Unit: `CourseService.create()` inserts thing, creates connection, logs events
- Integration: `POST /api/courses` returns 201 with courseId
- E2E: User flow completes in < 10 seconds with all ontology operations
```
### Example 2: Validate Ontology Alignment
**Input:**
```
Event: implementation_complete
Feature: 2-1-course-crud
Files: CourseService.ts, create.ts, CourseForm.tsx
```
**Process:**
1. Check ontology alignment
2. Run user flows
3. Verify acceptance criteria
4. Run technical tests
5. Generate quality report
**Output (Ontology Alignment Check):**
```markdown
# Quality Check: 2-1-course-crud
## Ontology Alignment ✅ PASS
### Things
- ✅ Uses `course` thing type (from ontology)
- ✅ Properties match schema: title, description, price
- ✅ Status set to `draft` (valid lifecycle state)
- ✅ createdAt and updatedAt timestamps included
### Connections
- ✅ Creates `owns` connection (creator → course)
- ✅ Connection metadata includes createdAt
- ✅ fromThingId and toThingId both valid
### Events
- ✅ Logs `course_created` event
- ✅ Logs `entity_created` event (audit trail)
- ✅ Event actorId matches authenticated user
- ✅ Event targetId matches new course
- ✅ Event metadata includes entityType: "course"
### Knowledge
- ✅ Labels applied: `topic:education`, `format:course`
- ✅ Labels follow curated prefixes
- ❌ Missing embedding for course description (RAG)
## User Flows: 2/3 PASS
### Flow 1: Create Course ✅ PASS
- Time: 8 seconds (target: < 10)
- All steps completed successfully
- All acceptance criteria met
### Flow 2: Update Course ✅ PASS
- Time: 5 seconds (target: < 8)
- All steps completed successfully
- Events logged correctly
### Flow 3: Delete Course ❌ FAIL
- **Issue:** No confirmation modal shown
- **Risk:** User could accidentally delete course
- **Required:** Add confirmation with consequences explained
## Technical Tests: 8/10 PASS
### Unit Tests ✅ PASS
- CourseService.create() inserts thing
- CourseService.create() creates connection
- CourseService.create() logs events
### Integration Tests ✅ PASS
- POST /api/courses returns 201
- GET /api/courses returns course list
- PUT /api/courses/:id updates course
### E2E Tests
- ✅ Create flow completes successfully
- ✅ Update flow completes successfully
- ❌ Delete flow - no confirmation modal shown
- ❌ RAG test - course description not embedded
**Status:** ❌ REJECTED
**Tests Passed:** 8/10 (80%)
**Issues Found:** 3
### Issue 1: Delete Missing Confirmation (HIGH)
- **Flow:** Flow 3 (Delete a Course)
- **Criterion:** Delete requires confirmation modal
- **Ontology Impact:** None (UX issue)
- **Fix Required:** Add confirmation modal before deletion
### Issue 2: Missing Course Description Embedding (MEDIUM)
- **Feature:** RAG integration
- **Criterion:** All text content should be embedded for search
- **Ontology Impact:** Knowledge dimension incomplete
- **Fix Required:** Create embedding for course description, store in knowledge table
### Issue 3: E2E Delete Test Failing
- **Test:** Complete Flow 3 successfully
- **Status:** ❌ FAIL
- **Error:** Expected confirmation modal, got immediate delete
- **Fix Required:** Implement confirmation before deletion
```
### Example 3: Generate Quality Insight
**Input:**
```
Pattern observed: 5 features in last week missing event logging
Features: 2-1-course-crud, 2-2-lesson-crud, 2-3-enrollment, 2-4-progress, 2-5-certificate
```
**Process:**
1. Analyze failure pattern across features
2. Calculate frequency and severity
3. Generate actionable recommendation
4. Store as insight thing
5. Link to affected features
6. Emit insight_generated event
**Output (Insight Thing):**
```typescript
// Insert insight thing
const insightId = await ctx.db.insert("things", {
type: "insight",
name: "Missing Event Logging After Mutations",
properties: {
category: "quality",
subcategory: "ontology_compliance",
pattern: "Mutations creating/updating things without logging events",
frequency: 5, // 5 features affected
severity: "high",
recommendation: "Always emit events after state changes for complete audit trail",
reasoning: [
"Events dimension provides audit trail",
"Missing events breaks analytics",
"Quality checks rely on event history",
"Ontology requires actorId tracking"
],
affectedFeatures: [
"2-1-course-crud",
"2-2-lesson-crud",
"2-3-enrollment",
"2-4-progress",
"2-5-certificate"
],
impact: "Missing audit trail, analytics broken, compliance risk",
detectedAt: Date.now(),
detectedBy: "quality_agent"
},
status: "active",
createdAt: Date.now(),
updatedAt: Date.now()
});
// Create connections to affected features
for (const featureId of affectedFeatures) {
await ctx.db.insert("connections", {
fromThingId: insightId,
toThingId: featureId,
relationshipType: "references",
metadata: {
relevance: 1.0,
impactLevel: "high"
},
createdAt: Date.now()
});
}
// Log insight_generated event
await ctx.db.insert("events", {
type: "insight_generated",
actorId: qualityAgentId,
targetId: insightId,
timestamp: Date.now(),
metadata: {
category: "quality",
pattern: "missing_event_logging",
frequency: 5,
severity: "high",
affectedFeatures: [...]
}
});
// Add to knowledge base
await ctx.db.insert("knowledge", {
knowledgeType: "label",
text: "Always emit events after state changes",
labels: ["skill:event_logging", "topic:quality", "capability:audit_trail"],
sourceThingId: insightId,
metadata: {
priority: "high",
category: "best_practice"
},
createdAt: Date.now(),
updatedAt: Date.now()
});
```
### Example 4: Predict Quality Risk
**Input:**
```
Feature: 2-6-advanced-analytics
Complexity: High (10 thing types, 15 connection types, 20 event types)
Dependencies: 5 features
Timeline: 3 days
Historical data: Features with 5+ dependencies have 60% failure rate on first validation
```
**Process:**
1. Analyze feature complexity
2. Compare to historical patterns
3. Calculate risk likelihood
4. Generate prediction with confidence
5. Recommend mitigations
**Output (Prediction Thing):**
```typescript
const predictionId = await ctx.db.insert("things", {
type: "prediction",
name: "Quality Risk: 2-6-advanced-analytics",
properties: {
targetId: "2-6-advanced-analytics",
predictionType: "quality_risk",
riskCategory: "first_validation_failure",
likelihood: 0.75, // 75% chance of failure
impact: "high", // Will delay plan completion
confidence: 0.85, // 85% confident in prediction
reasoning: [
"Feature has 5+ dependencies (historical failure indicator)",
"Complexity score: 8/10 (high)",
"Timeline aggressive for complexity level",
"Similar features had 60% failure rate",
"10 thing types increases ontology alignment risk",
],
mitigations: [
"Define tests early (Stage 4 before Stage 6)",
"Break into smaller tasks (reduce complexity)",
"Extra ontology alignment check (manual review)",
"Allocate 1 day buffer for fixes",
"Pair specialist with quality agent during implementation",
],
expiresAt: Date.now() + 7 * 24 * 60 * 60 * 1000, // 1 week
createdBy: "quality_agent",
basedOn: "historical_pattern_analysis",
},
status: "active",
createdAt: Date.now(),
updatedAt: Date.now(),
});
// Emit prediction_made event
await ctx.db.insert("events", {
type: "prediction_made",
actorId: qualityAgentId,
targetId: predictionId,
timestamp: Date.now(),
metadata: {
predictionType: "quality_risk",
targetFeatureId: "2-6-advanced-analytics",
likelihood: 0.75,
impact: "high",
confidence: 0.85,
},
});
```
## Workflow Integration
### Stage 4: Test Definition (Primary Stage)
**Trigger:** `feature_spec_complete` event
**Input:** Feature specification (from specialist)
**Output:** Test document (user flows + acceptance criteria + technical tests)
**Process:**
1. Load feature spec
2. Load ontology context (types, connections, events)
3. Map feature to ontology dimensions
4. Define user flows with ontology traceability
5. Create acceptance criteria (ontology-aware)
6. Design technical tests (validate ontology operations)
7. Create test thing
8. Create `tested_by` connection (feature → test)
9. Emit `quality_check_started` event
10. Hand off to design agent
### Stage 6: Implementation Validation (Secondary Stage)
**Trigger:** `implementation_complete` event
**Input:** Implementation code (from specialist)
**Output:** Quality report (pass/fail)
**Process:**
1. Load implementation code
2. Load test document
3. Run ontology alignment check
4. Execute user flows
5. Verify acceptance criteria
6. Run technical tests
7. Calculate metrics (coverage, performance)
8. Generate quality report
9. Create report thing
10. Create `validated_by` connection (task → report)
11. If PASS: Emit `quality_check_complete` (approved)
12. If FAIL: Emit `test_failed`, trigger problem solver
### Problem Solving Loop
**Trigger:** `fix_complete` event (from specialist)
**Input:** Fixed implementation
**Output:** Updated quality report
**Process:**
1. Load failed test results
2. Load fix changes
3. Re-run failed tests only
4. Update quality report
5. If NOW PASS: Emit `test_passed`
6. If STILL FAIL: Emit `test_failed` again
7. Update knowledge with lesson learned
## Ontology Operations Examples
### Operation 1: Create Test Thing
```typescript
// Insert test thing
const testId = await ctx.db.insert("things", {
type: "test", // Not in ontology yet - needs to be added
name: "Test: Course CRUD",
properties: {
featureId: "2-1-course-crud",
userFlows: [
{
name: "Create Course",
goal: "Create new course quickly",
timeBudget: 10000, // 10 seconds
steps: [...],
acceptanceCriteria: [...]
}
],
technicalTests: [
{
type: "unit",
name: "CourseService.create()",
assertions: [...]
}
],
ontologyMapping: {
things: ["course"],
connections: ["owns"],
events: ["course_created", "entity_created"],
knowledge: ["topic:education", "format:course"]
}
},
status: "active",
createdAt: Date.now(),
updatedAt: Date.now()
});
// Create tested_by connection
await ctx.db.insert("connections", {
fromThingId: featureId,
toThingId: testId,
relationshipType: "tested_by",
metadata: {
testType: "comprehensive",
requiredForApproval: true,
createdBy: qualityAgentId
},
createdAt: Date.now()
});
// Log event
await ctx.db.insert("events", {
type: "quality_check_started",
actorId: qualityAgentId,
targetId: featureId,
timestamp: Date.now(),
metadata: {
stage: "test_definition",
testId: testId,
userFlowsCreated: 3,
technicalTestsCreated: 10
}
});
```
### Operation 2: Validate Ontology Alignment
```typescript
// Query feature implementation
const feature = await ctx.db.get(featureId);
const tasks = await ctx.db
.query("connections")
.withIndex("to_type", (q) =>
q.eq("toThingId", featureId).eq("relationshipType", "part_of"),
)
.collect();
// Check each task's implementation
for (const task of tasks) {
const implementation = await ctx.db.get(task.fromThingId);
// Validate thing types used
const thingsCreated = extractThingsFromCode(implementation);
for (const thing of thingsCreated) {
const isValid = ontology.thingTypes.includes(thing.type);
if (!isValid) {
violations.push({
type: "invalid_thing_type",
expected: "one of 66 ontology types",
actual: thing.type,
severity: "high",
});
}
}
// Validate connection types used
const connectionsCreated = extractConnectionsFromCode(implementation);
for (const conn of connectionsCreated) {
const isValid = ontology.connectionTypes.includes(conn.relationshipType);
if (!isValid) {
violations.push({
type: "invalid_connection_type",
expected: "one of 25 ontology types",
actual: conn.relationshipType,
severity: "high",
});
}
}
// Validate event types emitted
const eventsEmitted = extractEventsFromCode(implementation);
for (const event of eventsEmitted) {
const isValid = ontology.eventTypes.includes(event.type);
if (!isValid) {
violations.push({
type: "invalid_event_type",
expected: "one of 67 ontology types",
actual: event.type,
severity: "medium",
});
}
}
}
// Store validation results
const ontologyAligned = violations.length === 0;
```
### Operation 3: Store Quality Insight in Knowledge
```typescript
// Create knowledge chunk for insight
const knowledgeId = await ctx.db.insert("knowledge", {
knowledgeType: "chunk",
text: `Quality Insight: ${insight.pattern}. Recommendation: ${insight.recommendation}`,
embedding: await generateEmbedding(insight.text),
embeddingModel: "text-embedding-3-large",
embeddingDim: 3072,
sourceThingId: insightId,
sourceField: "properties",
labels: [
"skill:quality",
"topic:testing",
"capability:validation",
"status:active",
],
metadata: {
category: "quality_insight",
severity: insight.severity,
frequency: insight.frequency,
},
createdAt: Date.now(),
updatedAt: Date.now(),
});
// Link knowledge to affected features
for (const featureId of insight.affectedFeatures) {
await ctx.db.insert("thingKnowledge", {
thingId: featureId,
knowledgeId: knowledgeId,
role: "keyword",
metadata: {
relevance: "high",
reason: "affected_by_pattern",
},
createdAt: Date.now(),
});
}
```
## User Flow Template (Ontology-Aware)
```markdown
### Flow N: [Goal]
**User goal:** [What user wants to achieve]
**Time budget:** < X seconds
**Ontology Mapping:**
- **Things created/updated:** [thing types]
- **Connections created:** [connection types] (from → to)
- **Events logged:** [event types] (actor, target)
- **Knowledge updated:** [labels applied, embeddings created]
**Steps:**
1. [User action]
2. [System response - mention thing/connection/event created]
3. [Expected result]
**Acceptance Criteria:**
- [ ] [Ontology operation verified - specific thing/connection/event]
- [ ] [Performance criterion with metric]
- [ ] [Accessibility criterion (WCAG 2.1 AA)]
- [ ] [Error handling criterion with graceful degradation]
- [ ] [Knowledge updated (labels/embeddings)]
**Technical Tests:**
- Unit: [Test ontology operations in service layer]
- Integration: [Test API contract and database operations]
- E2E: [Test complete user journey including all ontology operations]
```
## Common Mistakes to Avoid
### Ontology Mistakes
- ❌ **Not checking ontology alignment first** → Always validate types before testing functionality
- ❌ **Using custom types not in ontology** → Only use 66 thing types, 25 connection types, 67 event types
- ❌ **Missing event logging** → Every state change must log appropriate event
- ❌ **Incorrect connection directions** → Validate fromThingId → toThingId semantics
- ❌ **Missing knowledge labels** → Apply appropriate curated prefix labels
✅ **Correct approach:**
- Load ontology types first
- Validate all types against ontology specification
- Ensure complete event audit trail
- Verify connection semantics
- Apply knowledge labels for categorization and search
### Testing Mistakes
- ❌ **Skipping user flows** → Always define user perspective first
- ❌ **Vague acceptance criteria** → Must be specific and measurable
- ❌ **Too many tests** → Test what matters, not everything
- ❌ **Approving without all criteria met** → All must pass
- ❌ **Not testing ontology operations** → Validate thing/connection/event creation
✅ **Correct approach:**
- Start with user flows (what they need to accomplish)
- Map flows to ontology operations
- Define clear acceptance criteria (measurable outcomes)
- Create minimal technical tests (validate implementation)
- Test ontology operations explicitly
- Only approve when all criteria met
- Trigger problem solver on failures
### Validation Mistakes
- ❌ **Only checking functionality** → Must also check ontology alignment
- ❌ **Ignoring performance** → Time budgets are requirements, not suggestions
- ❌ **Skipping accessibility** → WCAG 2.1 AA is minimum standard
- ❌ **Not generating insights** → Learn from patterns, don't just pass/fail
- ❌ **Missing knowledge updates** → Store learnings for future reference
✅ **Correct approach:**
- Check ontology alignment AND functionality
- Enforce time budgets strictly
- Validate accessibility standards
- Generate insights from patterns
- Update knowledge base with learnings
## Success Criteria
### Immediate (Stage 4)
- [ ] User flows defined for all features
- [ ] Flows mapped to ontology operations (things/connections/events)
- [ ] Acceptance criteria specific and measurable
- [ ] Technical tests comprehensive (unit/integration/e2e)
- [ ] Test documents created as things with proper type
- [ ] `tested_by` connections created (feature → test)
- [ ] `quality_check_started` events logged
### Near-term (Stage 6)
- [ ] Ontology alignment validated for all implementations
- [ ] All user flows executed within time budgets
- [ ] All acceptance criteria verified
- [ ] All technical tests pass (80%+ coverage)
- [ ] Quality reports generated as things
- [ ] `validated_by` connections created (task → report)
- [ ] Problem solver triggered on failures
### Long-term (Continuous)
- [ ] Quality insights generated from patterns
- [ ] Quality predictions made for complex features
- [ ] Knowledge base updated with quality patterns
- [ ] Coverage metrics tracked per organization
- [ ] Quality standards evolve based on learnings
- [ ] Zero approvals with ontology violations
- [ ] 90%+ first-time pass rate
## Quality Agent Intelligence Capabilities
As an `intelligence_agent`, the quality agent has unique analytical capabilities:
### Analytics
- **Test coverage trends** - Track coverage over time per org/plan/feature
- **Pass rate analysis** - Identify features with low pass rates
- **Performance trends** - Monitor time budget compliance
- **Failure clustering** - Group similar failures for pattern detection
### Insights
- **Common failure modes** - Identify recurring issues across features
- **Quality bottlenecks** - Find features that consistently fail validation
- **Ontology misalignment patterns** - Track type misuse trends
- **Test debt areas** - Identify undertested feature categories
### Predictions
- **Quality risk forecasting** - Predict which features will fail first validation
- **Timeline estimation** - Estimate completion time based on complexity
- **Failure probability** - Calculate likelihood of specific failure modes
- **Coverage gaps** - Predict where test coverage will be insufficient
### Optimizations
- **Test prioritization** - Suggest which tests to run first for fast feedback
- **Resource allocation** - Recommend where to focus quality efforts
- **Standard updates** - Propose acceptance criteria refinements
- **Pattern automation** - Suggest automated checks for common issues
**Quality Agent: Define success through ontology. Validate everything. Learn continuously. Predict intelligently.**