Skip to main content

No project description provided

Project description

DeepStrike Python SDK

Runtime framework built on a Rust kernel. The kernel handles loop control, context compression, skill routing, governance, signal prioritization — the SDK handles all I/O.

Install

pip install deepstrike

Requires Python 3.10+. The Rust kernel is distributed as a pre-built wheel (deepstrike._kernel).


Quick start

import asyncio
from deepstrike import (
    InMemorySessionLog,
    LocalExecutionPlane,
    OpenAIProvider,
    RuntimeOptions,
    RuntimeRunner,
    collect_text,
    tool,
)

@tool
async def add(x: int, y: int) -> str:
    """Add two numbers."""
    return str(x + y)

plane = LocalExecutionPlane().register(add)
runner = RuntimeRunner(RuntimeOptions(
    provider=OpenAIProvider(api_key="sk-...", model="gpt-5-mini"),
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,
    max_turns=25,
))

asyncio.run(collect_text(runner.run_streaming("What is 17 + 28?")))
# => "45"

Streaming:

async for event in runner.run_streaming("Summarize README.md"):
    if isinstance(event, TextDelta):
        print(event.delta, end="", flush=True)
    elif isinstance(event, ToolCallEvent):
        print(f"\n[→ {event.name}]")
    elif isinstance(event, DoneEvent):
        print(f"\ndone in {event.iterations} turns ({event.status})")

Providers

Class Backend Notes
OpenAIProvider OpenAI API SSE tool-call accumulation
AnthropicProvider Anthropic API Native SSE, ThinkingDelta support
QwenProvider DashScope enable_thinking via extensions
DeepSeekProvider DeepSeek API Reasoner models strip tools automatically
MiniMaxProvider MiniMax API M1 reasoning via expose_reasoning
OllamaProvider Local Ollama http://localhost:11434 default
KimiProvider Moonshot API

All providers accept RetryConfig for exponential backoff and share a CircuitBreaker.


Context model (four slots)

The kernel renders context as four LLM API slots — only history is compressed.

Slot Source Role
system_stable system partition Identity, rules — never changes within a run
system_knowledge knowledge partition Preloaded memory, skill defs — low frequency
turns[0] task_state + signals Goal, plan, progress, compression log, runtime signals
turns[1..N] history Conversation transcript
runner = RuntimeRunner(RuntimeOptions(
    initial_memory=["User prefers chartreuse."],  # → Slot 2
    system_prompt="You are a helpful assistant.",  # → Slot 1
    # ...
))

Full reference: docs/context-partition-compression.md


Runtime options

runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,            # context window size
    max_turns=25,               # max turns (default 25)
    timeout_ms=60_000,          # timeout in ms (None = no limit)
    extensions={"temperature": 0.1},
    skill_dir="./skills",       # skill .md files directory
    knowledge_source=my_ks,     # KnowledgeSource implementation
    governance=gov,             # kernel Governance instance
    signal_source=gateway,      # SignalGateway or any SignalSource
    dream_store=my_store,       # DreamStore for long-term memory
    agent_id="my-agent",        # required with dream_store for memory meta-tool
    initial_memory=["..."],     # preloaded blocks → Slot 2 (system_knowledge)
    sub_agent_harness=SubAgentHarnessConfig(  # optional: HarnessLoop for spawned sub-agents
        eval_provider=eval_provider,
        max_attempts=3,
    ),
))

Tools

from deepstrike import tool, read_file

plane.register(tool(name="search", description="Search.", parameters=schema)(my_fn))
plane.register(read_file)
plane.unregister("search")

Skills

Set skill_dir — the kernel auto-injects a skill meta-tool, and the LLM loads skills by name on demand.

runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,
    max_turns=25,
    skill_dir="./skills",
))
---
name: summarize
description: Summarize text into 2-3 concise bullet points
when_to_use: When you need to condense long text
effort: 1
---
1. Identify the 2-3 most important points
2. Express each as a concise bullet

Knowledge

Implement KnowledgeSource — the kernel injects a knowledge meta-tool. Runtime retrieval results land in history as tool results. Use initial_memory for durable preload into Slot 2.

from deepstrike import KnowledgeSource

class VectorSearch(KnowledgeSource):
    async def init(self) -> None:
        await vector_db.connect()

    async def retrieve(self, query: str, top_k: int = 5) -> list[str]:
        return await vector_db.search(query, top_k)

runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,
    max_turns=25,
    knowledge_source=VectorSearch(),
))

Memory

WorkingMemory (SDK-side scratch pad)

WorkingMemory is an SDK helper — not the kernel working partition (removed). Kernel task state renders into Slot 3 (turns[0]).

from deepstrike import WorkingMemory

mem = WorkingMemory()
mem.set("step", 1)
mem.get("step")  # 1
mem.clear()

DreamStore (long-term memory + dreaming pipeline)

from deepstrike import DreamStore

class MyStore(DreamStore):
    async def load_sessions(self, agent_id): ...
    async def load_memories(self, agent_id): ...
    async def commit(self, agent_id, result, existing): ...
    async def search(self, agent_id, query, top_k): ...
    async def save_session(self, data): ...

runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,
    max_turns=25,
    dream_store=MyStore(),
    agent_id="my-agent",
))

# In-session: LLM calls memory(query) → DreamStore.search() → history tool result
# Preload:    initial_memory → Slot 2 (system_knowledge)
# Post-session: trigger memory consolidation
result = await runner.dream("my-agent", now_ms=int(time.time() * 1000))

Governance

SDK PermissionManager

from deepstrike import PermissionManager, PermissionMode

pm = PermissionManager(PermissionMode.DEFAULT)
pm.grant("fs", "read")
pm.revoke("db", "drop")
pm.evaluate("fs", "read")  # PermissionDecision(allowed=True, ...)

Kernel Governance (full pipeline)

from deepstrike import Governance

gov = Governance("allow")
gov.add_permission_rule("danger.*", "deny")
gov.block_tool("rm_rf")
gov.set_rate_limit("api_call", max_calls=10, window_ms=60_000)

runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,
    max_turns=25,
    governance=gov,
))
# Every tool call: Permission → Veto → RateLimit → Constraint → Audit

Signals

from deepstrike import SignalGateway, ScheduledPrompt, RuntimeSignal

gw = SignalGateway()

gw.schedule(ScheduledPrompt(goal="standup", run_at_ms=target_time))
gw.ingest(RuntimeSignal(kind="interrupt", payload={}, urgency="critical"))

runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    max_tokens=4096,
    max_turns=25,
    signal_source=gw,
))

runner.interrupt()  # direct interrupt
gw.destroy()

Harness (evaluation framework)

from deepstrike import SinglePassHarness, EvalLoopHarness, HarnessLoop, HarnessRequest

# 1. SinglePass — run once, always passes
outcome = await SinglePassHarness(runner).run(HarnessRequest(goal="Say hello"))

# 2. EvalLoop — retry until QualityGate passes
class ContainsHello(QualityGate):
    async def evaluate(self, request, outcome) -> bool:
        return "hello" in outcome.result.lower()

outcome = await EvalLoopHarness(runner, gate=ContainsHello(), max_attempts=3).run(req)

# 3. HarnessLoop — LLM-as-judge with feedback injection + skill extraction
loop = HarnessLoop(runner, eval_provider=eval_provider, max_attempts=3, skill_dir="./skills")

# Sub-agents: pass sub_agent_harness on RuntimeOptions to auto-evaluate spawned children
from deepstrike import SubAgentHarnessConfig
runner = RuntimeRunner(RuntimeOptions(
    provider=provider,
    session_log=InMemorySessionLog(),
    execution_plane=plane,
    sub_agent_harness=SubAgentHarnessConfig(eval_provider=eval_provider, max_attempts=3),
    # ...
))
async for event in loop.run_streaming(HarnessRequest(goal="Write a haiku")):
    if event.type == "done":
        print(event.verdict.passed, event.verdict.feedback)

Stream events

Class Key fields
TextDelta delta
ThinkingDelta delta
ToolCallEvent id, name, arguments
ToolDeltaEvent call_id, name, delta, chunk?
ToolSuspendEvent call_id, name, suspension_id, payload?
ToolResultEvent call_id, content, is_error
DoneEvent iterations, total_tokens, status
ErrorEvent message

status: completed · max_turns · token_budget · timeout · user_abort · error

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepstrike-0.2.3.tar.gz (177.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

deepstrike-0.2.3-cp310-abi3-win_arm64.whl (732.5 kB view details)

Uploaded CPython 3.10+Windows ARM64

deepstrike-0.2.3-cp310-abi3-win_amd64.whl (794.7 kB view details)

Uploaded CPython 3.10+Windows x86-64

deepstrike-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ x86-64

deepstrike-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl (965.0 kB view details)

Uploaded CPython 3.10+musllinux: musl 1.2+ ARM64

deepstrike-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (840.0 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ x86-64

deepstrike-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (787.1 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

deepstrike-0.2.3-cp310-abi3-macosx_11_0_arm64.whl (770.3 kB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

deepstrike-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl (825.3 kB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file deepstrike-0.2.3.tar.gz.

File metadata

  • Download URL: deepstrike-0.2.3.tar.gz
  • Upload date:
  • Size: 177.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deepstrike-0.2.3.tar.gz
Algorithm Hash digest
SHA256 0a48f455d0b93b1c3253e3058912fa577373c12738cebdb57c389da06a197265
MD5 022f86e870fd063a469710f46a7211f0
BLAKE2b-256 3d0a682f35804a22fc2a2a96e8ac3c42f9e4a0b31909f55333b02213f191fbae

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3.tar.gz:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-win_arm64.whl.

File metadata

  • Download URL: deepstrike-0.2.3-cp310-abi3-win_arm64.whl
  • Upload date:
  • Size: 732.5 kB
  • Tags: CPython 3.10+, Windows ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-win_arm64.whl
Algorithm Hash digest
SHA256 8c2adf517aad6b8bf8379c12aa181a5c8abae94c649d20999783be893d2885a8
MD5 053f93a0ac94c5361e500f8424b4f422
BLAKE2b-256 3b883d16eaecf45f3f8e4483c86d201b41adefb34e43dc7711fc4b7abafb7286

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-win_arm64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: deepstrike-0.2.3-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 794.7 kB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 40c55d2edb3b94302eb0c326460feab5b2743c73ea7877ba0b5dfc4bf8e04d3c
MD5 852db340b910a6c0c4cb7060b6b78a95
BLAKE2b-256 2b45d84228c0186709066197bb061999822354d5ad09a45378e6cb382cf9dea3

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-win_amd64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 0ddbcf3814516fd5d4eaaf2e5a2b20e6f0bd166eeaf83eb20895ae8d1fe48a0a
MD5 8c6f3f1386546148b6ac30af1f4ffd70
BLAKE2b-256 c0d16509b21a8c0a0c2a42a36a9f1793cbadf47a9140b6c353cc77c4d49929ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-musllinux_1_2_x86_64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9ef8c9132e65c68fe4b0118cd3b84c93313c85e34569f29eb0f70ca305b76dff
MD5 4d22ba973e40109209c5affa5d1829bb
BLAKE2b-256 d991189d715dab94534e0f5394c368540395d3adeacdb10e35f40a3ba28a664e

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-musllinux_1_2_aarch64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34da3f87ac4b2bf8b9eaf8f63ea6a5d07022dbfaa6c2178871ea5d3ae0b0f500
MD5 4eb6cfa21b1e9aacbeaf8a6e29f6fac1
BLAKE2b-256 f40dd6a5950a0a8d16c2e2dbbb6569e2ad61ee1401073b9e836a5d52ade1e618

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bc5dd864cb9baecf8e1b90df2c0c67d01a5ad902f583b88bcde70f694e97306c
MD5 f7a329b6887258acbb7380c74f650aab
BLAKE2b-256 ef1ccdbcbe5ace2eadfac0d0cce6f0d18f9c6053271a6fc2c665832b5061cf0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 21f6822d42e548d954eea5716e3cd5ca96c341d73fd8595b0ab58f59e0544d13
MD5 e63220a73ff7b5ccbfc7f5a15bbb772c
BLAKE2b-256 3023befdea35f9dca60b789a7c6840cf40a4b41ef9c5eed4528c6808beeae73c

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepstrike-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for deepstrike-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f23d3fc88365479a8b1abaf449b122c90bd3a9b840b20cf34c1b74342c6beaf9
MD5 cd973baead79b3df689905cea538e535
BLAKE2b-256 b33b6970c41b613290b13835ea33d8856da27e2d1e4d5738e1223e7be1a18fa1

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepstrike-0.2.3-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on kongusen/deepstrike

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page