Implement intelligent agent learning from Knowledge Graph execution history with per-task-type expertise tracking, recency bias, and learning curves. ## Phase 5.3 Implementation ### Learning Infrastructure (✅ Complete) - LearningProfileService with per-task-type expertise metrics - TaskTypeExpertise model tracking success_rate, confidence, learning curves - Recency bias weighting: recent 7 days weighted 3x higher (exponential decay) - Confidence scoring prevents overfitting: min(1.0, executions / 20) - Learning curves computed from daily execution windows ### Agent Scoring Service (✅ Complete) - Unified AgentScore combining SwarmCoordinator + learning profiles - Scoring formula: 0.3*base + 0.5*expertise + 0.2*confidence - Rank agents by combined score for intelligent assignment - Support for recency-biased scoring (recent_success_rate) - Methods: rank_agents, select_best, rank_agents_with_recency ### KG Integration (✅ Complete) - KGPersistence::get_executions_for_task_type() - query by agent + task type - KGPersistence::get_agent_executions() - all executions for agent - Coordinator::load_learning_profile_from_kg() - core KG→Learning integration - Coordinator::load_all_learning_profiles() - batch load for multiple agents - Convert PersistedExecution → ExecutionData for learning calculations ### Agent Assignment Integration (✅ Complete) - AgentCoordinator uses learning profiles for task assignment - extract_task_type() infers task type from title/description - assign_task() scores candidates using AgentScoringService - Fallback to load-based selection if no learning data available - Learning profiles stored in coordinator.learning_profiles RwLock ### Profile Adapter Enhancements (✅ Complete) - create_learning_profile() - initialize empty profiles - add_task_type_expertise() - set task-type expertise - update_profile_with_learning() - update swarm profiles from learning ## Files Modified ### vapora-knowledge-graph/src/persistence.rs (+30 lines) - get_executions_for_task_type(agent_id, task_type, limit) - get_agent_executions(agent_id, limit) ### vapora-agents/src/coordinator.rs (+100 lines) - load_learning_profile_from_kg() - core KG integration method - load_all_learning_profiles() - batch loading for agents - assign_task() already uses learning-based scoring via AgentScoringService ### Existing Complete Implementation - vapora-knowledge-graph/src/learning.rs - calculation functions - vapora-agents/src/learning_profile.rs - data structures and expertise - vapora-agents/src/scoring.rs - unified scoring service - vapora-agents/src/profile_adapter.rs - adapter methods ## Tests Passing - learning_profile: 7 tests ✅ - scoring: 5 tests ✅ - profile_adapter: 6 tests ✅ - coordinator: learning-specific tests ✅ ## Data Flow 1. Task arrives → AgentCoordinator::assign_task() 2. Extract task_type from description 3. Query KG for task-type executions (load_learning_profile_from_kg) 4. Calculate expertise with recency bias 5. Score candidates (SwarmCoordinator + learning) 6. Assign to top-scored agent 7. Execution result → KG → Update learning profiles ## Key Design Decisions ✅ Recency bias: 7-day half-life with 3x weight for recent performance ✅ Confidence scoring: min(1.0, total_executions / 20) prevents overfitting ✅ Hierarchical scoring: 30% base load, 50% expertise, 20% confidence ✅ KG query limit: 100 recent executions per task-type for performance ✅ Async loading: load_learning_profile_from_kg supports concurrent loads ## Next: Phase 5.4 - Cost Optimization Ready to implement budget enforcement and cost-aware provider selection.
357 lines
13 KiB
Plaintext
357 lines
13 KiB
Plaintext
"""
|
|
VAPORA Microservices Configuration
|
|
Defines Deployment, Service, and ConfigMap for each VAPORA service
|
|
"""
|
|
|
|
import k.api.all as k
|
|
|
|
# ===== BACKEND SERVICE (Axum REST API) =====
|
|
|
|
backend_deployment = k.Deployment {
|
|
apiVersion = "apps/v1"
|
|
kind = "Deployment"
|
|
metadata = {
|
|
name = "vapora-backend"
|
|
namespace = "vapora-system"
|
|
labels = {"app": "vapora-backend"}
|
|
}
|
|
spec = {
|
|
replicas = 3
|
|
strategy = {type = "RollingUpdate", rollingUpdate = {maxSurge = 1, maxUnavailable = 0}}
|
|
selector = {matchLabels = {"app": "vapora-backend"}}
|
|
template = {
|
|
metadata = {labels = {"app": "vapora-backend"}}
|
|
spec = {
|
|
serviceAccountName = "vapora-backend"
|
|
containers = [{
|
|
name = "backend"
|
|
image = "vapora/backend:0.2.0"
|
|
imagePullPolicy = "IfNotPresent"
|
|
ports = [
|
|
{name = "http", containerPort = 8080, protocol = "TCP"}
|
|
{name = "metrics", containerPort = 9090, protocol = "TCP"}
|
|
]
|
|
env = [
|
|
{name = "RUST_LOG", value = "info,vapora_backend=debug"}
|
|
{name = "DATABASE_URL", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "database-url"}}}
|
|
{name = "NATS_URL", value = "nats://nats-0.vapora-system:4222"}
|
|
{name = "REDIS_URL", value = "redis://redis-0.vapora-system:6379"}
|
|
]
|
|
livenessProbe = {
|
|
httpGet = {path = "/api/v1/health", port = 8080}
|
|
initialDelaySeconds = 10
|
|
periodSeconds = 10
|
|
}
|
|
readinessProbe = {
|
|
httpGet = {path = "/api/v1/ready", port = 8080}
|
|
initialDelaySeconds = 5
|
|
periodSeconds = 5
|
|
}
|
|
resources = {
|
|
requests = {cpu = "1000m", memory = "2Gi"}
|
|
limits = {cpu = "2000m", memory = "4Gi"}
|
|
}
|
|
volumeMounts = [
|
|
{name = "config", mountPath = "/etc/vapora", readOnly = true}
|
|
]
|
|
}]
|
|
volumes = [{
|
|
name = "config"
|
|
configMap = {name = "vapora-backend-config"}
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
backend_service = k.Service {
|
|
apiVersion = "v1"
|
|
kind = "Service"
|
|
metadata = {name = "vapora-backend", namespace = "vapora-system"}
|
|
spec = {
|
|
type = "ClusterIP"
|
|
ports = [
|
|
{name = "http", port = 8080, targetPort = 8080, protocol = "TCP"}
|
|
{name = "metrics", port = 9090, targetPort = 9090, protocol = "TCP"}
|
|
]
|
|
selector = {"app": "vapora-backend"}
|
|
}
|
|
}
|
|
|
|
# ===== FRONTEND SERVICE (Leptos UI) =====
|
|
|
|
frontend_deployment = k.Deployment {
|
|
apiVersion = "apps/v1"
|
|
kind = "Deployment"
|
|
metadata = {
|
|
name = "vapora-frontend"
|
|
namespace = "vapora-system"
|
|
labels = {"app": "vapora-frontend"}
|
|
}
|
|
spec = {
|
|
replicas = 2
|
|
strategy = {type = "RollingUpdate", rollingUpdate = {maxSurge = 1, maxUnavailable = 0}}
|
|
selector = {matchLabels = {"app": "vapora-frontend"}}
|
|
template = {
|
|
metadata = {labels = {"app": "vapora-frontend"}}
|
|
spec = {
|
|
containers = [{
|
|
name = "frontend"
|
|
image = "vapora/frontend:0.2.0"
|
|
imagePullPolicy = "IfNotPresent"
|
|
ports = [{name = "http", containerPort = 3000, protocol = "TCP"}]
|
|
env = [
|
|
{name = "API_ENDPOINT", value = "http://vapora-backend.vapora-system:8080"}
|
|
{name = "ENVIRONMENT", value = "production"}
|
|
]
|
|
livenessProbe = {
|
|
httpGet = {path = "/", port = 3000}
|
|
initialDelaySeconds = 10
|
|
periodSeconds = 30
|
|
}
|
|
readinessProbe = {
|
|
httpGet = {path = "/", port = 3000}
|
|
initialDelaySeconds = 5
|
|
periodSeconds = 5
|
|
}
|
|
resources = {
|
|
requests = {cpu = "500m", memory = "512Mi"}
|
|
limits = {cpu = "1000m", memory = "1Gi"}
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
frontend_service = k.Service {
|
|
apiVersion = "v1"
|
|
kind = "Service"
|
|
metadata = {name = "vapora-frontend", namespace = "vapora-system"}
|
|
spec = {
|
|
type = "ClusterIP"
|
|
ports = [{name = "http", port = 3000, targetPort = 3000, protocol = "TCP"}]
|
|
selector = {"app": "vapora-frontend"}
|
|
}
|
|
}
|
|
|
|
# ===== AGENT RUNTIME SERVICE =====
|
|
|
|
agents_deployment = k.Deployment {
|
|
apiVersion = "apps/v1"
|
|
kind = "Deployment"
|
|
metadata = {
|
|
name = "vapora-agents"
|
|
namespace = "vapora-system"
|
|
labels = {"app": "vapora-agents"}
|
|
}
|
|
spec = {
|
|
replicas = 3
|
|
strategy = {type = "RollingUpdate"}
|
|
selector = {matchLabels = {"app": "vapora-agents"}}
|
|
template = {
|
|
metadata = {labels = {"app": "vapora-agents"}}
|
|
spec = {
|
|
serviceAccountName = "vapora-agents"
|
|
nodeSelector = {"workload": "vapora"}
|
|
containers = [{
|
|
name = "agents"
|
|
image = "vapora/agents:0.2.0"
|
|
imagePullPolicy = "IfNotPresent"
|
|
ports = [{name = "metrics", containerPort = 9090}]
|
|
env = [
|
|
{name = "RUST_LOG", value = "debug,vapora_agents=trace"}
|
|
{name = "NATS_URL", value = "nats://nats-0.vapora-system:4222"}
|
|
{name = "DATABASE_URL", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "database-url"}}}
|
|
{name = "CLAUDE_API_KEY", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "claude-api-key"}}}
|
|
{name = "OPENAI_API_KEY", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "openai-api-key"}}}
|
|
{name = "GEMINI_API_KEY", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "gemini-api-key"}}}
|
|
]
|
|
resources = {
|
|
requests = {cpu = "4000m", memory = "8Gi"}
|
|
limits = {cpu = "8000m", memory = "16Gi"}
|
|
}
|
|
volumeMounts = [
|
|
{name = "agent-state", mountPath = "/var/vapora/agent-state"}
|
|
]
|
|
}]
|
|
volumes = [{
|
|
name = "agent-state"
|
|
persistentVolumeClaim = {claimName = "vapora-agent-state-pvc"}
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
agents_service = k.Service {
|
|
apiVersion = "v1"
|
|
kind = "Service"
|
|
metadata = {name = "vapora-agents", namespace = "vapora-system"}
|
|
spec = {
|
|
clusterIP = "None" # Headless service for StatefulSet-like behavior
|
|
ports = [{name = "metrics", port = 9090, targetPort = 9090}]
|
|
selector = {"app": "vapora-agents"}
|
|
}
|
|
}
|
|
|
|
# ===== LLM ROUTER SERVICE =====
|
|
|
|
llm_router_deployment = k.Deployment {
|
|
apiVersion = "apps/v1"
|
|
kind = "Deployment"
|
|
metadata = {
|
|
name = "vapora-llm-router"
|
|
namespace = "vapora-system"
|
|
labels = {"app": "vapora-llm-router"}
|
|
}
|
|
spec = {
|
|
replicas = 2
|
|
strategy = {type = "RollingUpdate"}
|
|
selector = {matchLabels = {"app": "vapora-llm-router"}}
|
|
template = {
|
|
metadata = {labels = {"app": "vapora-llm-router"}}
|
|
spec = {
|
|
containers = [{
|
|
name = "router"
|
|
image = "vapora/llm-router:0.2.0"
|
|
imagePullPolicy = "IfNotPresent"
|
|
ports = [
|
|
{name = "http", containerPort = 8899}
|
|
{name = "metrics", containerPort = 9090}
|
|
]
|
|
env = [
|
|
{name = "RUST_LOG", value = "debug,vapora_llm_router=trace"}
|
|
{name = "DATABASE_URL", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "database-url"}}}
|
|
{name = "REDIS_URL", value = "redis://redis-0.vapora-system:6379"}
|
|
{name = "ROUTING_MODE", value = "hybrid"}
|
|
{name = "CLAUDE_API_KEY", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "claude-api-key"}}}
|
|
{name = "OPENAI_API_KEY", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "openai-api-key"}}}
|
|
{name = "GEMINI_API_KEY", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "gemini-api-key"}}}
|
|
]
|
|
livenessProbe = {
|
|
httpGet = {path = "/health", port = 8899}
|
|
initialDelaySeconds = 10
|
|
periodSeconds = 10
|
|
}
|
|
resources = {
|
|
requests = {cpu = "1000m", memory = "2Gi"}
|
|
limits = {cpu = "2000m", memory = "4Gi"}
|
|
}
|
|
volumeMounts = [{name = "routing-cache", mountPath = "/routing-cache"}]
|
|
}]
|
|
volumes = [{
|
|
name = "routing-cache"
|
|
persistentVolumeClaim = {claimName = "vapora-routing-cache-pvc"}
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
llm_router_service = k.Service {
|
|
apiVersion = "v1"
|
|
kind = "Service"
|
|
metadata = {name = "vapora-llm-router", namespace = "vapora-system"}
|
|
spec = {
|
|
type = "ClusterIP"
|
|
ports = [
|
|
{name = "http", port = 8899, targetPort = 8899}
|
|
{name = "metrics", port = 9090, targetPort = 9090}
|
|
]
|
|
selector = {"app": "vapora-llm-router"}
|
|
}
|
|
}
|
|
|
|
# ===== MCP GATEWAY SERVICE =====
|
|
|
|
mcp_gateway_deployment = k.Deployment {
|
|
apiVersion = "apps/v1"
|
|
kind = "Deployment"
|
|
metadata = {
|
|
name = "vapora-mcp-gateway"
|
|
namespace = "vapora-system"
|
|
labels = {"app": "vapora-mcp-gateway"}
|
|
}
|
|
spec = {
|
|
replicas = 2
|
|
strategy = {type = "RollingUpdate"}
|
|
selector = {matchLabels = {"app": "vapora-mcp-gateway"}}
|
|
template = {
|
|
metadata = {labels = {"app": "vapora-mcp-gateway"}}
|
|
spec = {
|
|
containers = [{
|
|
name = "gateway"
|
|
image = "vapora/mcp-gateway:0.2.0"
|
|
imagePullPolicy = "IfNotPresent"
|
|
ports = [
|
|
{name = "http", containerPort = 8888}
|
|
{name = "metrics", containerPort = 9090}
|
|
]
|
|
env = [
|
|
{name = "RUST_LOG", value = "debug,vapora_mcp=trace"}
|
|
{name = "NATS_URL", value = "nats://nats-0.vapora-system:4222"}
|
|
{name = "DATABASE_URL", valueFrom = {secretKeyRef = {name = "vapora-secrets", key = "database-url"}}}
|
|
{name = "MCP_PLUGINS_PATH", value = "/plugins"}
|
|
]
|
|
livenessProbe = {
|
|
httpGet = {path = "/health", port = 8888}
|
|
initialDelaySeconds = 10
|
|
periodSeconds = 10
|
|
}
|
|
resources = {
|
|
requests = {cpu = "1000m", memory = "2Gi"}
|
|
limits = {cpu = "2000m", memory = "4Gi"}
|
|
}
|
|
volumeMounts = [{name = "plugins", mountPath = "/plugins"}]
|
|
}]
|
|
volumes = [{
|
|
name = "plugins"
|
|
persistentVolumeClaim = {claimName = "vapora-plugins-pvc"}
|
|
}]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
mcp_gateway_service = k.Service {
|
|
apiVersion = "v1"
|
|
kind = "Service"
|
|
metadata = {name = "vapora-mcp-gateway", namespace = "vapora-system"}
|
|
spec = {
|
|
type = "ClusterIP"
|
|
ports = [
|
|
{name = "http", port = 8888, targetPort = 8888}
|
|
{name = "metrics", port = 9090, targetPort = 9090}
|
|
]
|
|
selector = {"app": "vapora-mcp-gateway"}
|
|
}
|
|
}
|
|
|
|
# ===== SERVICE ACCOUNTS =====
|
|
|
|
service_accounts = [
|
|
{
|
|
name = "vapora-backend"
|
|
namespace = "vapora-system"
|
|
},
|
|
{
|
|
name = "vapora-agents"
|
|
namespace = "vapora-system"
|
|
},
|
|
{
|
|
name = "vapora-llm-router"
|
|
namespace = "vapora-system"
|
|
}
|
|
]
|
|
|
|
# ===== OUTPUT =====
|
|
|
|
output = {
|
|
backend = {deployment = backend_deployment, service = backend_service}
|
|
frontend = {deployment = frontend_deployment, service = frontend_service}
|
|
agents = {deployment = agents_deployment, service = agents_service}
|
|
llm_router = {deployment = llm_router_deployment, service = llm_router_service}
|
|
mcp_gateway = {deployment = mcp_gateway_deployment, service = mcp_gateway_service}
|
|
}
|