Skip to main content

Module intelligent_behavior

Module intelligent_behavior 

Source
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§

BehaviorModel
Behavior model that uses LLMs to generate intelligent responses
BehaviorRules
Behavior rules that define how the mock API should behave
ConditionEvaluator
Condition evaluator for state machine transitions
ConfidenceScore
Confidence score for an inferred OpenAPI element
ConsistencyRule
Consistency rule that enforces logical behavior patterns
CrudExample
CRUD example for state machine generation
EndpointSuggestion
Individual endpoint suggestion
ErrorExample
Error example for learning validation rules
ExamplePair
Example request/response pair for learning
FieldChange
Change detected in a field
FieldError
Field-level error
HistoryManager
History manager for state machine edits
HttpExchange
Captured HTTP request/response exchange used for behavioral analysis.
IntelligentBehaviorConfig
Configuration for the Intelligent Mock Behavior system
InteractionRecord
A single interaction record (request + response pair)
LlmUsage
LLM usage information
MockAI
MockAI unified interface
MutationAnalysis
Analysis of changes between requests
MutationAnalyzer
Mutation analyzer
OpenApiGenerationConfig
Configuration for OpenAPI spec generation
OpenApiGenerationMetadata
Metadata about the generated OpenAPI spec
OpenApiGenerationResult
Result of OpenAPI spec generation
OpenApiSpecGenerator
OpenAPI specification generator from recorded traffic
PaginatedResponse
Paginated response example
PaginationIntelligence
Pagination intelligence engine
PaginationMetadata
Pagination metadata for response
PaginationRequest
Pagination request parameters
PaginationRule
Pagination rule learned from examples
ParameterInfo
Parameter information
PatternMatch
Pattern match information
Persona
A persona defines consistent data patterns across endpoints
PersonasConfig
Personas configuration for consistent data generation
Relationship
Represents a relationship between two entities
RelationshipInference
Relationship inference engine
Request
HTTP request for MockAI processing.
RequestContext
Request context for error generation
Response
HTTP response from MockAI.
RuleExplanation
Rule explanation metadata
RuleGenerator
Rule generator that learns from examples
SessionManager
Session manager for tracking and managing sessions
SessionTracking
Session tracking configuration
SpecSuggestionEngine
Engine for AI-powered spec suggestion
StateMachine
State machine for resource lifecycle management
StateTransition
State transition definition
StatefulAiContext
Stateful AI context manager
SubScenario
Sub-scenario definition for nested state machine execution
SuggestionConfig
Configuration for spec suggestion
SuggestionMetadata
Metadata about the suggestion generation
SuggestionResult
Result from spec suggestion
ValidationErrorExample
Example error response for learning validation error formats
ValidationErrorResponse
Validation error response
ValidationGenerator
Validation error generator
ValidationIssue
Validation issue detected from mutation
ValidationRule
Validation rule inferred from examples
VectorMemoryStore
Vector memory store for persistent, searchable interaction history
Viewport
Viewport information for the visual editor
VisualEdge
Visual representation of a transition edge
VisualLayout
Visual layout for a state machine graph
VisualNode
Visual representation of a state node

Enums§

ChangeType
Type of change detected
ConditionError
Error types for condition evaluation
ErrorFormat
Error response format
MutationType
Type of mutation detected
OutputFormat
Output format for generated specs
PaginationFormat
Pagination format type
ResponseType
Response type inferred from mutation
RuleAction
Action to take when a consistency rule matches
RuleType
Rule type classification
SuggestionInput
Input type for spec suggestion
ValidationIssueType
Type of validation issue
ValidationSeverity
Severity of validation issue

Type Aliases§

ConditionResult
Result type for condition evaluation