mark-sdk 0.2.0a5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mark/.gitkeep +0 -0
- mark/__init__.py +173 -0
- mark/_version.py +3 -0
- mark/adapters/__init__.py +9 -0
- mark/adapters/backend.py +131 -0
- mark/adapters/langchain/__init__.py +15 -0
- mark/adapters/langchain/middleware.py +1094 -0
- mark/adapters/langchain/tools.py +95 -0
- mark/adapters/mcp/__init__.py +157 -0
- mark/agent.py +76 -0
- mark/context/.gitkeep +0 -0
- mark/context/__init__.py +4 -0
- mark/context/builder.py +68 -0
- mark/context/window.py +7 -0
- mark/deep_rl/__init__.py +20 -0
- mark/deep_rl/safety.py +95 -0
- mark/embeddings/__init__.py +4 -0
- mark/embeddings/base.py +54 -0
- mark/embeddings/cache.py +62 -0
- mark/embeddings/ollama.py +48 -0
- mark/embeddings/sentence_transformers.py +36 -0
- mark/governance/__init__.py +18 -0
- mark/governance/audit.py +93 -0
- mark/governance/gates.py +103 -0
- mark/governance/pipeline.py +69 -0
- mark/governance/sanitizer.py +40 -0
- mark/index/__init__.py +3 -0
- mark/index/vector.py +106 -0
- mark/intelligence/__init__.py +64 -0
- mark/intelligence/classifier.py +198 -0
- mark/intelligence/compressor.py +139 -0
- mark/intelligence/extractor.py +485 -0
- mark/intelligence/query_expander.py +76 -0
- mark/intelligence/reranker.py +132 -0
- mark/intelligence/retrieval.py +563 -0
- mark/media/__init__.py +20 -0
- mark/media/entity.py +158 -0
- mark/media/session_memory.py +95 -0
- mark/media/world_bible.py +125 -0
- mark/memory/.gitkeep +0 -0
- mark/memory/__init__.py +57 -0
- mark/memory/block.py +119 -0
- mark/memory/block_chain.py +293 -0
- mark/memory/block_graph.py +270 -0
- mark/memory/consolidation.py +116 -0
- mark/memory/contradiction.py +124 -0
- mark/memory/conversation.py +148 -0
- mark/memory/deduplication.py +219 -0
- mark/memory/global_bus.py +93 -0
- mark/memory/graph.py +77 -0
- mark/memory/mark_memory.py +871 -0
- mark/memory/migration.py +126 -0
- mark/memory/observe.py +200 -0
- mark/memory/record.py +73 -0
- mark/memory/retrieval.py +27 -0
- mark/memory/runtime.py +258 -0
- mark/memory/scoring.py +56 -0
- mark/memory/simple.py +334 -0
- mark/memory/store.py +117 -0
- mark/memory/trust_bus.py +336 -0
- mark/memory/working.py +88 -0
- mark/observability/.gitkeep +0 -0
- mark/observability/__init__.py +12 -0
- mark/observability/events.py +30 -0
- mark/observability/replay.py +63 -0
- mark/observability/session.py +57 -0
- mark/observability/trace.py +62 -0
- mark/plasticity/__init__.py +34 -0
- mark/plasticity/decay.py +101 -0
- mark/plasticity/hebbian.py +73 -0
- mark/plasticity/pruner.py +87 -0
- mark/plasticity/router.py +69 -0
- mark/plugins/__init__.py +57 -0
- mark/plugins/registry.py +200 -0
- mark/policies/.gitkeep +0 -0
- mark/policies/__init__.py +15 -0
- mark/policies/base.py +46 -0
- mark/policies/builtin.py +50 -0
- mark/policies/registry.py +36 -0
- mark/rl/__init__.py +28 -0
- mark/rl/buffer.py +99 -0
- mark/rl/collectors.py +113 -0
- mark/rl/encoder.py +56 -0
- mark/rl/reward.py +59 -0
- mark/runtime.py +301 -0
- mark/sandbox/.dockerignore +0 -0
- mark/sandbox/Dockerfile +0 -0
- mark/sandbox/__init__.py +3 -0
- mark/sandbox/compose.yaml +0 -0
- mark/sandbox/docker.py +180 -0
- mark/security/.gitkeep +0 -0
- mark/security/__init__.py +12 -0
- mark/security/encryption.py +114 -0
- mark/security/hasher.py +38 -0
- mark/security/redaction.py +40 -0
- mark/skills/.gitkeep +0 -0
- mark/skills/__init__.py +21 -0
- mark/skills/base.py +366 -0
- mark/skills/builtin.py +86 -0
- mark/skills/mark-memory-middleware/SKILL.md +36 -0
- mark/skills/mark-usage/SKILL.md +255 -0
- mark/skills/persona.py +77 -0
- mark/skills/registry.py +38 -0
- mark/skills/web_search.py +311 -0
- mark/storage/.gitkeep +0 -0
- mark/storage/__init__.py +3 -0
- mark/storage/json_store.py +84 -0
- mark/store/__init__.py +4 -0
- mark/store/activity_log.py +79 -0
- mark/store/sqlite.py +1045 -0
- mark/sync/.gitkeep +0 -0
- mark/sync/__init__.py +11 -0
- mark/sync/cloud.py +193 -0
- mark/sync/redaction.py +16 -0
- mark/types/__init__.py +32 -0
- mark/types/attribution.py +80 -0
- mark/types/gap.py +95 -0
- mark/types/graph.py +232 -0
- mark/types/llm.py +30 -0
- mark/types/memory.py +338 -0
- mark_sdk-0.2.0a5.dist-info/METADATA +348 -0
- mark_sdk-0.2.0a5.dist-info/RECORD +124 -0
- mark_sdk-0.2.0a5.dist-info/WHEEL +4 -0
- mark_sdk-0.2.0a5.dist-info/licenses/LICENSE +21 -0
mark/.gitkeep
ADDED
|
File without changes
|
mark/__init__.py
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"""Local-first MARK runtime SDK."""
|
|
2
|
+
|
|
3
|
+
from mark._version import __version__
|
|
4
|
+
from mark.agent import AgentResult, MarkAgent
|
|
5
|
+
from mark.context import ContextBundle, ContextBuilder
|
|
6
|
+
from mark.embeddings import CachedEmbeddingProvider, EmbeddingProvider, HashEmbeddingProvider
|
|
7
|
+
from mark.index import VectorIndex, VectorSearchResult
|
|
8
|
+
from mark.intelligence import (
|
|
9
|
+
ContextualCompressor,
|
|
10
|
+
KeywordQueryExpander,
|
|
11
|
+
LLMContextualCompressor,
|
|
12
|
+
LLMQueryExpander,
|
|
13
|
+
NoopCompressor,
|
|
14
|
+
NoopQueryExpander,
|
|
15
|
+
QueryExpander,
|
|
16
|
+
RetrievalPipeline,
|
|
17
|
+
RetrievalPolicy,
|
|
18
|
+
RetrievalResult,
|
|
19
|
+
SessionFilter,
|
|
20
|
+
SimpleWindowCompressor,
|
|
21
|
+
)
|
|
22
|
+
from mark.memory import (
|
|
23
|
+
BlockChain,
|
|
24
|
+
BlockGraph,
|
|
25
|
+
BlockVerification,
|
|
26
|
+
BusMessage,
|
|
27
|
+
BusSnapshot,
|
|
28
|
+
BusSubscription,
|
|
29
|
+
ChainVerification,
|
|
30
|
+
ClusterResult,
|
|
31
|
+
ConversationMemory,
|
|
32
|
+
DeduplicationConsolidator,
|
|
33
|
+
DeduplicationResult,
|
|
34
|
+
GlobalMemoryBus,
|
|
35
|
+
GraphNeighborhood,
|
|
36
|
+
MarkMemory,
|
|
37
|
+
MarkRuntime,
|
|
38
|
+
MemoryBlock,
|
|
39
|
+
MemoryManager,
|
|
40
|
+
MemoryRecord,
|
|
41
|
+
MemoryState,
|
|
42
|
+
MemoryWriteRejection,
|
|
43
|
+
ObserveEvent,
|
|
44
|
+
ObserveResult,
|
|
45
|
+
PublisherTrust,
|
|
46
|
+
SimpleMemory,
|
|
47
|
+
SimpleBlock,
|
|
48
|
+
TrustAwareGlobalMemoryBus,
|
|
49
|
+
)
|
|
50
|
+
from mark.governance import (
|
|
51
|
+
AuditEntry,
|
|
52
|
+
ConsolidationGate,
|
|
53
|
+
ConsolidationGateResult,
|
|
54
|
+
ContentSanitizer,
|
|
55
|
+
DuplicateHashGate,
|
|
56
|
+
FailureFilter,
|
|
57
|
+
GateResult,
|
|
58
|
+
GovernanceAuditLog,
|
|
59
|
+
ValidationGate,
|
|
60
|
+
)
|
|
61
|
+
from mark.intelligence import (
|
|
62
|
+
DeterministicExtractor,
|
|
63
|
+
ExtractionMerger,
|
|
64
|
+
ExtractionResult,
|
|
65
|
+
ExtractedEntity,
|
|
66
|
+
ExtractedRelation,
|
|
67
|
+
LLMStructuredExtractor,
|
|
68
|
+
StructuredExtraction,
|
|
69
|
+
)
|
|
70
|
+
from mark.media import CharacterMemory, LocationMemory, ObjectMemory, SessionMemory, WorldBibleMemory
|
|
71
|
+
from mark.plugins import HOOK_OBSERVE_EVENT
|
|
72
|
+
from mark.policies import PolicyDecision, PolicyRegistry
|
|
73
|
+
from mark.runtime import Mark, MarkConfig
|
|
74
|
+
from mark.skills import AgentPersona, SkillRegistry
|
|
75
|
+
from mark.store import LocalMemoryStore, SessionActivityLog
|
|
76
|
+
from mark.types import BlockLink, BlockStatus
|
|
77
|
+
from mark.types.llm import LLMProvider
|
|
78
|
+
from mark.observability import EventReplayer, LocalTracer, RuntimeEvent, RuntimeEventLog, SessionTrace
|
|
79
|
+
from mark.sync import CloudSync, SyncDelta, SyncMode, SyncOptions, SyncStats
|
|
80
|
+
|
|
81
|
+
__all__ = [
|
|
82
|
+
"AgentResult",
|
|
83
|
+
"AgentPersona",
|
|
84
|
+
"AuditEntry",
|
|
85
|
+
"BlockChain",
|
|
86
|
+
"BlockGraph",
|
|
87
|
+
"BlockLink",
|
|
88
|
+
"BlockStatus",
|
|
89
|
+
"BlockVerification",
|
|
90
|
+
"ChainVerification",
|
|
91
|
+
"BusMessage",
|
|
92
|
+
"BusSnapshot",
|
|
93
|
+
"BusSubscription",
|
|
94
|
+
"CachedEmbeddingProvider",
|
|
95
|
+
"CharacterMemory",
|
|
96
|
+
"ClusterResult",
|
|
97
|
+
"ConsolidationGate",
|
|
98
|
+
"ConsolidationGateResult",
|
|
99
|
+
"ContentSanitizer",
|
|
100
|
+
"ConversationMemory",
|
|
101
|
+
"ContextBuilder",
|
|
102
|
+
"ContextBundle",
|
|
103
|
+
"ContextualCompressor",
|
|
104
|
+
"DeduplicationConsolidator",
|
|
105
|
+
"DeduplicationResult",
|
|
106
|
+
"DeterministicExtractor",
|
|
107
|
+
"DuplicateHashGate",
|
|
108
|
+
"CloudSync",
|
|
109
|
+
"EmbeddingProvider",
|
|
110
|
+
"EventReplayer",
|
|
111
|
+
"FailureFilter",
|
|
112
|
+
"GateResult",
|
|
113
|
+
"GovernanceAuditLog",
|
|
114
|
+
"ExtractionMerger",
|
|
115
|
+
"ExtractionResult",
|
|
116
|
+
"ExtractedEntity",
|
|
117
|
+
"ExtractedRelation",
|
|
118
|
+
"GlobalMemoryBus",
|
|
119
|
+
"GraphNeighborhood",
|
|
120
|
+
"HashEmbeddingProvider",
|
|
121
|
+
"HOOK_OBSERVE_EVENT",
|
|
122
|
+
"KeywordQueryExpander",
|
|
123
|
+
"LLMContextualCompressor",
|
|
124
|
+
"LLMProvider",
|
|
125
|
+
"LLMQueryExpander",
|
|
126
|
+
"LLMStructuredExtractor",
|
|
127
|
+
"LocalMemoryStore",
|
|
128
|
+
"LocalTracer",
|
|
129
|
+
"LocationMemory",
|
|
130
|
+
"Mark",
|
|
131
|
+
"MarkAgent",
|
|
132
|
+
"MarkConfig",
|
|
133
|
+
"MarkMemory",
|
|
134
|
+
"MarkRuntime",
|
|
135
|
+
"MemoryBlock",
|
|
136
|
+
"MemoryManager",
|
|
137
|
+
"MemoryRecord",
|
|
138
|
+
"MemoryState",
|
|
139
|
+
"MemoryWriteRejection",
|
|
140
|
+
"NoopCompressor",
|
|
141
|
+
"NoopQueryExpander",
|
|
142
|
+
"ObjectMemory",
|
|
143
|
+
"ObserveEvent",
|
|
144
|
+
"ObserveResult",
|
|
145
|
+
"PolicyDecision",
|
|
146
|
+
"PolicyRegistry",
|
|
147
|
+
"PublisherTrust",
|
|
148
|
+
"QueryExpander",
|
|
149
|
+
"RetrievalPipeline",
|
|
150
|
+
"RuntimeEvent",
|
|
151
|
+
"RuntimeEventLog",
|
|
152
|
+
"RetrievalPolicy",
|
|
153
|
+
"RetrievalResult",
|
|
154
|
+
"SessionActivityLog",
|
|
155
|
+
"SessionTrace",
|
|
156
|
+
"SyncMode",
|
|
157
|
+
"SyncDelta",
|
|
158
|
+
"SyncOptions",
|
|
159
|
+
"SyncStats",
|
|
160
|
+
"SessionFilter",
|
|
161
|
+
"SessionMemory",
|
|
162
|
+
"SimpleBlock",
|
|
163
|
+
"SimpleMemory",
|
|
164
|
+
"SimpleWindowCompressor",
|
|
165
|
+
"StructuredExtraction",
|
|
166
|
+
"SkillRegistry",
|
|
167
|
+
"TrustAwareGlobalMemoryBus",
|
|
168
|
+
"ValidationGate",
|
|
169
|
+
"VectorIndex",
|
|
170
|
+
"VectorSearchResult",
|
|
171
|
+
"WorldBibleMemory",
|
|
172
|
+
"__version__",
|
|
173
|
+
]
|
mark/_version.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Optional framework adapters bundled with mark-sdk.
|
|
2
|
+
|
|
3
|
+
The adapter namespace is MIT framework glue. It must call public MARK APIs and
|
|
4
|
+
must not implement proprietary MARK Cloud intelligence.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from mark.adapters.backend import BackendResult, LocalMarkBackend, MarkBackend
|
|
8
|
+
|
|
9
|
+
__all__ = ["BackendResult", "LocalMarkBackend", "MarkBackend"]
|
mark/adapters/backend.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Framework-neutral backend protocol for MARK adapters."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
from dataclasses import dataclass, field
|
|
7
|
+
from typing import Any, Protocol
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass(frozen=True)
|
|
11
|
+
class BackendResult:
|
|
12
|
+
"""Small framework-neutral result envelope used by adapter helpers."""
|
|
13
|
+
|
|
14
|
+
ok: bool
|
|
15
|
+
value: Any = None
|
|
16
|
+
metadata: dict[str, Any] = field(default_factory=dict)
|
|
17
|
+
error: str | None = None
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class MarkBackend(Protocol):
|
|
21
|
+
"""Public backend protocol implemented by local and cloud MARK adapters."""
|
|
22
|
+
|
|
23
|
+
async def retrieve(self, query: str, **options: Any) -> BackendResult:
|
|
24
|
+
"""Retrieve memory relevant to the query."""
|
|
25
|
+
...
|
|
26
|
+
async def write(self, content: str, **options: Any) -> BackendResult:
|
|
27
|
+
"""Write content into memory."""
|
|
28
|
+
...
|
|
29
|
+
async def observe(self, content: str, **options: Any) -> BackendResult:
|
|
30
|
+
"""Record an observation through the backend."""
|
|
31
|
+
...
|
|
32
|
+
async def compress(self, query: str, candidates: list[Any], **options: Any) -> BackendResult:
|
|
33
|
+
"""Reduce candidate fragments to query-relevant evidence."""
|
|
34
|
+
...
|
|
35
|
+
async def heal_gap(self, query: str, **options: Any) -> BackendResult:
|
|
36
|
+
"""Attempt explicit gap healing for the query."""
|
|
37
|
+
...
|
|
38
|
+
async def list_sessions(self, agent_id: str, **options: Any) -> BackendResult:
|
|
39
|
+
"""Return known session ids for the agent."""
|
|
40
|
+
...
|
|
41
|
+
async def feedback(self, **payload: Any) -> BackendResult:
|
|
42
|
+
"""Submit a feedback signal."""
|
|
43
|
+
...
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class LocalMarkBackend:
|
|
47
|
+
"""Adapter backend over local ``mark.Mark`` or ``mark.MarkRuntime`` objects."""
|
|
48
|
+
|
|
49
|
+
def __init__(self, mark: Any, *, default_agent_id: str = "__mark__") -> None:
|
|
50
|
+
self.mark = mark
|
|
51
|
+
self.default_agent_id = default_agent_id
|
|
52
|
+
|
|
53
|
+
async def retrieve(self, query: str, **options: Any) -> BackendResult:
|
|
54
|
+
"""Retrieve memory relevant to the query."""
|
|
55
|
+
try:
|
|
56
|
+
memory = self._memory(options.pop("agent_id", self.default_agent_id))
|
|
57
|
+
options.pop("blocks", None) # MarkMemory.retrieve_sync does not accept blocks
|
|
58
|
+
if hasattr(memory, "retrieve_sync"):
|
|
59
|
+
result = memory.retrieve_sync(query, **options)
|
|
60
|
+
return BackendResult(True, result)
|
|
61
|
+
result = self.mark.memory.retrieve(query, **options)
|
|
62
|
+
return BackendResult(True, result)
|
|
63
|
+
except Exception as exc:
|
|
64
|
+
return BackendResult(False, error=str(exc))
|
|
65
|
+
|
|
66
|
+
async def write(self, content: str, **options: Any) -> BackendResult:
|
|
67
|
+
"""Write content into memory."""
|
|
68
|
+
try:
|
|
69
|
+
memory = self._memory(options.pop("agent_id", self.default_agent_id))
|
|
70
|
+
if hasattr(memory, "store_sync"):
|
|
71
|
+
fragment_id = memory.store_sync(content, **options)
|
|
72
|
+
return BackendResult(True, fragment_id, {"fragment_id": fragment_id})
|
|
73
|
+
block = self.mark.memory.block(options.pop("block", "adapter"))
|
|
74
|
+
record = block.write(content, **options)
|
|
75
|
+
return BackendResult(True, record, {"record_id": getattr(record, "id", "")})
|
|
76
|
+
except Exception as exc:
|
|
77
|
+
return BackendResult(False, error=str(exc))
|
|
78
|
+
|
|
79
|
+
async def observe(self, content: str, **options: Any) -> BackendResult:
|
|
80
|
+
"""Record an observation through the backend."""
|
|
81
|
+
try:
|
|
82
|
+
agent_id = options.pop("agent_id", self.default_agent_id)
|
|
83
|
+
if hasattr(self.mark, "observe"):
|
|
84
|
+
result = self.mark.observe(content, agent_id=agent_id, **options)
|
|
85
|
+
else:
|
|
86
|
+
result = self._memory(agent_id).observe(content, **options)
|
|
87
|
+
return BackendResult(True, result, {"fragment_id": getattr(result, "fragment_id", "")})
|
|
88
|
+
except Exception as exc:
|
|
89
|
+
return BackendResult(False, error=str(exc))
|
|
90
|
+
|
|
91
|
+
async def compress(self, query: str, candidates: list[Any], **options: Any) -> BackendResult:
|
|
92
|
+
# Local compression is performed during retrieve(compress=True). This method
|
|
93
|
+
# exists so framework adapters can share a protocol with cloud backends.
|
|
94
|
+
"""Reduce candidate fragments to query-relevant evidence."""
|
|
95
|
+
return BackendResult(True, candidates, {"local_passthrough": True, "query": query, **options})
|
|
96
|
+
|
|
97
|
+
async def heal_gap(self, query: str, **options: Any) -> BackendResult:
|
|
98
|
+
"""Attempt explicit gap healing for the query."""
|
|
99
|
+
options["heal_gaps"] = True
|
|
100
|
+
return await self.retrieve(query, **options)
|
|
101
|
+
|
|
102
|
+
async def list_sessions(self, agent_id: str, **options: Any) -> BackendResult:
|
|
103
|
+
"""Return known session ids for the agent."""
|
|
104
|
+
try:
|
|
105
|
+
memory = self._memory(agent_id)
|
|
106
|
+
if hasattr(memory, "list_sessions"):
|
|
107
|
+
return BackendResult(True, memory.list_sessions())
|
|
108
|
+
return BackendResult(True, [])
|
|
109
|
+
except Exception as exc:
|
|
110
|
+
return BackendResult(False, error=str(exc))
|
|
111
|
+
|
|
112
|
+
async def feedback(self, **payload: Any) -> BackendResult:
|
|
113
|
+
"""Submit a feedback signal."""
|
|
114
|
+
try:
|
|
115
|
+
if hasattr(self.mark, "memory") and hasattr(self.mark.memory, "feedback"):
|
|
116
|
+
feedback = self.mark.memory.feedback
|
|
117
|
+
params = inspect.signature(feedback).parameters
|
|
118
|
+
if all(key in params for key in payload):
|
|
119
|
+
feedback(**payload)
|
|
120
|
+
return BackendResult(True, payload)
|
|
121
|
+
return BackendResult(True, payload, {"skipped": "incompatible_feedback_signature"})
|
|
122
|
+
return BackendResult(True, payload, {"skipped": "feedback_unavailable"})
|
|
123
|
+
except Exception as exc:
|
|
124
|
+
return BackendResult(False, error=str(exc))
|
|
125
|
+
|
|
126
|
+
def _memory(self, agent_id: str) -> Any:
|
|
127
|
+
if hasattr(self.mark, "runtime") and hasattr(self.mark.runtime, "memory"):
|
|
128
|
+
return self.mark.runtime.memory(agent_id)
|
|
129
|
+
if hasattr(self.mark, "memory") and callable(self.mark.memory):
|
|
130
|
+
return self.mark.memory(agent_id)
|
|
131
|
+
return self.mark.memory
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""LangChain adapters for MARK.
|
|
2
|
+
|
|
3
|
+
Install optional dependencies with ``pip install "mark-sdk[langchain]"``.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from mark.adapters.langchain.middleware import MarkAgentMiddleware, MarkMemoryMiddleware
|
|
7
|
+
|
|
8
|
+
__all__ = ["MarkAgentMiddleware", "MarkMemoryMiddleware", "create_mark_tools"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def create_mark_tools(*args, **kwargs):
|
|
12
|
+
"""Create LangChain tools backed by a MARK backend."""
|
|
13
|
+
from mark.adapters.langchain.tools import create_mark_tools as _create_mark_tools
|
|
14
|
+
|
|
15
|
+
return _create_mark_tools(*args, **kwargs)
|