katsoft-llm-kit
LLM access, durable agent jobs and batch content pipelines in one library.
The import package is llm_kit; the console script is llm-kit.
pip install katsoft-llm-kit
pip install "katsoft-llm-kit[sdk,jobs,config]"
llm-kit --help
The library needs no AI harness, Claude Code, bootstrap or plugins-kit to
install and use.
The base install depends on katsoft-contracts (execution-event envelope,
interrupt contract, model declaration parser) and nothing else. Extras:
config, jobs and pipeline bring PyYAML; sdk brings the OpenAI client
(the OpenAI-compatible HTTP path, which serves OpenRouter and any other compatible endpoint); local brings psutil; frontdoor brings
FastAPI, uvicorn and httpx.
Supervised local jobs
llm_kit.jobs.supervisor adds opt-in local process ownership in version 1.6.
It requires the local extra. The existing job ledger and CLI remain unchanged.
The public functions are start, inspect, adopt and cancel.
JobProcessSpec declares the command, working directory, deadline and optional ledger cancellation command.
start returns a ProcessHandle after the durable dispatch handshake.
Handles and status records have JSON-compatible to_dict() methods.
ProcessHandle.from_dict() restores a saved handle.
Managers can restart while a detached supervisor retains its job.
adopt inspects a live supervisor or stops a vanished supervisor's remaining processes.
Cancellation stops the owned tree before the ledger cancellation command runs.
Survivors and failed ledger cancellation retain the resource lease and report indeterminate.
Use one shared lease_path for all supervised commands that write the same ledger.
Ordinary jobs commands do not participate in this opt-in lease.
Keep run directories private and machine-local. They contain command arguments and explicit environment overrides.
The supervisor does not supply harness permissions, task policy or acceptance evidence.
POSIX ownership covers recorded descendants and the command's session.
A descendant that starts a separate session and reparents before observation can escape that boundary.
Windows uses a kill-on-close Job Object and refuses dispatch if assignment fails.
These are process lifecycle controls, not a security sandbox.
Codex execution controls
Job options.extras and BackendOptions.extras accept native_subagents: "deny".
The Codex backend emits agents.enabled=false, features.multi_agent=false and features.multi_agent_v2=false.
Other non-null values refuse before dispatch.
With sandbox: "workspace-write", network: false emits an explicit sandbox_workspace_write.network_access=false override.
This override prevents a user configuration from silently enabling workspace network access.
add_dirs, scratch_dir and network: true widen the sandbox, so they are the calling code's to set.
The tracked project model file may not carry them in a row's or a profile's extras (it is refused at validation); network: false is allowed there. output_schema and __llm_kit_ names are refused there too.
Capabilities report these emitted controls. Callers still need version-specific harness evidence for their permission policy.
Scoped job denials
From version 1.7.1, a Claude job can deny Agent,Task without disabling its ordinary tools.
This source expands canonical subagent-spawn denial to name Workflow and SendMessage.
Claude Code 2.1.310 exposes workflow agent creation and stopped-agent resumption through these tools.
Scheduling tools such as CronCreate and ScheduleWakeup are separate caller policy; they are not child-agent aliases.
Broad write or shell denial requirements still select text-only mode.
A scoped rule such as Bash(git push --force*) keeps its original argument filter.
Scoped rules and unknown tool names require a literal disallowed-tools control and matching response provenance.
Adapters without that control are refused before dispatch.
Filters must have balanced parentheses. Separators apply only outside filters.
Mixed floors retain their whole-tool guarantees: Write,Bash(git push *) still requires filesystem-write denial.
The existing OpenCode permission mapping is unchanged.
These records describe emitted controls; verify the actual harness behavior for your policy.
Claude tool modes
BackendOptions.allowed_tools selects the tools of a ClaudeCliBackend call.
With None or "", the call has no tools. The argv carries --tools "", no MCP servers, no skills, no settings or CLAUDE.md, and --permission-mode dontAsk.
With tool names or rules, such as "Read,Grep,Glob", --tools names only those tools.
The child has exactly the named built-in tools; the other built-in tools are absent.
--allowedTools pre-approves every clause except a bare Read, Grep or Glob.
The same isolation follows, and dontAsk denies a call that would otherwise prompt.
So a bare Read reads only inside the working directory (measured), and the permissions reference says the same of Grep and Glob (not measured).
A scoped rule such as Read(/data/**) is pre-approved with exactly the scope written.
A grant that names default, an MCP tool (mcp__...) or anything other than a built-in tool name is refused before dispatch.
With ALL_TOOLS ("*", from llm_kit.completion.types), the call is an agent worker.
The argv carries --permission-mode bypassPermissions --allowedTools "": every built-in tool, with no permission check.
disallowed_tools still applies in every mode.
A completion job on Claude that names no allowed_tools runs as an ALL_TOOLS worker, unless a deny floor arms text-only mode.
Agent-loop review lanes grant Read,Grep,Glob, so their file reads stay inside the project root, their working directory.
Measured by the gated live suite (tests/llm-kit/live, run with LLM_KIT_LIVE_CLAUDE=1) on Claude Code 2.1.328 (2026-11-19): the no-grant child starts with no tools.
With --tools Read,Grep,Glob and no --allowedTools, Read and Grep work in the working directory; the child calls Read on an absolute path outside it, on a ../ path and through a link out of it, and Grep and Glob on a sibling directory, and each call is refused; the grant exposes no write or shell tool.
With a bare --allowedTools Read,Grep,Glob, an outside read succeeded (Claude Code 2.1.327).
Not measured: pre-approved Bash or write tools.
An agent session (ClaudeAgentSession) always runs with --permission-mode bypassPermissions.
Its grant is --tools <names> ("": no built-in tool), never --allowedTools, which restricts nothing under the bypass.
A scoped rule, default, an MCP tool name, and Agent, Task or Skill (a subagent or a skill may use tools outside the grant) are refused before the spawn.
A grant removes built-in tools only: the session still loads every settings source and the plugins' skills and MCP servers.
That --tools restricts under the bypass rests on the CLI reference only: no test runs the CLI with that argv.
Runtime mode
llm_kit._runtime.mode() reports how the library is deployed. This
distribution is "package": the contracts come from katsoft-contracts.
llm_kit._runtime.fleet() reports whether bootstrap_lib, the plugin
marketplace's shared library, imports in the same environment. With it, the
features that need it (claudx propagation, skill context,
the code-review lane) work and the model registry reads the layered config.
Without it, features that require the shared library raise
UnsupportedInPackageMode, Codex reachability uses a PATH check, and the model
registry reads the shipped defaults; point MODEL_ENDPOINTS_REGISTRY at a
registry file to change them. The Codex adapter itself works in package mode
and does not require Claude Code, bootstrap or plugins-kit.
Development source trees also use package contract routing.
Their marker has MODE = "source" and carries no release identity.
Release wheels have MODE = "package" with a verified version, commit, and tag.
_runtime.mode() returns "package" for both standalone forms.
A source tree beside installed katsoft-llm-kit metadata is refused as ambiguous.
Do not install this distribution into an environment that also holds a
path-linked copy of the llm_kit source tree.
CLI executables
The library starts the Claude and Codex command-line tools by name from PATH. Two environment
variables name a different build, each either a bare command name (looked up on PATH) or an
absolute path to an executable file:
LLM_KIT_CLAUDE_EXECUTABLE replaces claude.
LLM_KIT_CODEX_EXECUTABLE replaces codex.
A value that is empty, is a relative path, or names nothing runnable raises an error naming the
variable; the library never falls back to PATH in that case. Unset, the tool is claude or
codex on PATH.
Consent
The library makes no model calls of its own: the code that uses it does, so the library gates
nothing on a caller's behalf. Every model entry is classified local, subscription or
metered (paid or unverified billing), and the class and the reason for it are reported
(llm-kit models catalog, models describe, and protocol 2 responses). A protocol 2
request that does not opt in reports a claude or codex entry's class as null, because the
authentication probe that decides it runs only for an opted-in request.
The optional consent layer applies a policy you configure only when you
opt in, and you may build your own policy instead. To opt in, pass --consent [--consent-scope NAME] to
llm-kit models describe, send "consent": true or "consent": {"scope": "NAME"} in a
protocol 2 request, or call llm_kit.registry.consent.policy(scope=None). To apply your own
filter instead, pass --allow local,subscription (not combinable with --consent).
With the layer applied and no file, local and subscription are on and metered is off.
One file, $XDG_CONFIG_HOME/llm-kit/consent.json (~/.config/llm-kit/consent.json by
default; LLM_KIT_CONSENT_FILE overrides), holds the global policy and optional named scopes.
A scope overrides the global default for the classes it states, in either direction (a scope on over a global off allows that class for the scope only); a class the scope omits inherits the global value.
llm-kit consent show [--scope NAME] [--json]
llm-kit consent set [--scope NAME] --local|--subscription|--metered on|off
The same file holds the connection approvals, which always apply. A project model file
(.llm-kit/models.yaml) may connect an endpoint this machine does not know, with the name of
the environment variable that holds its key. Because that file is repository content, a call
sends the key only when the base URL is https (or plain http to a literal loopback address),
no endpoint of this machine sends that key variable to another host, and you have approved
exactly that endpoint name, host and key variable. The refusal prints the command:
llm-kit consent connection on|off --endpoint NAME --host HOST --key-env VAR
A keyless connection (key_env: null) needs no approval. The rules are in
docs/reference/llm-kit-formats.md, "Approval of a connection that sends a key".
Adapter names
The adapter for every non-harness entry is the OpenAI-compatible HTTP completion, and its name
is openai-compat. OpenRouter is one endpoint it serves, not its name. llm-kit models,
llm-kit models catalog, llm-kit invoke results, ledger events and the capability table
(llm_kit.adapters.capabilities.adapter_capabilities()) report openai-compat. The
openrouter registry entry, openrouter.ai URLs and llm-kit account keep their names.
Since 1.17.0: before it the adapter was named
openrouter. The old name is still read: a capability table, constructor table or catalog
modes_by_adapter keyed by openrouter serves openai-compat; a BackendSpec that says
backend="openrouter" builds the same backend; job-ledger and pipeline-run rows that store
openrouter read back as openai-compat. New writes use openai-compat. The response-cache
key is unchanged, so a stored cache keeps hitting. A custom BackendFactory should accept
both spellings. The Python names OpenRouterBackend (in llm_kit.adapters.backends,
llm_kit.pipeline.runtime and llm_kit.pipeline.runtime.backends) and
OPENROUTER_CAPABILITIES are deprecated aliases of OpenAICompatBackend and
OPENAI_COMPAT_CAPABILITIES that warn on use and are removable after 1.19.0.
Output cap
A model row of the project model file (.llm-kit/models.yaml) may declare max_output_tokens
(a positive integer; llm-kit models catalog shows it). A protocol 2 call to an OpenAI-compatible
row sends, in order: the request's max_tokens, the row's max_output_tokens, the row's
request_defaults.extras.max_tokens, then on openrouter.ai no cap (the model's full allowance)
and on other endpoints 4096. Explicit values are never clamped. When a call fails after the
provider answered, the protocol 2 error.finish_reason is the provider's raw stop string;
"length" means the cap ended the answer. Full statement: completion-seam-contract.md in the
plugin references.
Effort style reasoning-object
An endpoint (or a front-door routing) may opt in with effort_style: reasoning-object
to send an effort as the OpenRouter reasoning object. The default top-level style and
every other style are unchanged; nothing selects the new style implicitly.
- A typed effort
low|medium|high|minimal|xhigh|max sends {"reasoning": {"effort": value}};
none sends {"reasoning": {"enabled": false}}. An effort outside that vocabulary is refused
before any request. A typed effort of None sends nothing. An exact-model menu
(llm-kit models catalog) can still narrow what a model accepts.
- A caller
extras["reasoning"] wins as a whole over the typed effort. A mapping is sent
intact (exclude, max_tokens and other members included, and it is copied, not mutated);
None sends no reasoning at all; any other value, or a mapping beside a non-null
reasoning_effort (top-level or in chat_template_kwargs), is refused before any request.
This holds even when the typed effort is None.
- The front door treats an incoming
reasoning object as opaque and forwards it intact. An
incoming scalar reasoning_effort (top-level or in chat_template_kwargs) is translated to the
nested object. A malformed object or a scalar beside an object returns HTTP 400.
- A project-file row on such an endpoint may not default
request_defaults.extras.reasoning.
MiMo (xiaomi/mimo-v2.6-pro) exposes only the measured none control on a
reasoning-object endpoint. Other styles expose an empty menu for that model.
A live Novita probe on 2026-10-24 used the same prompt and a 4096-token cap.
reasoning.enabled=false returned 0 reasoning tokens. reasoning.enabled=true returned 596.
This evidence establishes an off switch. It does not establish positive effort levels.
A typed effort of None omits the control and retains the provider's default behavior.
Upgrading to 1.21
Machines that ran llm-kit relay peer export before 1.21 must run
llm-kit relay rotate-credentials. The hub and its peers upgrade together:
the mailbox moves to schema v2 and the peer export format moves to /2.
Front door: sized names
A frontdoor: true registry entry may carry frontdoor_group (the routing group its model
name stands for) and a context_window, the largest request a caller of that name may send.
The front door routes that name only to tiers whose context_window holds it, answers HTTP 400
when no tier does (naming the largest size the group holds), and lists the sized names in
/v1/models. A plain group name keeps its meaning: with a front-door entry for it, that
entry's window; without one, no size filter. A tier with routing.size_only: true is used only
when no ordinary tier holds the size, never as busy-spill (for a tier that costs a model swap).
Spill on a busy tier is immediate, as before. The access log records requested and size.
Front door: model preference lists