python-cordis
A plugin-driven framework kernel for Python, inspired by the cordis framework: everything is a plugin.
This project delivers the "engine" — how to organize an application as plugins —
not the agent/product logic on top of it. See
docs/python-cordis-feature-spec.md for the full feature specification
(status: 0.1 draft).
Status: P0 MVP (F1/F2/F3/F4/F5/F7/F9) done and green. P1 complete:
SandboxFS (F5.3), the LLM seam (F6), and HMR hot reload (F8) are implemented
and tested. P2 complete: structured lifecycle logging (F10.1), strict mypy
(F10.2), README architecture docs (F11.1), and packaging with a real
entry-point example plugin (F11.2). P3 complete: the agent main loop (F12),
event-sourced session log (F13), persistence backends (F14), and session
query (F15) are implemented and tested. F16 (transport/frontend) is implemented
as a reference iteration: four-quadrant RPC messages, HTTP up-link + WebSocket
down-link, a reversible transport plugin, and a minimal browser frontend
(install with pip install -e ".[web]", run python examples/demo_web.py).
Quick start
pip install -e .
pytest
python examples/demo.py
The demo builds a plugin tree with the filesystem seam + approval middleware, runs a "write → read → vetoed write → list" flow, and (new in P2) shows structured lifecycle logging and the auto-discovered entry-point plugin.
The web demo (python examples/demo_web.py) starts the transport plugin: an
HTTP up-link (/api/<method>) plus a WebSocket down-link (/ws), and serves a
minimal browser frontend at http://127.0.0.1:8765/ — send a message and watch
the agent's event stream render in real time.
Architecture
flowchart TD
subgraph Apps["应用层"]
Demo["examples/demo.py"]
end
subgraph Core["内核 core(无关插件)"]
Hooks["HookRegistry<br/>pluggy 四种调用模式"]
Ctx["Context 服务容器<br/>__getattr__ 反射 / 作用域链"]
Fiber["Fiber 生命周期<br/>start/stop + effect 逆序回滚"]
Config["配置装配<br/>OmegaConf overlay / dump / 插值"]
end
subgraph Seams["能力缝 seams(接口 + Provider + Consumer)"]
FS["FileSystem<br/>LocalFS / SandboxFS / tool-fs"]
LLM["LlmAdapter<br/>MockProvider / LlmStream"]
Pipe["工具流水线<br/>pre → execute → post"]
end
subgraph Enhance["增强(可选插件)"]
HMR["HMR 热重载<br/>Reloader / PluginReloader / FileWatcher"]
Obs["LifecycleLogger<br/>结构化日志(observability)"]
end
Demo --> Config
Demo --> Fiber --> Ctx
Demo --> Hooks
Hooks --> Seams
Ctx --> Seams
Seams --> Pipe
Fiber --> HMR
Fiber --> Obs
Key ideas:
- Hooks are the seams between kernel and plugins — the kernel declares what
can be extended (
@hookspec), plugins provide it (@hookimpl). Nothing in the kernel hard-codes a specific plugin. Fiberemits, plugins observe — the kernel only emits lifecycle events; logging is a plain, reversible plugin (LifecycleLogger).- Everything is replaceable — providers implement stable interfaces
(
FileSystem,LlmAdapter), so swappingLocalFS → SandboxFSneeds zero consumer changes.
Core concepts
HookRegistry: plugin registration/discovery and four hook invocation modes (emit/parallel/bail/waterfall) built onpluggy.Context: a reflective service container (ctx.fsresolves to a registered service), withextend()/isolate()scopes and reversibleregister().Fiber: plugin instance lifecycle —start()/stop()with effects torn down in reverse registration order. When constructed with aHookRegistrythat has the lifecycle specs registered, it emitsfiber_started/fiber_stopped.- Config assembly (
python_cordis.core.config): OmegaConf-based loading, overlay patching, dumping, and interpolation (no arbitrary code execution). - Capability seams (
python_cordis.seams): interface + provider + consumer triads (e.g.FileSystem/LocalFS/SandboxFS/tool-fs), plus the tool execution pipeline withpre→execute→postwaterfalls. - LLM seam (
python_cordis.seams.llm):LlmAdapterinterface with a normalizedstart/text/usage/finish/failureevent protocol, a deterministic offlineMockProvider, andLlmStreamthat routes requests/events throughllm_request/llm_eventwaterfalls. Adapter exceptions are normalized into a singlefailureevent, never leaked as a bare exception. - HMR (
python_cordis.core.hmr): hot module reload without restarting.Reloaderswaps a unit ("stop old, then start new") and rolls back on any failure, keeping the old version alive and recording the reason inerrors;PluginReloaderre-executes an already-imported plugin module in place (viapython_cordis.core.hmr's cache-bypassing source reload) and re-registers its hooks;FileWatcher(optionalwatchdog) fireson_changeon any watched file so a config or plugin edit takes effect live. - Structured logging (
python_cordis.observability):setup_lifecycle_loggingregisters the lifecycle hookspecs plus aLifecycleLoggerplugin that writes structured records (event,fiber) via the standardloggingmodule. It returns a disposer, so the observability is fully reversible. - Entry-point plugins (
python_cordis.contrib.demo_plugin): a real example plugin registered under thepython_cordis.pluginsgroup; afterpip install -e .,load_entry_points()auto-discovers it. - Transport (
python_cordis.contrib.web_server, optional[web]extra): four-quadrant RPC messages (client-request/server-response/server-request/client-response) correlated byrpc_id; anRpcRegistrythat statically distinguishes CALL / PUSH / ASK; an HTTP up-link on the standard library plus a WebSocket down-link on its own event-loop thread, bridged by a thread-safeEventBus; all wrapped in a reversibleWebServerPlugin(entry pointweb-server). A reference browser client lives inpython_cordis.contrib.web_frontend.
Development
pip install -e ".[dev,hmr]"
python -m mypy # strict type checking (F10.2)
python -m pytest # test suite
python -m build # sdist + wheel (F11.2)
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_cordis-0.1.0.tar.gz.
File metadata
- Download URL: python_cordis-0.1.0.tar.gz
- Upload date:
- Size: 71.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0b53c71c0068cb008c075ccb3b2bd92953bea7dfb0ee77fcda22721f31fd63ab
|
|
| MD5 |
feac0188173898617fa39c0e5076b488
|
|
| BLAKE2b-256 |
c643621b74e78827f4734e18665a29c765ba5681a2bd002f5f10768a645be91e
|
File details
Details for the file python_cordis-0.1.0-py3-none-any.whl.
File metadata
- Download URL: python_cordis-0.1.0-py3-none-any.whl
- Upload date:
- Size: 61.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
265188990526e72e2c21b7c657358a275125358dcb56a1b367e78b0e9e7fd99e
|
|
| MD5 |
a0082d7077d199fb72a30dda6e37a79f
|
|
| BLAKE2b-256 |
a609c2eab5d8f3e4dfd11c56e9f744ad413baa89e88108514178e919c44bc04b
|