Wormhole core engine.
Project description
Wormhole Core
Purpose
Wormhole Core is a deterministic, event-driven loop built to be embedded by the SDK. It does not perform direct I/O; the SDK (and other clients) provide adapters and tools.
External Engine Dependency (loopgraph)
Core depends on the published loopgraph>=0.3.0 package for graph execution.
Integration is done by constructing loopgraph Graphs and executing them via
Scheduler. Pin updates by editing pyproject.toml.
Module Overview
graph/: Graph construction helpers, scheduler runtime, and per-session registry wrappers.events/: event types andEventStreamfor emitting structured core events.hooks/: Hook registry and lifecycle hook types (prompt, tool gate, telemetry, compaction).backpressure.py: bounded queue configuration and metrics.retry.py: retry policy and idempotency helpers used by the SDK.loop/: session lifecycle (start,step,stop), compaction decisions, and resume helpers.storage/: Async storage protocols plus file-based stores for sessions, snapshots, event logs, and compaction.schemas/: session, message, and tool schemas.tools/: tool registry, schema validation, and permission gating.logging.py: structured debug logging helpers with redaction support.errors.py: stable error taxonomy.
Tool Implementations (SDK)
Core defines tool schemas, permission policy, and registries only. Concrete
OS-facing tool implementations live in the SDK under wormhole_sdk.tools
(bash, file_read, file_edit, file_write, binary handlers). Use
wormhole_sdk.tools.create_default_tools() to register the default tool set
with a ToolRegistry.
Schemas
Messages and Parts
Messages are sequences of typed parts.
- Part types:
text,tool_call,tool_output,cost,metadata - Roles:
user,assistant,system
Tools
Tools are registered with:
tool_id,name,schema,permission_kind,enabledcapabilities(read_only, concurrency_safe, approval_required)default_retry_policy(optional SDK override)
Capability notes:
read_onlyis informational only.concurrency_safecontrols scheduler parallelism.approval_requiredis advisory; the SDK ApprovalManager uses it to request approval.- Permission kinds are advisory; core only enforces the allowlist.
allowlist_only: intended for allowlist-only toolsuser_approval: intended for tools that should prompt for approval
Sessions
Session config defaults:
retention_days=30compaction_ratio=0.7auto_compaction_enabled=Trueallowlisted_tools=[]max_concurrent_tools=1backpressure=None(SDK defaults to bounded queues)model_retry_policy/tool_retry_policy(SDK executes retries)approval_timeout_seconds=60
Execution state and resume:
graph_idandexecution_state_idtrack the latest loopgraph snapshot.ExecutionStateSnapshotstores opaque loopgraph state for resume.
Loop termination enums:
FinishReason:end_turn,tool_use,max_tokens,stopContinuationMode:automatic,force_continue,force_stop
Persistence and Compaction
SessionStorepersists session records, execution state, and history.CompactionStorestores snapshots used to load the latest compressed prompt state.- Auto-compaction triggers when context ratio exceeds the configured threshold; it can be disabled.
- Compaction is two-stage: prune old
tool_outputpayloads into short placeholder tool results (keeping the last N rounds), then summarize if the context still exceeds the prune target. - Successful compaction appends a SYSTEM message with metadata
{"compaction": true, "snapshot_id": "..."}; full history remains immutable. - Context reconstruction uses the last compaction-tagged message plus all later messages, replacing old tool outputs with compact placeholders while preserving valid tool call/result sequencing.
Compaction (Core API)
from wormhole_core.compaction.strategies import NoOpSummarizationStrategy
from wormhole_core.loop.compaction import compact_session
from wormhole_core.schemas.session import CompactionConfig
from wormhole_core.storage.compaction_store import CompactionStore
result = await compact_session(
session_id="session-1",
messages=message_history,
compaction_store=CompactionStore(root_dir),
summarization_strategy=NoOpSummarizationStrategy(),
config=CompactionConfig(),
context_limit=8192,
)
Forking and Lineage
from wormhole_core.session.fork import fork_session
from wormhole_core.session.types import ForkRequest
from wormhole_core.storage.compaction_store import CompactionStore
from wormhole_core.storage.session_store import SessionStore
result = await fork_session(
ForkRequest(parent_session_id="session-1", new_session_id="child-1"),
session_store=SessionStore(root_dir / "sessions"),
compaction_store=CompactionStore(root_dir / "compactions"),
)
Sessions track lineage with parent_session_id. Use
SessionStore.list(parent_session_id=...) to query children.
Storage Protocols
Core defines async Protocol interfaces for persistence backends:
SessionStoreProtocolExecutionStateStoreProtocolEventLogStoreProtocolCompactionStoreProtocol
File-based stores in wormhole_core.storage implement these protocols and use
atomic write-then-rename plus file locking. The session list operation returns
SessionSummary (session_id, created_at, updated_at) without reading
session file contents.
Error Codes
Stable errors are emitted as WormholeError with codes:
WH-CORE-001: validation errorWH-CORE-002: permission deniedWH-CORE-003: not foundWH-CORE-004: session expiredWH-CORE-005: persistence errorWH-CORE-006: tool execution errorWH-CORE-007: invalid state transitionWH-CORE-008: engine errorWH-CORE-009: config errorWH-CORE-100: loopgraph unavailableWH-CORE-101: scheduler execution errorWH-CORE-102: snapshot errorWH-CORE-103: handler not foundWH-CORE-104: graph cycle errorWH-CORE-110: snapshot version mismatchWH-CORE-120: duplicate tool registrationWH-CORE-121: tool schema errorWH-CORE-130: hook errorWH-CORE-131: backpressure errorWH-CORE-132: capability violationWH-CORE-133: retry exhaustedWH-CORE-134: approval deniedWH-CORE-135: approval timeoutWH-CORE-136: approval persistence error
Quick Start (Async)
import asyncio
from wormhole_core.loop.session_api import SessionManager
from wormhole_core.schemas.session import SessionConfig
async def main() -> None:
manager = SessionManager()
handle = await manager.start_session(SessionConfig(max_concurrent_tools=2))
await manager.step_session(handle.session.session_id, input="hello")
await manager.stop_session(handle.session.session_id)
asyncio.run(main())
Doctest Coverage
Run doctests for core modules:
python -m pytest --doctest-modules packages/core/
Debug Logging Gate
Debug logs must be structured and disabled in release mode.
WORMHOLE_DEBUG=1enables debug logs.WORMHOLE_RELEASE=1forces debug logs off.
CI should include a release-mode run that fails on debug output, for example:
WORMHOLE_RELEASE=1 python -m pytest --doctest-modules 2>&1 | rg -n "DEBUG" && exit 1 || exit 0
Version History
wormhole-core follows pre-1.0 SemVer: in 0.x, MINOR bumps mark new
release milestones (and breaking changes); PATCH covers fixes within a
milestone. Versions are tracked independently of wormhole-sdk.
| Version | Milestone | Notes |
|---|---|---|
| 0.1.0 | Initial scaffold | SDK-ready core package layout. |
| 0.2.0 | Eventflow graph engine | Graph/Scheduler/EventBus/ExecutionState/FunctionRegistry integration; LoopEngine removed. |
| 0.3.0 | Event log persistence + runtime safeguards | EventLogStore, structured runtime checks. |
| 0.4.0 | Hook + backpressure + retry contracts | HookRegistry, BackpressureConfig, RetryPolicy, ToolCapabilities. |
| 0.5.0 | Tool execution timeout + tool-results-as-messages | Per-tool timeout enforcement; tool outputs flow as user-message parts. |
| 0.6.0 | OS-tool boundary + storage protocols | Concrete OS tools moved to SDK; protocol-based persistence (Session/ExecutionState/EventLog/Compaction). |
| 0.7.0 | Two-stage compaction + fork lineage | Prune-then-summarize compaction; parent_session_id lineage; reconstructed-context helpers. |
| 0.8.0 | Tool registration formalization | Strict typing for the registration flow. |
| 0.9.0 | TaskTool delegation schema + prompt locks | DelegationContext, prompt-layer lock APIs, child-session storage linkage. |
| 0.10.0 | Unified graph loop migration | Multi-turn conversation runs in one step_session call via the graph runtime; staged-message queue. |
| 0.11.0 | BREAKING: approval unification | Removed ApprovalHook; all approval flows go through ApprovalManager. Pre-approval paths must be normalized. |
| 0.12.0 | BREAKING: rename engine dep to loopgraph |
eventflow2 → loopgraph>=0.3.0,<0.4.0. Renames: EventflowError→LoopgraphError, EVENTFLOW_UNAVAILABLE→LOOPGRAPH_UNAVAILABLE, EventflowSnapshotStore→LoopgraphSnapshotStore, EventflowEvent/EventType aliases→Loopgraph*, ensure_eventflow_available→ensure_loopgraph_available. |
| 0.13.0 | First public release | License relicensed from proprietary "All Rights Reserved" to AGPL-3.0-or-later; Private :: Do Not Upload classifier removed. No source-API changes from 0.12.0. |
License
wormhole-core is distributed under the GNU Affero General Public License
v3.0 or later (AGPL-3.0-or-later). See LICENSE for the full
text.
The AGPL extends the GNU GPL by requiring that anyone who runs a modified
version of the software as a network service must make the source code of
that modified version available to the service's users. If you embed
wormhole-core in a hosted product, that obligation applies. For commercial
licensing terms outside the AGPL, contact the maintainers.
Project details
Release history Release notifications | RSS feed
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 wormhole_core-0.13.0.tar.gz.
File metadata
- Download URL: wormhole_core-0.13.0.tar.gz
- Upload date:
- Size: 98.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e963be3137811a38ee4f1d276155d57eb5ff27d29cdf96231f62f08a53ac2ab
|
|
| MD5 |
8547ea0ee45114d03254cf6d444a7045
|
|
| BLAKE2b-256 |
db1cc3d6deddea8e62368a1e19af4d8d09071c4255b955ebcf4500d03442ed5a
|
File details
Details for the file wormhole_core-0.13.0-py3-none-any.whl.
File metadata
- Download URL: wormhole_core-0.13.0-py3-none-any.whl
- Upload date:
- Size: 97.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06e43bbab2b27e78b4e733f6cdbc7d43bd77ef0c2787641f9a16a222ab840ff9
|
|
| MD5 |
567c4563ba5c030012971e017f526efc
|
|
| BLAKE2b-256 |
263f57efcb01e2a9d53473adca2f66adb8cdd1a0f0ff65c3a07d82edd88ac0a1
|