KOR SDK Context & Architecture
You are working on the KOR SDK, an Enterprise Developer Platform built on a Vertical Architecture.
1. Core Philosophy: The "KOR Way"
- •Vertical Architecture: Code is organized by domain (
mcp,lsp,skills,plugin), not by technical layer (models, views). Each domain is self-contained. - •Consolidated Modules: We prefer single-file modules (e.g.,
events.py,search.py,commands.py) over scattered__init__.pyfiles when the complexity is low (< 5 files). - •Facade First: The public API is the
Korclass inkor_core.api. Always design for the user accessing functionality viakor = Kor(). - •Pythonic & Explicit: We use explicit typing, dataclasses, and standard Python patterns. We avoid "magic" where possible (e.g., rigid frameworks).
2. Directory Map (Deep Dive)
packages/kor-core/src/kor_core/:
Core Infrastructure
- •
api.py(The Facade): The ONLY intended public entry point.- •Rule: Never import
Kernelin user code. Usefrom kor_core import Kor.
- •Rule: Never import
- •
kernel.py(The Engine): Orchestrates lifecycle.- •Key: It is a Singleton. Access via
get_kernel()internally if needed, but prefer passing dependencies.
- •Key: It is a Singleton. Access via
- •
config.py: Pydantic-based configuration.- •Pattern: Start with
ConfigManager().load(). Supports~/.kor/config.toml.
- •Pattern: Start with
- •
events.py: Unified Event Bus and Telemetry.- •Key: Use
HookEventenum for lifecycle events. ContainsTelemetrySubscriberandLoggingTelemetrySink.
- •Key: Use
Vertical Domains
- •
mcp/: Model Context Protocol.- •Structure:
client.py(connects to servers),server.py(hosts resources).
- •Structure:
- •
lsp/: Language Server Protocol.- •Feature: Provides Code Intelligence (Hover, Definition) to Agents.
- •
skills.py: Skills System.- •Pattern:
SkillLoaderinheritsBaseLoader.SkillRegistryinheritsSearchableRegistry.
- •Pattern:
Plugin System
- •
plugin.py: Plugin System.- •Consolidated: Contains
manifest,loader,context. - •Workflow: Plugins are loaded by
kernel.pyat boot.
- •Consolidated: Contains
Utilities
- •
search.py: Unified Search Infrastructure.- •Provides:
Searchableprotocol,SearchableRegistry[T],RegexBackend,BM25Backend. - •Pattern: All registries (Tools, Skills, Commands, Agents) inherit from
SearchableRegistry.
- •Provides:
- •
commands.py: Slash Commands System.- •Pattern:
CommandLoaderinheritsBaseLoader.CommandRegistryextendsSearchableRegistry.
- •Pattern:
Agent System
- •
agent/: Multi-Agent Orchestration.- •
state.py:AgentState,PlanTaskTypedDicts. - •
planning.py:Plannerclass with file sync, events. - •
archiver.py:PlanArchiverfor long-term memory. - •
graph.py: LangGraph workflow builder. - •
nodes/: Worker nodes (Supervisor, Architect, Coder, etc.).
- •
2.5 Native Planning Architecture
The SDK includes a Plan-and-Execute system for autonomous agents:
- •Entry Flow:
AutoPlanner → EnsurePlan → Supervisor → Workers - •File Sync: Agent state syncs with
PLAN.md(GFM checklist). - •Events:
TASK_STARTED,TASK_COMPLETED,PLAN_FINISHED. - •Memory: Completed plans archived to
~/.kor/memory/plans.jsonl. - •Tool:
ManagePlanToolwith actions:add_task,add_subtask,update_status,finish_task.
3. Implementation Recipes
How to add a new Tool
- •Create Class: In
kor_core/tools/<category>.py(or generictools.py). - •Inherit: From
BaseTool(pydanticBaseModel). - •Register: In
kor_core.kernel.Kernel._register_core_tools(). - •Tag: Add tags/keywords for semantic search discovery.
How to Add a New LLM Provider
- •Do NOT create a new file: Modify
kor_core/llm/provider.py. - •Update
UnifiedProvider: Ensure_create_clienthandles the newbase_urlor signature. - •Config: Map it in
kor_core/config.pyunderLLMConfig.
How to Create a Declarative Plugin
- •Folder:
plugins/kor-plugin-<name>/. - •Manifest:
plugin.json(defines commands, tools). - •Scripts:
scripts/my_script.py(executable logic). - •No Init: Do NOT verify
__init__.pyfor declarative plugins.
4. Coding Standards & Best Practices
- •Typing: Strict
mypycompatibility. Usetyping.List,typing.Optional. - •Imports:
- •Vertical:
from . import models(relative within module). - •Horizontal:
from kor_core.other import thing(absolute across modules). - •Avoid circular imports: Use
if TYPE_CHECKING:for type-only dependencies.
- •Vertical:
- •Async/Sync:
- •The Kernel is primarily Async.
- •
boot_sync()is a wrapper for CLI convenience. - •Always
awaitI/O operations (LLM, File, Network).
- •Error Handling:
- •Use specific exceptions from
kor_core.exceptions. - •Never swallow exceptions silently in the Kernel.
- •Use specific exceptions from
5. Architecture Decision Records (ADR) - Simplified
- •ADR-001 Vertical Arch: We moved from Layered (loaders/, registries/) to Vertical (mcp/, lsp/) to localize complexity.
- •ADR-002 Facade: We hid the
Kernelcomplexity behindKorto make the library approachable for beginners. - •ADR-003 Resources: We moved prompts/markdown OUT of
src/toresources/to separate code from data. - •ADR-004 Single File Modules: We merged small folders into single
.pyfiles to reduce "tab fatigue". - •ADR-005 CLI Decoupling: The CLI (
chat) is Agent-Agnostic. It renders generic events (messages,next_step) rather than hardcoding agent names. - •ADR-006 Native Planning: Agents use file-backed
PLAN.mdfor transparent, human-editable planning.
Use this skill to simulate "Senior Engineer" context when editing the codebase.