Developer-Focused DocumentationThis page contains technical implementation details for building custom runtimes. For user-facing runtime selection and configuration, see the Runtime Comparison page.
Why Build a Custom Runtime?
Custom runtimes enable you to:- Integrate specialized frameworks: Use LangChain chains, CrewAI crews, AutoGen agents, or any Python AI framework
- Implement custom orchestration: Build complex multi-agent systems or specialized workflow patterns
- Optimize for specific use cases: Create runtimes tailored to your organization’s needs
- Leverage existing tooling: Integrate with internal tools, APIs, and infrastructure
- Control execution logic: Full control over model interactions, tool calling, and conversation management
- Multi-agent collaboration systems (CrewAI, AutoGen)
- Specialized RAG implementations (LangChain with custom retrieval)
- Domain-specific orchestration (healthcare, finance, legal)
- Integration with proprietary AI systems
- Custom prompt engineering and model routing
Runtime Architecture
All runtimes in Kubiya inherit from theBaseRuntime abstract class and register via the RuntimeRegistry:
Key components:
| Component | Purpose |
|---|---|
| BaseRuntime | Abstract base class defining the runtime interface |
| RuntimeRegistry | Decorator-based registration system |
| RuntimeExecutionContext | Input context with agent config, prompt, skills, etc. |
| RuntimeExecutionResult | Standardized output with response, usage, metadata |
| RuntimeCapabilities | Feature flags (streaming, tools, MCP, etc.) |
| RuntimeType | Enum for runtime identification |
Building a Custom Runtime
Understand the Base Class
Review the What the base class provides for free:
BaseRuntime interface in /control_plane_api/worker/runtimes/base.pyKey abstract methods you must implement:- Lifecycle management (
execute()andstream_execute()orchestration) - Automatic hook calling (
before_execute,after_execute,on_error) - Control Plane integration (metadata caching)
- Cancellation registration
- Configuration validation
- Error handling framework
Implement Tool Integration
Tools are the capabilities your agent can use (Skills, MCP servers, custom functions).Option 1: Convert Kubiya Skills to your framework’s tool formatOption 2: Native MCP Server integrationOption 3: Hybrid approach
Register Your Runtime
Use the Runtime discovery:
@RuntimeRegistry.register() decorator to make your runtime discoverable:Real-World Examples
Example 1: LangChain Runtime
Key implementation patterns for LangChain integration:- Convert Kubiya Skills to LangChain
StructuredToolformat - Use LangChain’s
AgentExecutorfor tool orchestration - Leverage LangChain callbacks for streaming
- Map conversation history to LangChain message format
Example 2: CrewAI Runtime
Key implementation patterns for multi-agent CrewAI:- Define multiple specialized agents with roles
- Use CrewAI’s
Processfor orchestration (sequential, hierarchical) - Agents collaborate on tasks automatically
- Note: CrewAI doesn’t provide token usage metrics
Configuration Schema
Define runtime-specific configuration viaruntime_config in agent configuration:
Best Practices
Standardize usage metrics
Standardize usage metrics
Always populate If your framework doesn’t expose usage, estimate or use callbacks.
usage in RuntimeExecutionResult for analytics:Implement proper error handling
Implement proper error handling
Use lifecycle hooks for graceful degradation:
Support conversation history
Support conversation history
Convert Kubiya conversation history to your framework’s format:
Leverage Control Plane integration
Leverage Control Plane integration
Use the Control Plane client for metadata, caching, and state:
Document your runtime
Document your runtime
Provide comprehensive documentation for users:
Test thoroughly
Test thoroughly
Write comprehensive tests:
API Reference
BaseRuntime Class
Abstract base class for all runtimesRuntimeExecutionContext
Input context passed to runtime:RuntimeExecutionResult
Output structure from runtime:RuntimeCapabilities
Runtime capability flags:RuntimeRegistry
Runtime registration and discovery:Deployment
Steps to deploy your custom runtime:- Implement your runtime class following this guide
- Add to RuntimeType enum in
base.py(if adding new type) - Register with decorator:
@RuntimeRegistry.register(RuntimeType.YOUR_RUNTIME) - Write tests (unit + integration)
- Document your runtime (README.md in runtime directory)
- Update agent configuration to use your runtime:
- Monitor execution via Kubiya dashboard and logs
Next Steps
Agno Runtime Source
Reference implementation of Agno runtime
Claude Code Runtime Source
Reference implementation of Claude Code runtime
Skills Documentation
Learn about Skills (tools) integration
Control Plane API
Control Plane integration and runtime registry