Expand description
intelligent_behavior lives in mockforge_intelligence::intelligent_behavior
(Issue #562 phase 2). Re-exported here so existing
crate::intelligent_behavior::* call sites inside core (voice, reality,
graph, ai_contract_diff, ai_studio, contract_drift, failure_analysis) and
external mockforge_core::intelligent_behavior::* consumers keep
compiling without churn. Data types had already been promoted to
mockforge-foundation (A12/A17); this PR moved the LLM-bound engines too.
Intelligent Mock Behavior System
This module provides LLM-powered stateful mock behavior that maintains consistency across multiple API requests, simulating a real, thinking backend.
§Features
- Stateful Context Management: Tracks state across requests using sessions
- LLM-Powered Decision Making: Uses AI to generate intelligent, context-aware responses
- Vector Memory: Semantic search over past interactions for long-term memory
- Consistency Rules: Enforces logical behavior patterns (e.g., auth requirements)
- State Machines: Resources follow realistic lifecycle transitions
§Architecture
Request → Context Manager → Behavior Model → LLM + Vector Store → Response
↓ ↓ ↓
Session State Consistency Rules Past Interactions§Example Usage
ⓘ
use mockforge_intelligence::intelligent_behavior::{
StatefulAiContext, BehaviorModel, IntelligentBehaviorConfig,
};
// Create a stateful context
let config = IntelligentBehaviorConfig::default();
let mut context = StatefulAiContext::new("session_123", config);
// Record an interaction
context.record_interaction(
"POST",
"/api/users",
Some(serde_json::json!({"name": "Alice"})),
Some(serde_json::json!({"id": "user_1", "name": "Alice"})),
).await?;
// Get current state
let state = context.get_state();Modules§
- behavior
- Behavior model for LLM-powered decision making
- cache
- Response caching for intelligent behavior
- condition_
evaluator - Re-exported from mockforge_foundation::state_machine (Phase 6 / A4).
- config
- Configuration for the Intelligent Mock Behavior system
- context
- Stateful AI context management
- embedding_
client - Embedding client for vector memory
- history
- Re-exported from mockforge_foundation::state_machine (Phase 6 / A4).
- llm_
client - LLM client wrapper for intelligent behavior
- memory
- Vector memory store for long-term semantic memory
- mockai
- Unified MockAI interface
- mutation_
analyzer - Request mutation detection and context analysis
- openapi_
generator - OpenAPI specification generator from recorded traffic
- pagination_
intelligence - Context-aware pagination intelligence
- relationship_
inference - Relationship Inference for Smart Personas
- rule_
generator - Rule auto-generation engine for MockAI
- rules
- Re-exported from mockforge_foundation::state_machine (Phase 6 / A3).
- session
- Re-exported from mockforge_foundation::intelligent_behavior::session (Phase 6 / A7).
- spec_
suggestion - AI-powered specification suggestion and generation
- sub_
scenario - Re-exported from mockforge_foundation::state_machine (Phase 6 / A3).
- types
- Core types for the Intelligent Mock Behavior system
- validation_
generator - AI-driven validation error generation
- visual_
layout - Re-exported from mockforge_foundation::state_machine (Phase 6 / A3).
Structs§
- Behavior
Model - Behavior model that uses LLMs to generate intelligent responses
- Behavior
Rules - Behavior rules that define how the mock API should behave
- Condition
Evaluator - Condition evaluator for state machine transitions
- Confidence
Score - Confidence score for an inferred OpenAPI element
- Consistency
Rule - Consistency rule that enforces logical behavior patterns
- Crud
Example - CRUD example for state machine generation
- Endpoint
Suggestion - Individual endpoint suggestion
- Error
Example - Error example for learning validation rules
- Example
Pair - Example request/response pair for learning
- Field
Change - Change detected in a field
- Field
Error - Field-level error
- History
Manager - History manager for state machine edits
- Http
Exchange - Captured HTTP request/response exchange used for behavioral analysis.
- Intelligent
Behavior Config - Configuration for the Intelligent Mock Behavior system
- Interaction
Record - A single interaction record (request + response pair)
- LlmUsage
- LLM usage information
- MockAI
- MockAI unified interface
- Mutation
Analysis - Analysis of changes between requests
- Mutation
Analyzer - Mutation analyzer
- Open
ApiGeneration Config - Configuration for OpenAPI spec generation
- Open
ApiGeneration Metadata - Metadata about the generated OpenAPI spec
- Open
ApiGeneration Result - Result of OpenAPI spec generation
- Open
ApiSpec Generator - OpenAPI specification generator from recorded traffic
- Paginated
Response - Paginated response example
- Pagination
Intelligence - Pagination intelligence engine
- Pagination
Metadata - Pagination metadata for response
- Pagination
Request - Pagination request parameters
- Pagination
Rule - Pagination rule learned from examples
- Parameter
Info - Parameter information
- Pattern
Match - Pattern match information
- Persona
- A persona defines consistent data patterns across endpoints
- Personas
Config - Personas configuration for consistent data generation
- Relationship
- Represents a relationship between two entities
- Relationship
Inference - Relationship inference engine
- Request
- HTTP request for MockAI processing.
- Request
Context - Request context for error generation
- Response
- HTTP response from MockAI.
- Rule
Explanation - Rule explanation metadata
- Rule
Generator - Rule generator that learns from examples
- Session
Manager - Session manager for tracking and managing sessions
- Session
Tracking - Session tracking configuration
- Spec
Suggestion Engine - Engine for AI-powered spec suggestion
- State
Machine - State machine for resource lifecycle management
- State
Transition - State transition definition
- Stateful
AiContext - Stateful AI context manager
- SubScenario
- Sub-scenario definition for nested state machine execution
- Suggestion
Config - Configuration for spec suggestion
- Suggestion
Metadata - Metadata about the suggestion generation
- Suggestion
Result - Result from spec suggestion
- Validation
Error Example - Example error response for learning validation error formats
- Validation
Error Response - Validation error response
- Validation
Generator - Validation error generator
- Validation
Issue - Validation issue detected from mutation
- Validation
Rule - Validation rule inferred from examples
- Vector
Memory Store - Vector memory store for persistent, searchable interaction history
- Viewport
- Viewport information for the visual editor
- Visual
Edge - Visual representation of a transition edge
- Visual
Layout - Visual layout for a state machine graph
- Visual
Node - Visual representation of a state node
Enums§
- Change
Type - Type of change detected
- Condition
Error - Error types for condition evaluation
- Error
Format - Error response format
- Mutation
Type - Type of mutation detected
- Output
Format - Output format for generated specs
- Pagination
Format - Pagination format type
- Response
Type - Response type inferred from mutation
- Rule
Action - Action to take when a consistency rule matches
- Rule
Type - Rule type classification
- Suggestion
Input - Input type for spec suggestion
- Validation
Issue Type - Type of validation issue
- Validation
Severity - Severity of validation issue
Type Aliases§
- Condition
Result - Result type for condition evaluation