API Reference¶
Core¶
Kernel¶
agent_os_kernel.kernel.Kernel
¶
The Agent OS Kernel.
One API: submit(action_request) -> action_result Three components: Policy, Gate (this class), Log Three invariants: all access through Gate, default deny, no silent actions
Source code in src/agent_os_kernel/kernel.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
log
property
¶
Access the kernel's log (read-only).
policy
property
¶
Access the kernel's policy (read-only).
__init__(policy, providers=None, log_path='kernel.log')
¶
Initialize the kernel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy
|
str | Path | Policy
|
Path to YAML policy file, or a Policy instance. |
required |
providers
|
dict[str, Provider] | list[Provider] | None
|
Provider registry. Either a dict mapping action types to providers, or a list of providers (auto-registered by their declared action types). |
None
|
log_path
|
str | Path
|
Path to the JSONL log file. |
'kernel.log'
|
Source code in src/agent_os_kernel/kernel.py
close()
¶
submit(request)
¶
Submit an action request through the Gate.
Per v2 §4.2: 1. Validate request format 2. Match request against policy (default deny) 3. Resolve provider for action 4. Call provider.execute(request) 5. Log result 6. Return result
Every path produces exactly one log record.
Source code in src/agent_os_kernel/kernel.py
ActionRequest¶
agent_os_kernel.models.ActionRequest
dataclass
¶
A request to perform a world-facing action.
Attributes:
| Name | Type | Description |
|---|---|---|
action |
str
|
Action type, e.g. "fs.read", "net.http". |
target |
str
|
Resource target, e.g. "/workspace/data.csv". |
params |
dict[str, Any]
|
Action-specific parameters. |
Source code in src/agent_os_kernel/models.py
ActionResult¶
agent_os_kernel.models.ActionResult
dataclass
¶
The result of a submitted action.
Attributes:
| Name | Type | Description |
|---|---|---|
status |
str
|
One of "OK", "DENIED", "ERROR". |
data |
Any
|
Provider return value, or None. |
error |
str | None
|
Error message if status is not OK. |
record_id |
str | None
|
Optional snapshot ID for reversible actions (v2.1).
Set by ReversibleActionLayer after successful snapshot persistence.
This is the caller-side correlation key — use it to rollback via
|
Source code in src/agent_os_kernel/models.py
Record¶
agent_os_kernel.models.Record
dataclass
¶
An append-only log entry produced by every Gate decision.
Attributes:
| Name | Type | Description |
|---|---|---|
timestamp |
str
|
ISO 8601 timestamp. |
action |
str
|
Action type, e.g. "fs.read". |
target |
str
|
Resource target. |
status |
str
|
One of "INVALID", "DENIED", "NO_PROVIDER", "FAILED", "OK". |
error |
str | None
|
Error message if status is not OK. |
duration_ms |
int | None
|
Execution time if provider was called. |
record_id |
str | None
|
Optional snapshot ID linking to reversible action (v2.1). Note: the kernel does not populate this field — it is always None in log entries written by the Gate. The v2.1 design includes it in the schema for forward-compatibility, but writing it would require modifying the kernel interface (contradicting v2.1's "kernel is unchanged" principle). Use ActionResult.record_id for caller-side snapshot correlation instead. |
Source code in src/agent_os_kernel/models.py
Policy¶
Policy¶
agent_os_kernel.policy.Policy
dataclass
¶
A set of capability rules loaded from a YAML file.
Policy is a static allow-list. If no rule matches, the action is denied.
Source code in src/agent_os_kernel/policy.py
is_allowed(request)
¶
Check if a request is permitted by any capability rule.
Per v2 §3.3: iterate rules, check action + resource + constraint. Default deny if no rule matches.
Source code in src/agent_os_kernel/policy.py
CapabilityRule¶
agent_os_kernel.policy.CapabilityRule
dataclass
¶
A single capability rule from the policy file.
Attributes:
| Name | Type | Description |
|---|---|---|
action |
str
|
The action type being permitted, e.g. "fs.read". |
resource |
str
|
The resource pattern being permitted, e.g. "/workspace/**". |
constraint |
dict[str, Any] | None
|
Optional additional restrictions, e.g. {"method": "GET"}. |
Source code in src/agent_os_kernel/policy.py
action_matches(action)
¶
constraint_matches(request)
¶
Check if the request satisfies this rule's constraints.
Source code in src/agent_os_kernel/policy.py
resource_matches(target)
¶
Check if the requested target matches this rule's resource pattern.
Uses glob-style matching: ** matches everything including path separators.
Source code in src/agent_os_kernel/policy.py
load_policy¶
agent_os_kernel.policy.load_policy(policy_path)
¶
Load a policy from a YAML file.
Expected format
capabilities: - action: fs.read resource: /workspace/ - action: fs.write resource: /workspace/output/
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
policy_path
|
str | Path
|
Path to the YAML policy file. |
required |
Returns:
| Type | Description |
|---|---|
Policy
|
A Policy instance with the parsed capability rules. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the policy file does not exist. |
ValueError
|
If the policy file is malformed. |
Source code in src/agent_os_kernel/policy.py
Log¶
agent_os_kernel.log.Log
¶
Append-only JSONL log writer.
Writes one JSON object per line. Never modifies or deletes records.
Source code in src/agent_os_kernel/log.py
close()
¶
open()
¶
read_all()
¶
Read all records from the log file.
Returns:
| Type | Description |
|---|---|
list[Record]
|
List of Record instances. |
Source code in src/agent_os_kernel/log.py
write(record)
¶
Append a single record to the log.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
record
|
Record
|
The Record to write. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If the log is not open. |
Source code in src/agent_os_kernel/log.py
Providers¶
Provider (Base)¶
agent_os_kernel.providers.base.Provider
¶
Bases: ABC
Abstract base class for all providers.
A provider: - declares which action types it handles - receives an already-authorized request from the Gate - executes the real effect - returns a result or raises an exception
A provider does NOT: - check authorization (the Gate already did) - write to the Log (the Gate does this) - call other providers - interact with the agent loop
Source code in src/agent_os_kernel/providers/base.py
actions
abstractmethod
property
¶
List of action types this provider handles.
execute(request)
abstractmethod
¶
Execute the action and return a result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ActionRequest
|
An already-authorized ActionRequest. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The result of the action (provider-specific). |
Raises:
| Type | Description |
|---|---|
Exception
|
If execution fails. |
Source code in src/agent_os_kernel/providers/base.py
FilesystemProvider¶
agent_os_kernel.providers.filesystem.FilesystemProvider
¶
Bases: Provider
Provider for filesystem operations.
Source code in src/agent_os_kernel/providers/filesystem.py
ProcessProvider¶
agent_os_kernel.providers.process.ProcessProvider
¶
Bases: Provider
Provider for process execution.
Source code in src/agent_os_kernel/providers/process.py
HttpProvider¶
agent_os_kernel.providers.http.HttpProvider
¶
Bases: Provider
Provider for HTTP requests using urllib (no external dependencies).
Source code in src/agent_os_kernel/providers/http.py
McpProvider¶
agent_os_kernel.providers.mcp.McpProvider
¶
Bases: Provider
Provider for MCP tool calls.
The target format is "server_name/tool_name", e.g. "scholar/search". MCP servers are configured at initialization with their command and env.
Server config format
{ "server_name": { "command": ["npx", "-y", "@modelcontextprotocol/server-filesystem", "/path"], "env": {"KEY": "value"}, # optional } }
Source code in src/agent_os_kernel/providers/mcp.py
__init__(servers=None)
¶
Initialize with MCP server configurations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
servers
|
dict[str, Any] | None
|
Mapping of server names to connection configs. Each config must have a "command" key (list of strings). Optional "env" key for environment variables. |
None
|
Source code in src/agent_os_kernel/providers/mcp.py
Reversible Action Layer¶
ReversibleActionLayer¶
agent_os_kernel.reversible.ReversibleActionLayer
¶
Wraps the kernel to provide snapshot-based rollback.
The layer coordinates snapshot capture, execution, and rollback. The kernel does not know this layer exists.
Source code in src/agent_os_kernel/reversible.py
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
rollback(record_id)
¶
Roll back a previously executed action by its record ID.
Source code in src/agent_os_kernel/reversible.py
submit(request)
¶
Submit an action, capturing a snapshot if the action is reversible.
Per design §7.1-7.2: capture and persistence failures are best-effort. If either fails, the action proceeds without rollback capability.
Note: record_id is set on the returned ActionResult, not on the kernel's log Record. See Record.record_id docstring for rationale.
Source code in src/agent_os_kernel/reversible.py
SnapshotStrategy¶
agent_os_kernel.reversible.SnapshotStrategy
¶
Bases: ABC
Captures pre-execution state for a specific action type.
Each provider that supports rollback defines its own strategy.
Source code in src/agent_os_kernel/reversible.py
FsWriteSnapshotStrategy¶
agent_os_kernel.reversible.FsWriteSnapshotStrategy
¶
Bases: SnapshotStrategy
Snapshot strategy for fs.write actions.
Captures file content before overwrite so it can be restored.
Source code in src/agent_os_kernel/reversible.py
FsDeleteSnapshotStrategy¶
agent_os_kernel.reversible.FsDeleteSnapshotStrategy
¶
Bases: SnapshotStrategy
Snapshot strategy for fs.delete actions.
Captures file content before deletion so it can be restored via fs.write. If the file did not exist before delete, capture returns None and no snapshot is persisted (the delete was a no-op, nothing to restore).
Source code in src/agent_os_kernel/reversible.py
SnapshotStore¶
agent_os_kernel.reversible.SnapshotStore
¶
Persists snapshots indexed by record ID.
A simple file-based key-value store. Snapshots expire after TTL.
Source code in src/agent_os_kernel/reversible.py
delete(record_id)
¶
load(record_id)
¶
Load a snapshot by record ID. Returns None if not found or expired.
Source code in src/agent_os_kernel/reversible.py
save(record_id, request, snapshot)
¶
Save a snapshot associated with a record ID.
Source code in src/agent_os_kernel/reversible.py
Agent Loop¶
ToolDef¶
agent_os_kernel.agent_loop.ToolDef
dataclass
¶
Declares a tool the LLM can call. Contains NO execution logic.
Execution is always handled by kernel.submit() -> provider.execute(). ToolDef only provides the metadata the LLM needs to generate tool calls and the mapping rules to convert tool calls into ActionRequests.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Tool name shown to the LLM. |
description |
str
|
Tool description shown to the LLM. |
parameters |
dict[str, Any]
|
JSON Schema for tool parameters. |
action |
str
|
Kernel action type, e.g. "fs.read", "mcp.call". |
target_from |
str | Callable[[dict[str, Any]], str]
|
How to extract the target for the ActionRequest. If a string, uses that parameter name from the tool args. If a callable, calls it with the args dict to produce the target. |
Source code in src/agent_os_kernel/agent_loop.py
AgentLoop¶
agent_os_kernel.agent_loop.AgentLoop
¶
LLM agent loop where kernel.submit() is the sole execution path.
Invariant: there is no code path that executes a tool without going through kernel.submit(). This is enforced structurally — ToolDefs contain no execution logic, and this class only calls kernel.submit().
Source code in src/agent_os_kernel/agent_loop.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | |
__init__(kernel, model, instructions='', tools=None, max_turns=20, submit=None)
¶
Initialize the agent loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Kernel
|
The Kernel instance for authorization and execution. |
required |
model
|
str
|
LiteLLM model string, e.g. "gpt-4o", "anthropic/claude-sonnet-4-20250514". |
required |
instructions
|
str
|
System prompt for the LLM. |
''
|
tools
|
list[ToolDef] | None
|
List of ToolDefs available to the agent. |
None
|
max_turns
|
int
|
Maximum LLM call iterations before stopping. |
20
|
submit
|
SubmitFn | None
|
Optional override for the submit callable. Defaults to kernel.submit(). Use this for ReversibleActionLayer integration. |
None
|
Source code in src/agent_os_kernel/agent_loop.py
run(prompt)
async
¶
Run the agent loop until completion or max_turns.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt
|
str
|
User input prompt. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The agent's final text output. |
Source code in src/agent_os_kernel/agent_loop.py
run_agent_loop¶
agent_os_kernel.agent_loop.run_agent_loop(kernel, model, prompt, *, instructions='', tools=None, max_turns=20, submit=None)
async
¶
Convenience function: create an AgentLoop and run it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel
|
Kernel
|
The Kernel instance. |
required |
model
|
str
|
LiteLLM model string. |
required |
prompt
|
str
|
User input prompt. |
required |
instructions
|
str
|
System prompt for the LLM. |
''
|
tools
|
list[ToolDef] | None
|
List of ToolDefs. |
None
|
max_turns
|
int
|
Maximum LLM call iterations. |
20
|
submit
|
SubmitFn | None
|
Optional override for the submit callable. Defaults to kernel.submit(). Use this for ReversibleActionLayer integration. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
The agent's final text output. |
Source code in src/agent_os_kernel/agent_loop.py
SubmitFn¶
agent_os_kernel.models.SubmitFn = Callable[['ActionRequest'], 'ActionResult']
module-attribute
¶
CLI¶
The kernel provides a CLI entry point:
Commands¶
| Command | Description |
|---|---|
submit |
Submit an action through the kernel |
log |
Display kernel log entries |
validate-policy |
Validate a policy YAML file |
version |
Print version information |
Examples¶
# Validate a policy file
python -m agent_os_kernel validate-policy --policy configs/example_policy.yaml
# Submit an action
python -m agent_os_kernel submit --policy policy.yaml --action fs.read --target /workspace/data.txt
# View log entries
python -m agent_os_kernel log --log-path kernel.log --status OK --limit 10
# Print version
python -m agent_os_kernel version