The plugin runtime for Python AI agents.
Your model clients, tools, memory and connectors become plugins that
start when they're ready, restart when they fail, and clean up after themselves.
Quickstart · A real agent · Agent guide · Reference
pycordis is not another LLM framework. It sits underneath the one you
already use (the OpenAI or Anthropic SDK, PydanticAI, LangGraph…) and runs
everything around it. Think FastAPI's Depends, plus a process supervisor, for
long-running async apps.
pip install pycordis-framework # Python 3.12+, zero dependencies
The problem
Every real agent's main() ends up like this:
llm = AsyncAnthropic() # crashes if the key is missing
db = await VectorDB.connect(url) # must come before search_docs
tools = [search_docs(db)]
if SLACK_TOKEN: # optional tool, ad-hoc check
tools.append(slack_tool(SLACK_TOKEN))
memories: dict[str, Memory] = {} # global, shared by every user
try:
await serve(llm, tools, memories)
finally:
await db.close() # and the Slack client? the scheduler?
Startup order is maintained by hand. One flaky dependency kills the whole process. Per-user state is a global dict. And when a tool is missing, you get to ask "why didn't it load?"
With pycordis, each piece is a plugin that declares what it provides and what it needs. The runtime handles the order, the restarts, the isolation and the cleanup.
Concepts in 30 seconds
| Term | What it is |
|---|---|
| Plugin | A function (or class) that sets something up. Unloading it undoes everything it did. |
| Service | A value a plugin provides under a typed ServiceKey, like your LLM client. |
| inject | The services a plugin needs. It starts when they all exist, and stops if one goes away. |
| Scope | A child context, such as one per conversation, with its own services. Torn down on exit. |
| Collection | A registry, like your tools, that many plugins add to. Items leave with their plugin. |
Quickstart
import asyncio
from collections.abc import Callable
from pycordis import Context, ServiceKey, plugin_meta
DB = ServiceKey[dict[str, str]]("db")
@plugin_meta(name="search", inject=[DB]) # needs DB
def search(ctx: Context, config: None) -> Callable[[], None]:
print(f"search: online, {len(ctx.use(DB))} docs")
return lambda: print("search: offline") # cleanup, run on unload
@plugin_meta(name="db", provide=DB) # provides DB
async def db(ctx: Context, config: None) -> None:
await asyncio.sleep(0.1) # connecting...
ctx.provide(DB, {"intro": "hello"})
async def main() -> None:
async with Context() as app:
app.plugin(search) # registered first: it simply waits for DB
conn = await app.plugin(db)
await conn.dispose() # pull the DB out from under it
asyncio.run(main())
search: online, 1 docs
search: offline
search started the moment DB existed, and shut itself down the moment it
went away. No ordering in main(), no try/finally, no globals.
A real agent
A model client with a restart policy, a tool registry you can change while it runs, and private memory per user:
import asyncio
from collections.abc import Callable
from pycordis import Collection, Context, RestartPolicy, ServiceKey
from pycordis import current_context, plugin_meta
class Model: # stand-in: use AsyncOpenAI, AsyncAnthropic, Ollama...
async def reply(self, text: str, tools: list[str]) -> str:
return f"echo {text!r} · tools: {tools}"
LLM = ServiceKey[Model]("llm")
TOOLS = ServiceKey[Collection[Callable[[str], str]]]("tools")
MEMORY = ServiceKey[list[str]]("memory")
@plugin_meta(name="llm", provide=LLM, policy=RestartPolicy(mode="on-failure"))
async def llm(ctx: Context, config: None) -> None:
ctx.provide(LLM, Model()) # if this raises, pycordis retries with backoff
@plugin_meta(name="web-search", inject=[TOOLS])
def web_search(ctx: Context, config: None) -> None:
ctx.use(TOOLS).add(lambda query: f"results for {query}", name="web_search")
async def turn(text: str) -> str:
chat = current_context() # the conversation this turn belongs to
chat.use(MEMORY).append(text)
tools = [name for name, _ in chat.use(TOOLS).items()]
return await chat.use(LLM).reply(text, tools)
async def main() -> None:
async with Context() as app:
await app.plugin(Collection.of(TOOLS))
app.plugin(llm) # no await: it starts in the background
search = await app.plugin(web_search) # await: wait until it runs
chat = app.scope(name="alice", inject=[LLM, TOOLS], provide=[MEMORY])
async with chat as alice:
alice.provide(MEMORY, []) # alice's own memory
print(await alice.spawn(turn("hi"))) # spawn = run inside alice's scope
await search.dispose() # unplug a tool, live
print(await alice.spawn(turn("still there?")))
print("memory:", alice.use(MEMORY))
asyncio.run(main())
echo 'hi' · tools: ['web_search']
echo 'still there?' · tools: []
memory: ['hi', 'still there?']
The tool vanished when its plugin unloaded, and nobody cleaned anything up. The agent guide builds the full version: a flaky LLM that recovers, two users, health checks and diagnostics.
Why pycordis
- 🔌 Start in any order. A plugin runs as soon as what it needs exists.
- ♻️ Self-healing. Failing plugins restart with backoff, dependents wait instead of crashing, and
load_timeoutcatches hangs. - 💬 Per-user isolation.
app.scope()gives each conversation its own services, torn down even after an error. - 🧰 Live tool registries. With
Collection[T], tools appear and disappear with their plugin. - 🩺 "Why isn't it running?"
pycordis doctornames the missing service, the failed plugin or the dependency cycle. - ⚙️ Config files with hot reload. TOML or JSON (YAML with PyYAML),
${env:KEY}secrets, dev/prod profiles. - 📈 Ops built in.
/healthz,/readyzand/inspectendpoints, lifecycle telemetry, JSON logs. - 🎯 Typed, zero dependencies.
ctx.use(LLM)is aModelto your type checker. Pure standard library, nothing extra in your supply chain.
Run it from a config file
Plugins take typed config:
# my_agent.py
from dataclasses import dataclass
from anthropic import AsyncAnthropic
from pycordis import Context, ServiceKey, plugin_meta
LLM = ServiceKey[AsyncAnthropic]("llm")
@dataclass
class LLMConfig:
api_key: str
@plugin_meta(name="llm", provide=LLM, Config=LLMConfig)
def llm(ctx: Context, config: LLMConfig) -> None:
ctx.provide(LLM, AsyncAnthropic(api_key=config.api_key))
# needs a "slack_client" service that nothing provides yet: see `pycordis doctor` below
@plugin_meta(name="slack", inject=["slack_client"])
def slack(ctx: Context, config: None) -> None: ...
The config file decides what runs:
# agent.toml
[loader]
watch = true # edit while it runs: only what changed reloads
[[plugins]]
id = "llm"
use = "my_agent:llm"
config = { api_key = "${env:ANTHROPIC_API_KEY}" } # checked against LLMConfig
restart = { mode = "on-failure", max_restarts = 5 } # self-healing
[[plugins]]
id = "slack"
use = "my_agent:slack"
disabled = false # true: kept in the file, not running
Start it, with health endpoints for your orchestrator:
pycordis start -c agent.toml --health-port 8080 # GET /healthz /readyz /inspect
# in a container, add --health-host 0.0.0.0 so the orchestrator's probes reach it
If something doesn't start, ask why:
$ pycordis doctor -c agent.toml
root #0 ACTIVE
└─ slack #2 [entry slack] PENDING
missing-service: no plugin declares or currently provides "slack_client"
How it compares
| pycordis | hand-written main() |
FastAPI lifespan + Depends |
|
|---|---|---|---|
| Start order from dependencies | ✅ | by hand | by hand |
| Restart a failed part while the rest keeps running | ✅ | ❌ | ❌ |
| Add or remove parts while running | ✅ | ❌ | ❌ |
| Per-conversation state with cleanup | ✅ | by hand | per request |
| Explains why something didn't start | ✅ | ❌ | ❌ |
pycordis works with agent frameworks, not against them: it owns the lifecycles, and your framework owns the reasoning.
FAQ
Does it replace LangChain, LangGraph or PydanticAI? No. Use them inside plugins. pycordis manages their clients, tools and lifetimes.
Do I need the config file or the CLI? No. Everything works from plain
Python. The loader and pycordis command are optional.
Is it production-ready? It's 0.1 (beta): strictly typed, 1,250+ tests and 98% coverage, but the API may still change before 1.0.
What's cordis? The TypeScript plugin framework behind Koishi. pycordis is a faithful asyncio port of cordis 4.1.0, with the same lifecycle, events and error messages. You don't need to know it. If you do, the mapping table lists every API side by side.
Learn more
- 🤖 Build an agent: an LLM agent end to end.
- 📖 Reference: every feature in depth.
- 🔁 cordis → pycordis: the API mapping.
- 📝 Changelog · 🔐 Security
License
MIT. pycordis is a port of cordis (MIT, © 2021-present Shigma).
Metadata
Release files for pycordis-framework 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pycordis_framework-0.1.1.tar.gz | 330.0 kB | With provenance | Details for pycordis_framework-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pycordis_framework-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pycordis_framework-0.1.1-py3-none-any.whl |
Total release size: 534.3 kB
Release files / pycordis_framework-0.1.1.tar.gz
| Download URL | pycordis_framework-0.1.1.tar.gz |
|---|---|
| Size | 330.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
38e9120a25335b1f123226fda3c94310f36e6200fe632f36fc1a19d213ef6fef
|
|
BLAKE2b-256 checksum How to use checksums |
2bc4a3947c65dbff9f1f2d30513c3b9a8a0107a799348c208ef34178304f2dc7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logRelease files / pycordis_framework-0.1.1-py3-none-any.whl
| Download URL | pycordis_framework-0.1.1-py3-none-any.whl |
|---|---|
| Size | 204.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7d1126861d4e20ed92dad73d70a0fd5c72292301b98f89e066ed8ded9c0fa441
|
|
BLAKE2b-256 checksum How to use checksums |
fb3317d3c154555a93f10bf3496f0870e7e86c784a0a3ad1868379ee07c198bd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logSecurity for pycordis-framework 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pycordis_framework-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 10, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.