Kailash Kaizen - AI Agent Framework
Kaizen is a production-ready AI agent framework built on Kailash Core SDK that provides signature-based programming and multi-agent coordination.
Features
Kaizen enables building sophisticated AI agents with:
- Signature-Based Programming: Type-safe agent interfaces with automatic validation and optimization
- BaseAgent Architecture: Production-ready agent foundation with error handling, audit trails, and cost tracking
- Multi-Agent Coordination: Supervisor-worker, agent-to-agent protocols, hierarchical structures
- Orchestration Patterns: 9 composable patterns (Ensemble, Blackboard, Router, Parallel, Sequential, Supervisor-Worker, Handoff, Consensus, Debate)
- Multimodal Processing: Vision, audio, and text processing capabilities
- Autonomy Infrastructure: 6 integrated subsystems (Hooks, Checkpoint, Interrupt, Memory, Planning, Meta-Controller)
- Distributed Coordination: AgentRegistry for 100+ agent systems with O(1) capability discovery
- Enterprise Features: Cost tracking, streaming responses, automatic optimization
- Memory System: 3-tier hierarchical storage (Hot/Warm/Cold) with DataFlow backend
- Security: RBAC, process isolation, compliance controls (SOC2, GDPR, HIPAA, PCI-DSS)
- Enterprise Agent Trust Protocol (v0.8.0): Cryptographic trust chains, TrustedAgent, secure messaging, credential rotation
- Performance Optimization (v1.0): 7 caches with 10-100x speedup (SchemaCache, EmbeddingCache, PromptCache, etc.)
- Specialist System (v1.0): Claude Code-style specialists and skills with
.kaizen/ directory
- GPT-5 Support (v1.0): Automatic temperature=1.0 enforcement, 8000 max_tokens for reasoning
- Wrapper Composition System: Stackable cross-cutting wrappers (governance, monitoring, streaming) with enforced ordering
Quick Start
Basic Agent
from kaizen.core.base_agent import BaseAgent
from kaizen.signatures import Signature, InputField, OutputField
from dataclasses import dataclass
# Define agent signature (type-safe interface)
class SummarizeSignature(Signature):
text: str = InputField(description="Text to summarize")
summary: str = OutputField(description="Generated summary")
# Define configuration
@dataclass
class SummaryConfig:
llm_provider: str = os.environ.get("LLM_PROVIDER", "openai")
model: str = os.environ["LLM_MODEL"]
temperature: float = 0.7
# Create agent with signature
class SummaryAgent(BaseAgent):
def __init__(self, config: SummaryConfig):
super().__init__(
config=config,
signature=SummarizeSignature()
)
# Execute
agent = SummaryAgent(SummaryConfig())
result = agent.run(text="Long text here...")
print(result['summary'])
Pipeline Patterns (Orchestration)
from kaizen_agents.patterns.pipeline import Pipeline
# Ensemble: Multi-perspective collaboration
pipeline = Pipeline.ensemble(
agents=[code_expert, data_expert, writing_expert, research_expert],
synthesizer=synthesis_agent,
discovery_mode="a2a", # A2A semantic matching
top_k=3 # Select top 3 agents
)
# Execute - automatically selects best agents for task
result = pipeline.run(task="Analyze codebase", input="repo_path")
# Router: Intelligent task delegation
router = Pipeline.router(
agents=[code_agent, data_agent, writing_agent],
routing_strategy="semantic" # A2A-based routing
)
# Blackboard: Iterative problem-solving
blackboard = Pipeline.blackboard(
agents=[solver, analyzer, optimizer],
controller=controller,
max_iterations=10,
discovery_mode="a2a"
)
Reference Documentation
Comprehensive Guides
For in-depth documentation, see packages/kailash-kaizen/docs/:
Core Guides:
Reference Documentation:
Quick Start (Skills)
- kaizen-quickstart-template - Quick start guide with templates
- kaizen-baseagent-quick - BaseAgent fundamentals
- kaizen-signatures - Signature-based programming
- kaizen-agent-execution - Agent execution patterns
- README - Framework overview
Agent Patterns
- kaizen-agent-patterns - Common agent design patterns
- kaizen-chain-of-thought - Chain of thought reasoning
- kaizen-react-pattern - ReAct (Reason + Act) pattern
- kaizen-rag-agent - Retrieval-Augmented Generation agents
- kaizen-config-patterns - Agent configuration strategies
Multi-Agent Systems & Orchestration
- kaizen-multi-agent-setup - Multi-agent system setup
- kaizen-supervisor-worker - Supervisor-worker coordination
- kaizen-a2a-protocol - Agent-to-agent communication
- kaizen-shared-memory - Shared memory between agents
- kaizen-agent-registry - Distributed agent coordination for 100+ agent systems
Pipeline Patterns (9 Composable Patterns):
- Ensemble: Multi-perspective collaboration with A2A discovery + synthesis
- Blackboard: Controller-driven iterative problem-solving
- Router (Meta-Controller): Intelligent task routing via A2A matching
- Parallel: Concurrent execution with aggregation
- Sequential: Linear agent chain
- Supervisor-Worker: Hierarchical coordination
- Handoff: Agent handoff with context transfer
- Consensus: Voting-based decision making
- Debate: Adversarial deliberation
Multimodal Processing
- kaizen-multimodal-orchestration - Multimodal coordination
- kaizen-vision-processing - Vision and image processing
- kaizen-audio-processing - Audio processing agents
- kaizen-multimodal-pitfalls - Common pitfalls and solutions
Advanced Features
- kaizen-control-protocol - Bidirectional agent ↔ client communication
- kaizen-tool-calling - Autonomous tool execution with approval workflows
- kaizen-memory-system - Persistent memory, learning, FAQ detection
- kaizen-checkpoint-resume - Checkpoint & resume for long-running agents
- kaizen-interrupt-mechanism - Graceful shutdown, Ctrl+C handling
- kaizen-persistent-memory - DataFlow-backed conversation persistence
- kaizen-streaming - Streaming agent responses
- kaizen-cost-tracking - Cost monitoring and optimization
- kaizen-ux-helpers - UX enhancement utilities
Observability & Monitoring
- kaizen-observability-hooks - Lifecycle event hooks, production security (RBAC)
- kaizen-observability-tracing - Distributed tracing with OpenTelemetry
- kaizen-observability-metrics - Prometheus metrics collection
- kaizen-observability-logging - Structured JSON logging
- kaizen-observability-audit - Compliance audit trails
Enterprise Agent Trust Protocol (v0.8.0)
- kaizen-trust-eatp - Complete trust infrastructure for AI agents
- Trust lineage chains with cryptographic verification
- TrustedAgent and TrustedSupervisorAgent with built-in trust
- Secure messaging with HMAC authentication and replay protection
- Trust-aware orchestration with policy enforcement
- Enterprise System Agent (ESA) for legacy system integration
- A2A HTTP service for cross-organization trust operations
- Credential rotation, rate limiting, and security audit logging
Agent Manifest & Deploy (v1.3)
- kaizen-agent-manifest - TOML-based agent declaration, governance metadata, and deployment
AgentManifest with [agent] and [governance] TOML sections
GovernanceManifest with risk_level, suggested_posture, budget
introspect_agent() for runtime metadata extraction (Python API only, NOT MCP)
deploy() / deploy_local() for local FileRegistry or remote CARE Platform
FileRegistry with atomic writes and path traversal prevention
Composition Validation (v1.3)
- kaizen-composition - DAG validation, schema compatibility, cost estimation
validate_dag() with iterative DFS cycle detection (max_agents=1000)
check_schema_compatibility() with JSON Schema structural subtyping and type widening
estimate_cost() with historical data projection and confidence levels
MCP Catalog Server (v1.3)
- kaizen-catalog-server - Standalone MCP server for agent catalog operations
CatalogMCPServer with 11 tools: Discovery (4), Deployment (3), Application (2), Governance (2)
- Separate from KaizenMCPServer (which handles BaseAgent tools)
- Pre-seeds 14 built-in agents on startup
- Entry point:
python -m kaizen.mcp.catalog_server
Budget Tracking & Posture Integration (v1.3)
- kaizen-budget-tracking - Atomic budget accounting and posture-budget governance
BudgetTracker with two-phase reserve/record, threshold callbacks, on_record() API
PostureBudgetIntegration links budget to posture state machine
- Configurable thresholds: warning (80%), downgrade to SUPERVISED (95%), emergency to PSEUDO_AGENT (100%)
L3 Autonomy Primitives
- kaizen-l3-overview - L3 primitives overview (5 subsystems)
- EnvelopeTracker/Splitter/Enforcer for continuous budget tracking
- ScopedContext for hierarchical context with access control
- MessageRouter/Channel for typed inter-agent messaging
- AgentFactory/Registry for runtime agent spawning
- PlanValidator/Executor for DAG task graph execution
- kaizen-l3-envelope - Budget tracking, splitting, and non-bypassable enforcement
EnvelopeTracker with atomic recording, child allocation, reclamation
EnvelopeSplitter for stateless ratio-based budget division
EnvelopeEnforcer middleware with gradient zones (AutoApproved/Flagged/Held/Blocked)
- kaizen-l3-context - Hierarchical scoped context with projection-based access control
ContextScope tree with parent traversal and child merge
ScopeProjection glob patterns (allow/deny with deny precedence)
DataClassification 5-level clearance filtering
- kaizen-l3-messaging - Typed inter-agent communication
MessageRouter with 8-step validation
- 6 typed payloads: Delegation, Status, Clarification, Completion, Escalation, System
DeadLetterStore bounded ring buffer for undeliverable messages
- kaizen-l3-factory - Runtime agent spawning with lifecycle tracking
AgentFactory with 8-check spawn preconditions
- 6-state lifecycle machine (Pending/Running/Waiting/Completed/Failed/Terminated)
- Cascade termination (leaves-first)
- kaizen-l3-plan-dag - Dynamic task graph execution
PlanValidator structural + envelope validation
PlanExecutor with gradient rules (G1-G8)
- 7 typed modifications with batch-atomic application
v1.0 Developer Guides
Located in the package source:
- Performance Optimization (
09-performance-optimization-guide.md) - Caching (10-100x speedup), parallel execution
- Specialist System (
06-specialist-system-guide.md) - Claude Code-style specialists and skills
- Native Tool System (
00-native-tools-guide.md) - TAOD loop tool integration
- Runtime Abstraction (
01-runtime-abstraction-guide.md) - Multi-runtime support
- LocalKaizenAdapter (
02-local-kaizen-adapter-guide.md) - TAOD loop implementation
- Memory Provider (
03-memory-provider-guide.md) - Memory provider interface
- Multi-LLM Routing (
04-multi-llm-routing-guide.md) - Intelligent LLM selection
- Unified Agent API (
05-unified-agent-api-guide.md) - Simplified 2-line agent creation
- Task/Skill Tools (
07-task-skill-tools-guide.md) - Subagent spawning
- Claude Code Parity (
08-claude-code-parity-tools-guide.md) - 7 parity tools
Testing & Quality
Key Concepts
Signature-Based Programming
Signatures define type-safe interfaces for agents:
- Input: Define expected inputs with descriptions
- Output: Specify output format and structure
- Validation: Automatic type checking and validation
- Optimization: Framework can optimize prompts automatically
BaseAgent Architecture
Foundation for all Kaizen agents:
- Error Handling: Built-in retry logic and error recovery
- Audit Trails: Automatic logging of agent actions
- Cost Tracking: Monitor API usage and costs
- Streaming: Support for streaming responses
- Memory: State management across invocations
- Hooks System: Zero-code-change observability and lifecycle management
Autonomy Infrastructure (6 Subsystems)
1. Hooks System - Event-driven observability framework
- Zero-code-change monitoring via lifecycle events (PRE/POST hooks)
- 6 builtin hooks: Logging, Metrics, Cost, Performance, Audit, Tracing
- Production security: RBAC, Ed25519 signatures, process isolation, rate limiting
- Performance: <0.01ms overhead (625x better than 10ms target)
2. Checkpoint System - Persistent state management
- Save/load/fork agent state for failure recovery
- 4 storage backends: Filesystem, Redis, PostgreSQL, S3
- Automatic compression and incremental checkpoints
- State manager with deduplication and versioning
3. Interrupt Mechanism - Graceful shutdown and execution control
- 3 interrupt sources: USER (Ctrl+C), SYSTEM (timeout/budget), PROGRAMMATIC (API)
- 2 shutdown modes: GRACEFUL (finish cycle + checkpoint) vs IMMEDIATE (stop now)
- Signal propagation across multi-agent hierarchies
4. Memory System - 3-tier hierarchical storage
- Hot tier: In-memory buffer (<1ms retrieval, last 100 messages)
- Warm tier: Database (10-50ms, agent-specific history with JSONL compression)
- Cold tier: Object storage (100ms+, long-term archival with S3/MinIO)
- DataFlow-backed with auto-persist and cross-session continuity
5. Planning Agents - Structured workflow orchestration
- PlanningAgent: Plan before you act (pre-execution validation)
- PEVAgent: Plan, Execute, Verify, Refine (iterative refinement)
- Tree-of-Thoughts: Explore multiple reasoning paths
- Multi-step decomposition, validation, and replanning
6. Meta-Controller Routing - Intelligent task delegation
- A2A-based semantic capability matching (no hardcoded if/else)
- Automatic agent discovery, ranking, and selection
- Fallback strategies and load balancing
- Integrated with Router, Ensemble, and Supervisor-Worker patterns
AgentRegistry - Distributed Coordination
For 100+ agent distributed systems:
- O(1) capability-based discovery with semantic matching
- Event broadcasting (6 event types for cross-runtime coordination)
- Health monitoring with automatic deregistration
- Status management (ACTIVE, UNHEALTHY, DEGRADED, OFFLINE)
- Multi-runtime coordination across processes/machines
When to Use This Skill
Use Kaizen when you need to:
- Build AI agents with type-safe interfaces
- Implement multi-agent systems with orchestration patterns
- Process multimodal inputs (vision, audio, text)
- Create RAG (Retrieval-Augmented Generation) systems
- Implement chain-of-thought reasoning
- Build supervisor-worker or ensemble architectures
- Track costs and performance of AI agents
- Add zero-code-change observability to agents
- Monitor, trace, and audit agent behavior in production
- Secure agent observability with RBAC and compliance controls
- Create production-ready agentic applications
- Enterprise trust and accountability (v0.8.0):
- Cryptographic trust chains for AI agents
- Cross-organization agent coordination
- Regulatory compliance with audit trails
- Secure inter-agent communication
- Agent manifest, deploy, and composition (v1.3):
- Declare agents with TOML manifests and governance metadata
- Deploy agents to local FileRegistry or remote CARE Platform
- Validate composite agent DAGs for cycles
- Check schema compatibility between connected agents
- Estimate pipeline costs from historical data
- Discover/deploy agents via MCP Catalog Server
- Link budget thresholds to automatic posture transitions
- L3 Autonomy Primitives:
- Agent spawning with PACT-governed lifecycle tracking
- Continuous budget tracking with gradient zones and non-bypassable enforcement
- Hierarchical scoped context with projection-based access control
- Typed inter-agent messaging with 8-step routing validation
- Dynamic task graph execution with gradient-driven failure handling
Use Pipeline Patterns When:
- Ensemble: Need diverse perspectives synthesized (code review, research)
- Blackboard: Iterative problem-solving (optimization, debugging)
- Router: Intelligent task delegation to specialists
- Parallel: Bulk processing or voting-based consensus
- Sequential: Linear workflows with dependency chains
Integration Patterns
With DataFlow (Data-Driven Agents)
from kaizen.core.base_agent import BaseAgent
from dataflow import DataFlow
class DataAgent(BaseAgent):
def __init__(self, config, db: DataFlow):
self.db = db
super().__init__(config=config, signature=MySignature())
With Nexus (Multi-Channel Agents)
from kaizen.core.base_agent import BaseAgent
from nexus import Nexus
# Deploy agents via API/CLI/MCP
agent_workflow = create_agent_workflow()
app = Nexus()
app.register("agent", agent_workflow.build())
app.start() # Agents available via all channels
With Core SDK (Custom Workflows)
from kaizen.core.base_agent import BaseAgent
from kailash.workflow.builder import WorkflowBuilder
# Embed agents in workflows
workflow = WorkflowBuilder()
workflow.add_node("KaizenAgent", "agent1", {
"agent": my_agent,
"input": "..."
})
Provider Configuration (v2.5.0 -- Explicit over Implicit)
As of v2.5.0, provider configuration follows an explicit over implicit model. Structured output config is separated from provider-specific settings.
BaseAgentConfig Fields
| Field |
Purpose |
Example |
response_format |
Structured output config (json_schema, json_object) |
{"type": "json_schema", "json_schema": {}} |
provider_config |
Provider-specific operational settings only |
{"api_version": "2024-10-21"} |
structured_output_mode |
Controls auto-generation: "auto" (deprecated), "explicit", "off" |
"explicit" |
Quick Pattern
from kaizen.core.config import BaseAgentConfig
from kaizen.core.structured_output import create_structured_output_config
# Explicit mode (recommended)
config = BaseAgentConfig(
llm_provider="openai",
model=os.environ["LLM_MODEL"],
response_format=create_structured_output_config(MySignature(), strict=True),
structured_output_mode="explicit",
)
# Azure with provider-specific settings (separate from response_format)
config = BaseAgentConfig(
llm_provider="azure",
model=os.environ["LLM_MODEL"],
response_format={"type": "json_object"},
provider_config={"api_version": "2024-10-21"},
structured_output_mode="explicit",
)
Azure Env Vars (Canonical Names)
| Canonical |
Legacy (deprecated) |
AZURE_ENDPOINT |
AZURE_OPENAI_ENDPOINT, AZURE_AI_INFERENCE_ENDPOINT |
AZURE_API_KEY |
AZURE_OPENAI_API_KEY, AZURE_AI_INFERENCE_API_KEY |
AZURE_API_VERSION |
AZURE_OPENAI_API_VERSION |
Legacy vars emit DeprecationWarning. Use resolve_azure_env() from kaizen.nodes.ai.azure_detection for canonical-first resolution.
Anti-Patterns
- Never put structured output config in
provider_config -- use response_format
- Never rely on auto-generated structured output without understanding it -- set
structured_output_mode="explicit"
- Never use multiple env var names for the same Azure setting without deprecation
- Never use error-based backend switching -- detect the backend upfront or set
AZURE_BACKEND explicitly
Prompt Utilities
kaizen.core.prompt_utils is the single source of truth for signature-based prompt generation:
generate_prompt_from_signature(signature) -- builds system prompt from signature fields
json_prompt_suffix(output_fields) -- returns JSON format instructions for Azure json_object compatibility
For detailed configuration patterns, see:
- kaizen-config-patterns -- Domain configs, auto-extraction, provider-specific patterns
- kaizen-structured-outputs -- Full structured output guide with migration examples
Critical Rules
- Define signatures before implementing agents
- Extend BaseAgent for production agents
- Use type hints in signatures for validation
- Track costs in production environments
- Test agents with real infrastructure (real infrastructure recommended)
- Enable hooks for observability
- Use AgentRegistry for distributed coordination
- Use
response_format for structured output (not provider_config)
- Set
structured_output_mode="explicit" for new agents
- NEVER skip signature definitions
- NEVER ignore cost tracking in production
- NEVER put structured output keys in
provider_config
- Avoid mocking LLM calls in integration tests (real infrastructure recommended)
Kaizen-Agents Governance (v0.1.0)
- kaizen-agents-governance -- GovernedSupervisor, progressive disclosure (Layer 1/2/3), 7 governance modules
GovernedSupervisor with 3-layer progressive API (2-param simple -> 8-param configured -> 9 governance subsystems)
AccountabilityTracker -- D/T/R addressing, policy source chain
BudgetTracker -- reclamation, predictive warnings, reallocation
CascadeManager -- monotonic envelope tightening, BFS termination
ClearanceEnforcer + ClassificationAssigner -- data classification (C0-C4), regex pre-filter
DerelictionDetector -- insufficient tightening detection
BypassManager -- time-limited emergency overrides with anti-stacking
VacancyManager -- orphan detection, grandparent auto-designation
AuditTrail -- EATP hash chain with hmac.compare_digest()
- SDK integration:
EnvelopeAllocator -> EnvelopeSplitter, ScopeBridge -> ScopedContext
L3 Integration & Event System
kaizen-l3-overview -- L3 autonomy primitives, L3Runtime integration, EATP event system
L3Runtime convenience class wiring all 5 subsystems (Factory->Enforcer, Factory->Router, Factory->Context, Enforcer->Plan)
L3EventBus pub/sub for 15 governance event types across all primitives
EatpTranslator converts L3 events into EATP audit records with severity classification
kaizen-agents-security -- Security patterns for governance
- Anti-self-modification via
_ReadOnlyView proxies
- Pervasive NaN/Inf defense (
math.isfinite() on all numeric paths)
- Bounded collections, monotonic invariants, thread safety
- Delegate tool security (mandatory BashTool gate, ExecPolicy, session sanitization)
Wrapper Composition System
Composition wrappers add cross-cutting concerns (governance, monitoring, streaming) around a BaseAgent without modifying it. WrapperBase enforces a canonical stacking order and duplicate detection.
Canonical stacking order (innermost to outermost):
BaseAgent -> L3GovernedAgent -> MonitoredAgent -> StreamingAgent
WrapperBase rejects duplicate wrappers (DuplicateWrapperError) and out-of-order stacking (WrapperOrderError). Every wrapper proxies get_parameters() and to_workflow() to the inner agent. The innermost property walks the full stack to the non-wrapper agent.
Key files:
packages/kaizen-agents/src/kaizen_agents/wrapper_base.py -- WrapperBase with stack ordering + duplicate detection
packages/kaizen-agents/src/kaizen_agents/governed_agent.py -- L3GovernedAgent with ConstraintEnvelope enforcement (Financial, Operational, Temporal, Data Access, Communication, Posture ceiling). Rejects BEFORE LLM cost is incurred. Uses _ProtectedInnerProxy to block governance bypass via .inner._inner.
packages/kaizen-agents/src/kaizen_agents/monitored_agent.py -- MonitoredAgent with CostTracker, budget enforcement via BudgetExhaustedError, NaN/Inf defense on budget values
packages/kaizen-agents/src/kaizen_agents/streaming_agent.py -- StreamingAgent with run_stream() async iterator, typed StreamEvent events, buffer overflow protection, timeout enforcement. Falls back to batch when provider lacks StreamingProvider.
packages/kaizen-agents/src/kaizen_agents/events.py -- Frozen dataclass events: TextDelta, ToolCallStart, ToolCallEnd, TurnComplete, BudgetExhausted, ErrorEvent, StreamBufferOverflow
packages/kaizen-agents/src/kaizen_agents/supervisor_wrapper.py -- SupervisorWrapper for task delegation to worker pool via LLMBased routing
Building a wrapper stack:
from kaizen.core.base_agent import BaseAgent
from kaizen_agents.governed_agent import L3GovernedAgent
from kaizen_agents.monitored_agent import MonitoredAgent
from kaizen_agents.streaming_agent import StreamingAgent
from kaizen_agents.events import TextDelta, TurnComplete
from kailash.trust.envelope import ConstraintEnvelope, FinancialConstraint
# Stack innermost to outermost
agent = MyAgent(config=config)
governed = L3GovernedAgent(agent, envelope=ConstraintEnvelope(
financial=FinancialConstraint(budget_limit=10.0)
))
monitored = MonitoredAgent(governed, budget_usd=5.0)
streaming = StreamingAgent(monitored)
# Stream typed events
async for event in streaming.run_stream(prompt="analyze this"):
match event:
case TextDelta(text=t): print(t, end="")
case TurnComplete(text=t): print(f"\n[Done: {t[:50]}]")
SupervisorWrapper -- delegates tasks to a worker pool using LLM-based routing:
from kaizen_agents.supervisor_wrapper import SupervisorWrapper
from kaizen_agents.patterns.llm_routing import LLMBased
supervisor = SupervisorWrapper(inner_agent, workers=[w1, w2], routing=LLMBased())
result = await supervisor.run_async(task="complex task")
Provider Capability Protocols
SPEC-02 defines runtime_checkable protocols in kaizen.providers.base for structural capability discovery. Providers satisfy protocols structurally -- no explicit inheritance needed.
| Protocol |
Key Method |
Purpose |
StreamingProvider |
stream_chat() -> StreamEvent |
Token-by-token streaming |
ToolCallingProvider |
chat_with_tools(messages, tools) |
Native function calling |
StructuredOutputProvider |
chat_structured(messages, schema) |
JSON schema structured outputs |
AsyncLLMProvider |
chat_async(messages) |
Async chat completions |
ProviderCapability enum: CHAT_SYNC, CHAT_ASYNC, CHAT_STREAM, TOOLS, STRUCTURED_OUTPUT, EMBEDDINGS, VISION, AUDIO, REASONING_MODELS, BYOK.
Use get_provider_for_model(model) from kaizen.providers.registry to resolve a model string to a provider instance. Use isinstance(provider, StreamingProvider) for capability checks.
LLM-Based Routing
LLMBased from kaizen_agents.patterns.llm_routing scores agent capabilities against task requirements using Kaizen signatures (not keyword matching or dispatch tables).
from kaizen_agents.patterns.llm_routing import LLMBased
routing = LLMBased(config=config) # config optional; falls back to .env defaults
score = await routing.score("analyze revenue data", agent_capability)
best = await routing.select_best("analyze revenue data", [agent1, agent2, agent3])
score() returns [0.0, 1.0]. Accepts Capability dataclasses (.name + .description) or plain strings. select_best() returns the highest-scoring candidate or None when empty.
Convergence Status (SPEC-02 / SPEC-05 / SPEC-10)
Three convergence SPECs have shipped on the feat/spec04-baseagent-slim branch:
SPEC-02 (Provider Split) -- The provider monolith (kaizen.nodes.ai.ai_providers) is now split into per-provider modules under kaizen/providers/. See kaizen-multi-provider for the updated registry, protocols, and CostTracker.
kaizen.providers.base -- ProviderCapability enum (10 members), 5 runtime-checkable protocols
kaizen.providers.registry -- ProviderRegistry with 14 provider entries and prefix-dispatch model detection
kaizen.providers.cost -- CostTracker with thread-safe accumulation
- Backward-compat shim at
kaizen.nodes.ai.ai_providers re-exports all public names
SPEC-05 (Delegate Facade) -- Delegate is now a composition facade wrapping AgentLoop -> [L3GovernedAgent] -> [MonitoredAgent]. See kaizen-delegate for the updated API surface.
ConstructorIOError -- raised on outbound IO in __init__
ToolRegistryCollisionError -- raised on duplicate tool name registration
run_sync() refuses under a running event loop with an actionable error message
- Deferred MCP:
mcp_servers= stores configs, connects on first run()
- Introspection:
.core_agent, .signature, .model read-only properties
SPEC-10 (Multi-Agent) -- 11 deprecated agent subclasses (SupervisorAgent, WorkerAgent, CoordinatorAgent, PipelineStageAgent, etc.) now emit DeprecationWarning. Composition patterns accept plain BaseAgent instances. max_total_delegations cap (default 20) with DelegationCapExceeded exception.
Related Skills
Support
For Kaizen-specific questions, invoke:
kaizen-specialist - Kaizen framework implementation
testing-specialist - Agent testing strategies
- ``decide-framework
skill - When to use Kaizen vs other frameworks
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: integrum-global-kailash-vibe-cc-setup-04-kaizen3description: Kailash Kaizen - AI Agent Framework4---56# Kailash Kaizen - AI Agent Framework78Kaizen is a production-ready AI agent framework built on Kailash Core SDK that provides signature-based programming and multi-agent coordination.910## Features1112Kaizen enables building sophisticated AI agents with:1314- **Signature-Based Programming**: Type-safe agent interfaces with automatic validation and optimization15- **BaseAgent Architecture**: Production-ready agent foundation with error handling, audit trails, and cost tracking16- **Multi-Agent Coordination**: Supervisor-worker, agent-to-agent protocols, hierarchical structures17- **Orchestration Patterns**: 9 composable patterns (Ensemble, Blackboard, Router, Parallel, Sequential, Supervisor-Worker, Handoff, Consensus, Debate)18- **Multimodal Processing**: Vision, audio, and text processing capabilities19- **Autonomy Infrastructure**: 6 integrated subsystems (Hooks, Checkpoint, Interrupt, Memory, Planning, Meta-Controller)20- **Distributed Coordination**: AgentRegistry for 100+ agent systems with O(1) capability discovery21- **Enterprise Features**: Cost tracking, streaming responses, automatic optimization22- **Memory System**: 3-tier hierarchical storage (Hot/Warm/Cold) with DataFlow backend23- **Security**: RBAC, process isolation, compliance controls (SOC2, GDPR, HIPAA, PCI-DSS)24- **Enterprise Agent Trust Protocol (v0.8.0)**: Cryptographic trust chains, TrustedAgent, secure messaging, credential rotation25- **Performance Optimization (v1.0)**: 7 caches with 10-100x speedup (SchemaCache, EmbeddingCache, PromptCache, etc.)26- **Specialist System (v1.0)**: Claude Code-style specialists and skills with `.kaizen/` directory27- **GPT-5 Support (v1.0)**: Automatic temperature=1.0 enforcement, 8000 max_tokens for reasoning28- **Wrapper Composition System**: Stackable cross-cutting wrappers (governance, monitoring, streaming) with enforced ordering2930## Quick Start3132### Basic Agent3334```python35from kaizen.core.base_agent import BaseAgent36from kaizen.signatures import Signature, InputField, OutputField37from dataclasses import dataclass3839# Define agent signature (type-safe interface)40class SummarizeSignature(Signature):41 text: str = InputField(description="Text to summarize")42 summary: str = OutputField(description="Generated summary")4344# Define configuration45@dataclass46class SummaryConfig:47 llm_provider: str = os.environ.get("LLM_PROVIDER", "openai")48 model: str = os.environ["LLM_MODEL"]49 temperature: float = 0.75051# Create agent with signature52class SummaryAgent(BaseAgent):53 def __init__(self, config: SummaryConfig):54 super().__init__(55 config=config,56 signature=SummarizeSignature()57 )5859# Execute60agent = SummaryAgent(SummaryConfig())61result = agent.run(text="Long text here...")62print(result['summary'])63```6465### Pipeline Patterns (Orchestration)6667```python68from kaizen_agents.patterns.pipeline import Pipeline6970# Ensemble: Multi-perspective collaboration71pipeline = Pipeline.ensemble(72 agents=[code_expert, data_expert, writing_expert, research_expert],73 synthesizer=synthesis_agent,74 discovery_mode="a2a", # A2A semantic matching75 top_k=3 # Select top 3 agents76)7778# Execute - automatically selects best agents for task79result = pipeline.run(task="Analyze codebase", input="repo_path")8081# Router: Intelligent task delegation82router = Pipeline.router(83 agents=[code_agent, data_agent, writing_agent],84 routing_strategy="semantic" # A2A-based routing85)8687# Blackboard: Iterative problem-solving88blackboard = Pipeline.blackboard(89 agents=[solver, analyzer, optimizer],90 controller=controller,91 max_iterations=10,92 discovery_mode="a2a"93)94```9596## Reference Documentation9798### Comprehensive Guides99100For in-depth documentation, see `packages/kailash-kaizen/docs/`:101102**Core Guides:**103104- **[BaseAgent Architecture](../../../packages/kailash-kaizen/docs/guides/baseagent-architecture.md)** - Complete unified agent system guide105- **[Multi-Agent Coordination](../../../packages/kailash-kaizen/docs/guides/multi-agent-coordination.md)** - Google A2A protocol, 5 coordination patterns106- **[Signature Programming](../../../packages/kailash-kaizen/docs/guides/signature-programming.md)** - Complete signature system guide107- **[Hooks System Guide](../../../packages/kailash-kaizen/docs/guides/hooks-system-guide.md)** - Event-driven observability framework108- **[Integration Patterns](../../../packages/kailash-kaizen/docs/guides/integration-patterns.md)** - DataFlow, Nexus, MCP integration109- **[Meta-Controller Guide](../../../packages/kailash-kaizen/docs/guides/meta-controller-guide.md)** - Intelligent task delegation110- **[Planning System Guide](../../../packages/kailash-kaizen/docs/guides/planning-system-guide.md)** - Structured workflow orchestration111112**Reference Documentation:**113114- **[API Reference](../../../packages/kailash-kaizen/docs/reference/api-reference.md)** - Complete API documentation115- **[Checkpoint API](../../../packages/kailash-kaizen/docs/reference/checkpoint-api.md)** - State persistence API116- **[Coordination API](../../../packages/kailash-kaizen/docs/reference/coordination-api.md)** - Multi-agent coordination API117- **[Interrupts API](../../../packages/kailash-kaizen/docs/reference/interrupts-api.md)** - Graceful shutdown API118- **[Memory API](../../../packages/kailash-kaizen/docs/reference/memory-api.md)** - 3-tier memory system API119- **[Observability API](../../../packages/kailash-kaizen/docs/reference/observability-api.md)** - Hooks and monitoring API120- **[Planning Agents API](../../../packages/kailash-kaizen/docs/reference/planning-agents-api.md)** - Planning/PEV/ToT agents API121- **[Tools API](../../../packages/kailash-kaizen/docs/reference/tools-api.md)** - Tool calling and approval API122- **[Configuration Guide](../../../packages/kailash-kaizen/docs/reference/configuration.md)** - All configuration options123- **[Troubleshooting](../../../packages/kailash-kaizen/docs/reference/troubleshooting.md)** - Common issues and solutions124125### Quick Start (Skills)126127- **[kaizen-quickstart-template](kaizen-quickstart-template.md)** - Quick start guide with templates128- **[kaizen-baseagent-quick](kaizen-baseagent-quick.md)** - BaseAgent fundamentals129- **[kaizen-signatures](kaizen-signatures.md)** - Signature-based programming130- **[kaizen-agent-execution](kaizen-agent-execution.md)** - Agent execution patterns131- **[README](README.md)** - Framework overview132133### Agent Patterns134135- **[kaizen-agent-patterns](kaizen-agent-patterns.md)** - Common agent design patterns136- **[kaizen-chain-of-thought](kaizen-chain-of-thought.md)** - Chain of thought reasoning137- **[kaizen-react-pattern](kaizen-react-pattern.md)** - ReAct (Reason + Act) pattern138- **[kaizen-rag-agent](kaizen-rag-agent.md)** - Retrieval-Augmented Generation agents139- **[kaizen-config-patterns](kaizen-config-patterns.md)** - Agent configuration strategies140141### Multi-Agent Systems & Orchestration142143- **[kaizen-multi-agent-setup](kaizen-multi-agent-setup.md)** - Multi-agent system setup144- **[kaizen-supervisor-worker](kaizen-supervisor-worker.md)** - Supervisor-worker coordination145- **[kaizen-a2a-protocol](kaizen-a2a-protocol.md)** - Agent-to-agent communication146- **[kaizen-shared-memory](kaizen-shared-memory.md)** - Shared memory between agents147- **[kaizen-agent-registry](kaizen-agent-registry.md)** - Distributed agent coordination for 100+ agent systems148149**Pipeline Patterns** (9 Composable Patterns):150151- **Ensemble**: Multi-perspective collaboration with A2A discovery + synthesis152- **Blackboard**: Controller-driven iterative problem-solving153- **Router** (Meta-Controller): Intelligent task routing via A2A matching154- **Parallel**: Concurrent execution with aggregation155- **Sequential**: Linear agent chain156- **Supervisor-Worker**: Hierarchical coordination157- **Handoff**: Agent handoff with context transfer158- **Consensus**: Voting-based decision making159- **Debate**: Adversarial deliberation160161### Multimodal Processing162163- **[kaizen-multimodal-orchestration](kaizen-multimodal-orchestration.md)** - Multimodal coordination164- **[kaizen-vision-processing](kaizen-vision-processing.md)** - Vision and image processing165- **[kaizen-audio-processing](kaizen-audio-processing.md)** - Audio processing agents166- **[kaizen-multimodal-pitfalls](kaizen-multimodal-pitfalls.md)** - Common pitfalls and solutions167168### Advanced Features169170- **[kaizen-control-protocol](kaizen-control-protocol.md)** - Bidirectional agent ↔ client communication171- **[kaizen-tool-calling](kaizen-tool-calling.md)** - Autonomous tool execution with approval workflows172- **[kaizen-memory-system](kaizen-memory-system.md)** - Persistent memory, learning, FAQ detection173- **[kaizen-checkpoint-resume](kaizen-checkpoint-resume.md)** - Checkpoint & resume for long-running agents174- **[kaizen-interrupt-mechanism](kaizen-interrupt-mechanism.md)** - Graceful shutdown, Ctrl+C handling175- **[kaizen-persistent-memory](kaizen-persistent-memory.md)** - DataFlow-backed conversation persistence176- **[kaizen-streaming](kaizen-streaming.md)** - Streaming agent responses177- **[kaizen-cost-tracking](kaizen-cost-tracking.md)** - Cost monitoring and optimization178- **[kaizen-ux-helpers](kaizen-ux-helpers.md)** - UX enhancement utilities179180### Observability & Monitoring181182- **[kaizen-observability-hooks](kaizen-observability-hooks.md)** - Lifecycle event hooks, production security (RBAC)183- **[kaizen-observability-tracing](kaizen-observability-tracing.md)** - Distributed tracing with OpenTelemetry184- **[kaizen-observability-metrics](kaizen-observability-metrics.md)** - Prometheus metrics collection185- **[kaizen-observability-logging](kaizen-observability-logging.md)** - Structured JSON logging186- **[kaizen-observability-audit](kaizen-observability-audit.md)** - Compliance audit trails187188### Enterprise Agent Trust Protocol (v0.8.0)189190- **[kaizen-trust-eatp](kaizen-trust-eatp.md)** - Complete trust infrastructure for AI agents191 - Trust lineage chains with cryptographic verification192 - TrustedAgent and TrustedSupervisorAgent with built-in trust193 - Secure messaging with HMAC authentication and replay protection194 - Trust-aware orchestration with policy enforcement195 - Enterprise System Agent (ESA) for legacy system integration196 - A2A HTTP service for cross-organization trust operations197 - Credential rotation, rate limiting, and security audit logging198199### Agent Manifest & Deploy (v1.3)200201- **[kaizen-agent-manifest](kaizen-agent-manifest.md)** - TOML-based agent declaration, governance metadata, and deployment202 - `AgentManifest` with `[agent]` and `[governance]` TOML sections203 - `GovernanceManifest` with risk_level, suggested_posture, budget204 - `introspect_agent()` for runtime metadata extraction (Python API only, NOT MCP)205 - `deploy()` / `deploy_local()` for local FileRegistry or remote CARE Platform206 - `FileRegistry` with atomic writes and path traversal prevention207208### Composition Validation (v1.3)209210- **[kaizen-composition](kaizen-composition.md)** - DAG validation, schema compatibility, cost estimation211 - `validate_dag()` with iterative DFS cycle detection (max_agents=1000)212 - `check_schema_compatibility()` with JSON Schema structural subtyping and type widening213 - `estimate_cost()` with historical data projection and confidence levels214215### MCP Catalog Server (v1.3)216217- **[kaizen-catalog-server](kaizen-catalog-server.md)** - Standalone MCP server for agent catalog operations218 - `CatalogMCPServer` with 11 tools: Discovery (4), Deployment (3), Application (2), Governance (2)219 - Separate from KaizenMCPServer (which handles BaseAgent tools)220 - Pre-seeds 14 built-in agents on startup221 - Entry point: `python -m kaizen.mcp.catalog_server`222223### Budget Tracking & Posture Integration (v1.3)224225- **[kaizen-budget-tracking](kaizen-budget-tracking.md)** - Atomic budget accounting and posture-budget governance226 - `BudgetTracker` with two-phase reserve/record, threshold callbacks, `on_record()` API227 - `PostureBudgetIntegration` links budget to posture state machine228 - Configurable thresholds: warning (80%), downgrade to SUPERVISED (95%), emergency to PSEUDO_AGENT (100%)229230### L3 Autonomy Primitives231232- **[kaizen-l3-overview](kaizen-l3-overview.md)** - L3 primitives overview (5 subsystems)233 - EnvelopeTracker/Splitter/Enforcer for continuous budget tracking234 - ScopedContext for hierarchical context with access control235 - MessageRouter/Channel for typed inter-agent messaging236 - AgentFactory/Registry for runtime agent spawning237 - PlanValidator/Executor for DAG task graph execution238- **[kaizen-l3-envelope](kaizen-l3-envelope.md)** - Budget tracking, splitting, and non-bypassable enforcement239 - `EnvelopeTracker` with atomic recording, child allocation, reclamation240 - `EnvelopeSplitter` for stateless ratio-based budget division241 - `EnvelopeEnforcer` middleware with gradient zones (AutoApproved/Flagged/Held/Blocked)242- **[kaizen-l3-context](kaizen-l3-context.md)** - Hierarchical scoped context with projection-based access control243 - `ContextScope` tree with parent traversal and child merge244 - `ScopeProjection` glob patterns (allow/deny with deny precedence)245 - `DataClassification` 5-level clearance filtering246- **[kaizen-l3-messaging](kaizen-l3-messaging.md)** - Typed inter-agent communication247 - `MessageRouter` with 8-step validation248 - 6 typed payloads: Delegation, Status, Clarification, Completion, Escalation, System249 - `DeadLetterStore` bounded ring buffer for undeliverable messages250- **[kaizen-l3-factory](kaizen-l3-factory.md)** - Runtime agent spawning with lifecycle tracking251 - `AgentFactory` with 8-check spawn preconditions252 - 6-state lifecycle machine (Pending/Running/Waiting/Completed/Failed/Terminated)253 - Cascade termination (leaves-first)254- **[kaizen-l3-plan-dag](kaizen-l3-plan-dag.md)** - Dynamic task graph execution255 - `PlanValidator` structural + envelope validation256 - `PlanExecutor` with gradient rules (G1-G8)257 - 7 typed modifications with batch-atomic application258259### v1.0 Developer Guides260261Located in the package source:262263- **Performance Optimization** (`09-performance-optimization-guide.md`) - Caching (10-100x speedup), parallel execution264- **Specialist System** (`06-specialist-system-guide.md`) - Claude Code-style specialists and skills265- **Native Tool System** (`00-native-tools-guide.md`) - TAOD loop tool integration266- **Runtime Abstraction** (`01-runtime-abstraction-guide.md`) - Multi-runtime support267- **LocalKaizenAdapter** (`02-local-kaizen-adapter-guide.md`) - TAOD loop implementation268- **Memory Provider** (`03-memory-provider-guide.md`) - Memory provider interface269- **Multi-LLM Routing** (`04-multi-llm-routing-guide.md`) - Intelligent LLM selection270- **Unified Agent API** (`05-unified-agent-api-guide.md`) - Simplified 2-line agent creation271- **Task/Skill Tools** (`07-task-skill-tools-guide.md`) - Subagent spawning272- **Claude Code Parity** (`08-claude-code-parity-tools-guide.md`) - 7 parity tools273274### Testing & Quality275276- **[kaizen-testing-patterns](kaizen-testing-patterns.md)** - Testing AI agents277- **[Performance Benchmarks](../../../packages/kailash-kaizen/docs/benchmarks/BENCHMARK_GUIDE.md)** - Measure Kaizen performance278279## Key Concepts280281### Signature-Based Programming282283Signatures define type-safe interfaces for agents:284285- **Input**: Define expected inputs with descriptions286- **Output**: Specify output format and structure287- **Validation**: Automatic type checking and validation288- **Optimization**: Framework can optimize prompts automatically289290### BaseAgent Architecture291292Foundation for all Kaizen agents:293294- **Error Handling**: Built-in retry logic and error recovery295- **Audit Trails**: Automatic logging of agent actions296- **Cost Tracking**: Monitor API usage and costs297- **Streaming**: Support for streaming responses298- **Memory**: State management across invocations299- **Hooks System**: Zero-code-change observability and lifecycle management300301### Autonomy Infrastructure (6 Subsystems)302303**1. Hooks System** - Event-driven observability framework304305- Zero-code-change monitoring via lifecycle events (PRE/POST hooks)306- 6 builtin hooks: Logging, Metrics, Cost, Performance, Audit, Tracing307- Production security: RBAC, Ed25519 signatures, process isolation, rate limiting308- Performance: <0.01ms overhead (625x better than 10ms target)309310**2. Checkpoint System** - Persistent state management311312- Save/load/fork agent state for failure recovery313- 4 storage backends: Filesystem, Redis, PostgreSQL, S3314- Automatic compression and incremental checkpoints315- State manager with deduplication and versioning316317**3. Interrupt Mechanism** - Graceful shutdown and execution control318319- 3 interrupt sources: USER (Ctrl+C), SYSTEM (timeout/budget), PROGRAMMATIC (API)320- 2 shutdown modes: GRACEFUL (finish cycle + checkpoint) vs IMMEDIATE (stop now)321- Signal propagation across multi-agent hierarchies322323**4. Memory System** - 3-tier hierarchical storage324325- Hot tier: In-memory buffer (<1ms retrieval, last 100 messages)326- Warm tier: Database (10-50ms, agent-specific history with JSONL compression)327- Cold tier: Object storage (100ms+, long-term archival with S3/MinIO)328- DataFlow-backed with auto-persist and cross-session continuity329330**5. Planning Agents** - Structured workflow orchestration331332- PlanningAgent: Plan before you act (pre-execution validation)333- PEVAgent: Plan, Execute, Verify, Refine (iterative refinement)334- Tree-of-Thoughts: Explore multiple reasoning paths335- Multi-step decomposition, validation, and replanning336337**6. Meta-Controller Routing** - Intelligent task delegation338339- A2A-based semantic capability matching (no hardcoded if/else)340- Automatic agent discovery, ranking, and selection341- Fallback strategies and load balancing342- Integrated with Router, Ensemble, and Supervisor-Worker patterns343344### AgentRegistry - Distributed Coordination345346For 100+ agent distributed systems:347348- O(1) capability-based discovery with semantic matching349- Event broadcasting (6 event types for cross-runtime coordination)350- Health monitoring with automatic deregistration351- Status management (ACTIVE, UNHEALTHY, DEGRADED, OFFLINE)352- Multi-runtime coordination across processes/machines353354## When to Use This Skill355356Use Kaizen when you need to:357358- Build AI agents with type-safe interfaces359- Implement multi-agent systems with orchestration patterns360- Process multimodal inputs (vision, audio, text)361- Create RAG (Retrieval-Augmented Generation) systems362- Implement chain-of-thought reasoning363- Build supervisor-worker or ensemble architectures364- Track costs and performance of AI agents365- Add zero-code-change observability to agents366- Monitor, trace, and audit agent behavior in production367- Secure agent observability with RBAC and compliance controls368- Create production-ready agentic applications369- **Enterprise trust and accountability (v0.8.0)**:370 - Cryptographic trust chains for AI agents371 - Cross-organization agent coordination372 - Regulatory compliance with audit trails373 - Secure inter-agent communication374- **Agent manifest, deploy, and composition (v1.3)**:375 - Declare agents with TOML manifests and governance metadata376 - Deploy agents to local FileRegistry or remote CARE Platform377 - Validate composite agent DAGs for cycles378 - Check schema compatibility between connected agents379 - Estimate pipeline costs from historical data380 - Discover/deploy agents via MCP Catalog Server381 - Link budget thresholds to automatic posture transitions382- **L3 Autonomy Primitives**:383 - Agent spawning with PACT-governed lifecycle tracking384 - Continuous budget tracking with gradient zones and non-bypassable enforcement385 - Hierarchical scoped context with projection-based access control386 - Typed inter-agent messaging with 8-step routing validation387 - Dynamic task graph execution with gradient-driven failure handling388389**Use Pipeline Patterns When:**390391- **Ensemble**: Need diverse perspectives synthesized (code review, research)392- **Blackboard**: Iterative problem-solving (optimization, debugging)393- **Router**: Intelligent task delegation to specialists394- **Parallel**: Bulk processing or voting-based consensus395- **Sequential**: Linear workflows with dependency chains396397## Integration Patterns398399### With DataFlow (Data-Driven Agents)400401```python402from kaizen.core.base_agent import BaseAgent403from dataflow import DataFlow404405class DataAgent(BaseAgent):406 def __init__(self, config, db: DataFlow):407 self.db = db408 super().__init__(config=config, signature=MySignature())409```410411### With Nexus (Multi-Channel Agents)412413```python414from kaizen.core.base_agent import BaseAgent415from nexus import Nexus416417# Deploy agents via API/CLI/MCP418agent_workflow = create_agent_workflow()419app = Nexus()420app.register("agent", agent_workflow.build())421app.start() # Agents available via all channels422```423424### With Core SDK (Custom Workflows)425426```python427from kaizen.core.base_agent import BaseAgent428from kailash.workflow.builder import WorkflowBuilder429430# Embed agents in workflows431workflow = WorkflowBuilder()432workflow.add_node("KaizenAgent", "agent1", {433 "agent": my_agent,434 "input": "..."435})436```437438## Provider Configuration (v2.5.0 -- Explicit over Implicit)439440As of v2.5.0, provider configuration follows an **explicit over implicit** model. Structured output config is separated from provider-specific settings.441442### BaseAgentConfig Fields443444| Field | Purpose | Example |445| ------------------------ | ---------------------------------------------------------------------- | -------------------------------------------- |446| `response_format` | Structured output config (json_schema, json_object) | `{"type": "json_schema", "json_schema": {}}` |447| `provider_config` | Provider-specific operational settings only | `{"api_version": "2024-10-21"}` |448| `structured_output_mode` | Controls auto-generation: `"auto"` (deprecated), `"explicit"`, `"off"` | `"explicit"` |449450### Quick Pattern451452```python453from kaizen.core.config import BaseAgentConfig454from kaizen.core.structured_output import create_structured_output_config455456# Explicit mode (recommended)457config = BaseAgentConfig(458 llm_provider="openai",459 model=os.environ["LLM_MODEL"],460 response_format=create_structured_output_config(MySignature(), strict=True),461 structured_output_mode="explicit",462)463464# Azure with provider-specific settings (separate from response_format)465config = BaseAgentConfig(466 llm_provider="azure",467 model=os.environ["LLM_MODEL"],468 response_format={"type": "json_object"},469 provider_config={"api_version": "2024-10-21"},470 structured_output_mode="explicit",471)472```473474### Azure Env Vars (Canonical Names)475476| Canonical | Legacy (deprecated) |477| ------------------- | ------------------------------------------------------ |478| `AZURE_ENDPOINT` | `AZURE_OPENAI_ENDPOINT`, `AZURE_AI_INFERENCE_ENDPOINT` |479| `AZURE_API_KEY` | `AZURE_OPENAI_API_KEY`, `AZURE_AI_INFERENCE_API_KEY` |480| `AZURE_API_VERSION` | `AZURE_OPENAI_API_VERSION` |481482Legacy vars emit `DeprecationWarning`. Use `resolve_azure_env()` from `kaizen.nodes.ai.azure_detection` for canonical-first resolution.483484### Anti-Patterns485486- **Never** put structured output config in `provider_config` -- use `response_format`487- **Never** rely on auto-generated structured output without understanding it -- set `structured_output_mode="explicit"`488- **Never** use multiple env var names for the same Azure setting without deprecation489- **Never** use error-based backend switching -- detect the backend upfront or set `AZURE_BACKEND` explicitly490491### Prompt Utilities492493`kaizen.core.prompt_utils` is the single source of truth for signature-based prompt generation:494495- `generate_prompt_from_signature(signature)` -- builds system prompt from signature fields496- `json_prompt_suffix(output_fields)` -- returns JSON format instructions for Azure `json_object` compatibility497498For detailed configuration patterns, see:499500- **[kaizen-config-patterns](kaizen-config-patterns.md)** -- Domain configs, auto-extraction, provider-specific patterns501- **[kaizen-structured-outputs](kaizen-structured-outputs.md)** -- Full structured output guide with migration examples502503## Critical Rules504505- Define signatures before implementing agents506- Extend BaseAgent for production agents507- Use type hints in signatures for validation508- Track costs in production environments509- Test agents with real infrastructure (real infrastructure recommended)510- Enable hooks for observability511- Use AgentRegistry for distributed coordination512- Use `response_format` for structured output (not `provider_config`)513- Set `structured_output_mode="explicit"` for new agents514- NEVER skip signature definitions515- NEVER ignore cost tracking in production516- NEVER put structured output keys in `provider_config`517- Avoid mocking LLM calls in integration tests (real infrastructure recommended)518519### Kaizen-Agents Governance (v0.1.0)520521- **[kaizen-agents-governance](kaizen-agents-governance.md)** -- GovernedSupervisor, progressive disclosure (Layer 1/2/3), 7 governance modules522 - `GovernedSupervisor` with 3-layer progressive API (2-param simple -> 8-param configured -> 9 governance subsystems)523 - `AccountabilityTracker` -- D/T/R addressing, policy source chain524 - `BudgetTracker` -- reclamation, predictive warnings, reallocation525 - `CascadeManager` -- monotonic envelope tightening, BFS termination526 - `ClearanceEnforcer` + `ClassificationAssigner` -- data classification (C0-C4), regex pre-filter527 - `DerelictionDetector` -- insufficient tightening detection528 - `BypassManager` -- time-limited emergency overrides with anti-stacking529 - `VacancyManager` -- orphan detection, grandparent auto-designation530 - `AuditTrail` -- EATP hash chain with `hmac.compare_digest()`531 - SDK integration: `EnvelopeAllocator` -> `EnvelopeSplitter`, `ScopeBridge` -> `ScopedContext`532533### L3 Integration & Event System534535- **[kaizen-l3-overview](kaizen-l3-overview.md)** -- L3 autonomy primitives, L3Runtime integration, EATP event system536 - `L3Runtime` convenience class wiring all 5 subsystems (Factory->Enforcer, Factory->Router, Factory->Context, Enforcer->Plan)537 - `L3EventBus` pub/sub for 15 governance event types across all primitives538 - `EatpTranslator` converts L3 events into EATP audit records with severity classification539540- **[kaizen-agents-security](kaizen-agents-security.md)** -- Security patterns for governance541 - Anti-self-modification via `_ReadOnlyView` proxies542 - Pervasive NaN/Inf defense (`math.isfinite()` on all numeric paths)543 - Bounded collections, monotonic invariants, thread safety544 - Delegate tool security (mandatory BashTool gate, ExecPolicy, session sanitization)545546### Wrapper Composition System547548Composition wrappers add cross-cutting concerns (governance, monitoring, streaming) around a `BaseAgent` without modifying it. `WrapperBase` enforces a canonical stacking order and duplicate detection.549550**Canonical stacking order** (innermost to outermost):551552```553BaseAgent -> L3GovernedAgent -> MonitoredAgent -> StreamingAgent554```555556`WrapperBase` rejects duplicate wrappers (`DuplicateWrapperError`) and out-of-order stacking (`WrapperOrderError`). Every wrapper proxies `get_parameters()` and `to_workflow()` to the inner agent. The `innermost` property walks the full stack to the non-wrapper agent.557558**Key files:**559560- `packages/kaizen-agents/src/kaizen_agents/wrapper_base.py` -- `WrapperBase` with stack ordering + duplicate detection561- `packages/kaizen-agents/src/kaizen_agents/governed_agent.py` -- `L3GovernedAgent` with `ConstraintEnvelope` enforcement (Financial, Operational, Temporal, Data Access, Communication, Posture ceiling). Rejects BEFORE LLM cost is incurred. Uses `_ProtectedInnerProxy` to block governance bypass via `.inner._inner`.562- `packages/kaizen-agents/src/kaizen_agents/monitored_agent.py` -- `MonitoredAgent` with `CostTracker`, budget enforcement via `BudgetExhaustedError`, NaN/Inf defense on budget values563- `packages/kaizen-agents/src/kaizen_agents/streaming_agent.py` -- `StreamingAgent` with `run_stream()` async iterator, typed `StreamEvent` events, buffer overflow protection, timeout enforcement. Falls back to batch when provider lacks `StreamingProvider`.564- `packages/kaizen-agents/src/kaizen_agents/events.py` -- Frozen dataclass events: `TextDelta`, `ToolCallStart`, `ToolCallEnd`, `TurnComplete`, `BudgetExhausted`, `ErrorEvent`, `StreamBufferOverflow`565- `packages/kaizen-agents/src/kaizen_agents/supervisor_wrapper.py` -- `SupervisorWrapper` for task delegation to worker pool via `LLMBased` routing566567**Building a wrapper stack:**568569```python570from kaizen.core.base_agent import BaseAgent571from kaizen_agents.governed_agent import L3GovernedAgent572from kaizen_agents.monitored_agent import MonitoredAgent573from kaizen_agents.streaming_agent import StreamingAgent574from kaizen_agents.events import TextDelta, TurnComplete575from kailash.trust.envelope import ConstraintEnvelope, FinancialConstraint576577# Stack innermost to outermost578agent = MyAgent(config=config)579governed = L3GovernedAgent(agent, envelope=ConstraintEnvelope(580 financial=FinancialConstraint(budget_limit=10.0)581))582monitored = MonitoredAgent(governed, budget_usd=5.0)583streaming = StreamingAgent(monitored)584585# Stream typed events586async for event in streaming.run_stream(prompt="analyze this"):587 match event:588 case TextDelta(text=t): print(t, end="")589 case TurnComplete(text=t): print(f"\n[Done: {t[:50]}]")590```591592**SupervisorWrapper** -- delegates tasks to a worker pool using LLM-based routing:593594```python595from kaizen_agents.supervisor_wrapper import SupervisorWrapper596from kaizen_agents.patterns.llm_routing import LLMBased597598supervisor = SupervisorWrapper(inner_agent, workers=[w1, w2], routing=LLMBased())599result = await supervisor.run_async(task="complex task")600```601602### Provider Capability Protocols603604SPEC-02 defines `runtime_checkable` protocols in `kaizen.providers.base` for structural capability discovery. Providers satisfy protocols structurally -- no explicit inheritance needed.605606| Protocol | Key Method | Purpose |607| -------------------------- | ----------------------------------- | ------------------------------ |608| `StreamingProvider` | `stream_chat()` -> `StreamEvent` | Token-by-token streaming |609| `ToolCallingProvider` | `chat_with_tools(messages, tools)` | Native function calling |610| `StructuredOutputProvider` | `chat_structured(messages, schema)` | JSON schema structured outputs |611| `AsyncLLMProvider` | `chat_async(messages)` | Async chat completions |612613`ProviderCapability` enum: `CHAT_SYNC`, `CHAT_ASYNC`, `CHAT_STREAM`, `TOOLS`, `STRUCTURED_OUTPUT`, `EMBEDDINGS`, `VISION`, `AUDIO`, `REASONING_MODELS`, `BYOK`.614615Use `get_provider_for_model(model)` from `kaizen.providers.registry` to resolve a model string to a provider instance. Use `isinstance(provider, StreamingProvider)` for capability checks.616617### LLM-Based Routing618619`LLMBased` from `kaizen_agents.patterns.llm_routing` scores agent capabilities against task requirements using Kaizen signatures (not keyword matching or dispatch tables).620621```python622from kaizen_agents.patterns.llm_routing import LLMBased623624routing = LLMBased(config=config) # config optional; falls back to .env defaults625score = await routing.score("analyze revenue data", agent_capability)626best = await routing.select_best("analyze revenue data", [agent1, agent2, agent3])627```628629`score()` returns `[0.0, 1.0]`. Accepts `Capability` dataclasses (`.name` + `.description`) or plain strings. `select_best()` returns the highest-scoring candidate or `None` when empty.630631### Convergence Status (SPEC-02 / SPEC-05 / SPEC-10)632633Three convergence SPECs have shipped on the `feat/spec04-baseagent-slim` branch:634635**SPEC-02 (Provider Split)** -- The provider monolith (`kaizen.nodes.ai.ai_providers`) is now split into per-provider modules under `kaizen/providers/`. See **[kaizen-multi-provider](kaizen-multi-provider.md)** for the updated registry, protocols, and CostTracker.636637- `kaizen.providers.base` -- `ProviderCapability` enum (10 members), 5 runtime-checkable protocols638- `kaizen.providers.registry` -- `ProviderRegistry` with 14 provider entries and prefix-dispatch model detection639- `kaizen.providers.cost` -- `CostTracker` with thread-safe accumulation640- Backward-compat shim at `kaizen.nodes.ai.ai_providers` re-exports all public names641642**SPEC-05 (Delegate Facade)** -- Delegate is now a composition facade wrapping `AgentLoop -> [L3GovernedAgent] -> [MonitoredAgent]`. See **[kaizen-delegate](kaizen-delegate.md)** for the updated API surface.643644- `ConstructorIOError` -- raised on outbound IO in `__init__`645- `ToolRegistryCollisionError` -- raised on duplicate tool name registration646- `run_sync()` refuses under a running event loop with an actionable error message647- Deferred MCP: `mcp_servers=` stores configs, connects on first `run()`648- Introspection: `.core_agent`, `.signature`, `.model` read-only properties649650**SPEC-10 (Multi-Agent)** -- 11 deprecated agent subclasses (SupervisorAgent, WorkerAgent, CoordinatorAgent, PipelineStageAgent, etc.) now emit `DeprecationWarning`. Composition patterns accept plain `BaseAgent` instances. `max_total_delegations` cap (default 20) with `DelegationCapExceeded` exception.651652## Related Skills653654- **[01-core-sdk](../../01-core-sdk/SKILL.md)** - Core workflow patterns655- **[02-dataflow](../dataflow/SKILL.md)** - Database integration656- **[03-nexus](../nexus/SKILL.md)** - Multi-channel deployment657- **[05-kailash-mcp](../05-kailash-mcp/SKILL.md)** - MCP server integration658- **[17-gold-standards](../../17-gold-standards/SKILL.md)** - Best practices659660## Support661662For Kaizen-specific questions, invoke:663664- `kaizen-specialist` - Kaizen framework implementation665- `testing-specialist` - Agent testing strategies666- ``decide-framework` skill` - When to use Kaizen vs other frameworks667668---669> Converted and distributed by [TomeVault](https://tomevault.io/claim/integrum-global) — claim your Tome and manage your conversions.670<!-- tomevault:4.0:skill_md:2026-04-13 -->