memoryking 0.1.0__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.
- memoryking/__init__.py +3 -0
- memoryking/__main__.py +1328 -0
- memoryking/adapters/__init__.py +1 -0
- memoryking/adapters/adapter_state.py +242 -0
- memoryking/adapters/anchor_schema.sql +7 -0
- memoryking/adapters/atlas.py +441 -0
- memoryking/adapters/browser_commands.py +125 -0
- memoryking/adapters/dashboard.py +510 -0
- memoryking/adapters/dense_search.py +86 -0
- memoryking/adapters/egress_policy.py +244 -0
- memoryking/adapters/egress_schema.sql +13 -0
- memoryking/adapters/embedding.schema.json +302 -0
- memoryking/adapters/embedding_store.py +469 -0
- memoryking/adapters/execution.py +369 -0
- memoryking/adapters/experience.py +423 -0
- memoryking/adapters/experience.schema.json +1508 -0
- memoryking/adapters/experience_records.py +239 -0
- memoryking/adapters/experience_schema.sql +23 -0
- memoryking/adapters/handoff.py +494 -0
- memoryking/adapters/handoff.schema.json +299 -0
- memoryking/adapters/handoff_schema.sql +17 -0
- memoryking/adapters/index_schema.sql +11 -0
- memoryking/adapters/inference.py +454 -0
- memoryking/adapters/inference.schema.json +541 -0
- memoryking/adapters/inspection.py +1128 -0
- memoryking/adapters/inspection.schema.json +568 -0
- memoryking/adapters/knowledge.schema.json +633 -0
- memoryking/adapters/knowledge_schema.sql +37 -0
- memoryking/adapters/knowledge_store.py +800 -0
- memoryking/adapters/legacy_snapshot.py +358 -0
- memoryking/adapters/legacy_tables.py +49 -0
- memoryking/adapters/local_contract.py +45 -0
- memoryking/adapters/local_embeddings.py +189 -0
- memoryking/adapters/local_files.py +242 -0
- memoryking/adapters/local_ipc.py +258 -0
- memoryking/adapters/local_schema.sql +44 -0
- memoryking/adapters/local_store.py +632 -0
- memoryking/adapters/local_wire.schema.json +7672 -0
- memoryking/adapters/models/minilm-l6-v2-onnx.json +57 -0
- memoryking/adapters/models/ms-marco-minilm-l6-v2-onnx.json +57 -0
- memoryking/adapters/optional_schema.sql +43 -0
- memoryking/adapters/plan_dashboard.py +51 -0
- memoryking/adapters/plans.py +253 -0
- memoryking/adapters/postgres_admin.py +300 -0
- memoryking/adapters/postgres_anchor_schema.sql +9 -0
- memoryking/adapters/postgres_counter.sql +14 -0
- memoryking/adapters/postgres_egress_schema.sql +15 -0
- memoryking/adapters/postgres_experience_schema.sql +39 -0
- memoryking/adapters/postgres_index_schema.sql +7 -0
- memoryking/adapters/postgres_optional_schema.sql +71 -0
- memoryking/adapters/postgres_pool.py +77 -0
- memoryking/adapters/postgres_recovery.py +525 -0
- memoryking/adapters/postgres_schema.sql +365 -0
- memoryking/adapters/postgres_sql.py +102 -0
- memoryking/adapters/postgres_store.py +428 -0
- memoryking/adapters/postgres_summary_schema.sql +12 -0
- memoryking/adapters/postgres_trust_schema.sql +20 -0
- memoryking/adapters/processing.schema.json +471 -0
- memoryking/adapters/processing_store.py +346 -0
- memoryking/adapters/projects.py +83 -0
- memoryking/adapters/proposals.py +238 -0
- memoryking/adapters/ranking.py +315 -0
- memoryking/adapters/repository.schema.json +664 -0
- memoryking/adapters/repository_git.py +264 -0
- memoryking/adapters/repository_schema.sql +25 -0
- memoryking/adapters/repository_store.py +960 -0
- memoryking/adapters/retrieval.py +1285 -0
- memoryking/adapters/retrieval.schema.json +553 -0
- memoryking/adapters/retrieval_schema.sql +10 -0
- memoryking/adapters/shared_control.py +40 -0
- memoryking/adapters/shared_dashboard.py +636 -0
- memoryking/adapters/shared_gateway.py +63 -0
- memoryking/adapters/shared_http.py +216 -0
- memoryking/adapters/shared_mcp.py +159 -0
- memoryking/adapters/shared_service.py +124 -0
- memoryking/adapters/stdio.py +193 -0
- memoryking/adapters/stdio.tools.json +6776 -0
- memoryking/adapters/summary_schema.sql +10 -0
- memoryking/adapters/team.py +253 -0
- memoryking/adapters/timeline.py +80 -0
- memoryking/adapters/token_count.py +55 -0
- memoryking/adapters/tokenizers/LICENSE +21 -0
- memoryking/adapters/tokenizers/cl100k_base.tiktoken +100256 -0
- memoryking/adapters/trust.py +123 -0
- memoryking/adapters/trust_schema.sql +13 -0
- memoryking/adapters/web/app.css +1251 -0
- memoryking/adapters/web/app.js +907 -0
- memoryking/adapters/web/brand.js +44 -0
- memoryking/adapters/web/crown-mono.svg +1 -0
- memoryking/adapters/web/crown.svg +8 -0
- memoryking/adapters/web/elephant.png +0 -0
- memoryking/adapters/web/favicon.svg +8 -0
- memoryking/adapters/web/graph-layout.js +52 -0
- memoryking/adapters/web/graph-worker.js +10 -0
- memoryking/adapters/web/graph.js +570 -0
- memoryking/adapters/web/index.html +208 -0
- memoryking/adapters/web/observatory.js +1208 -0
- memoryking/adapters/web/team.js +151 -0
- memoryking/adapters/web/wordmark.svg +1 -0
- memoryking/adapters/working.py +971 -0
- memoryking/adapters/working.schema.json +1717 -0
- memoryking/adapters/working_schema.sql +24 -0
- memoryking/application/__init__.py +1 -0
- memoryking/application/conformance.py +50 -0
- memoryking/application/legacy_import.py +337 -0
- memoryking/application/local_port.py +9 -0
- memoryking/application/storage.py +117 -0
- memoryking/application/store_core.py +1292 -0
- memoryking/backups.py +131 -0
- memoryking/contracts/__init__.py +6 -0
- memoryking/contracts/__main__.py +20 -0
- memoryking/contracts/canonical.py +88 -0
- memoryking/contracts/embedding.schema.json +302 -0
- memoryking/contracts/embedding_generated.py +65 -0
- memoryking/contracts/experience.schema.json +1508 -0
- memoryking/contracts/experience_generated.py +239 -0
- memoryking/contracts/generated.py +122 -0
- memoryking/contracts/handoff.schema.json +299 -0
- memoryking/contracts/handoff_generated.py +69 -0
- memoryking/contracts/inference.schema.json +541 -0
- memoryking/contracts/inference_generated.py +106 -0
- memoryking/contracts/processing.schema.json +471 -0
- memoryking/contracts/processing_generated.py +82 -0
- memoryking/contracts/py.typed +0 -0
- memoryking/contracts/repository.schema.json +664 -0
- memoryking/contracts/repository_generated.py +144 -0
- memoryking/contracts/retrieval.schema.json +553 -0
- memoryking/contracts/retrieval_generated.py +110 -0
- memoryking/contracts/schema.json +696 -0
- memoryking/contracts/validation.py +92 -0
- memoryking/contracts/working.schema.json +1717 -0
- memoryking/contracts/working_generated.py +291 -0
- memoryking/domain/__init__.py +1 -0
- memoryking/domain/anchors.py +97 -0
- memoryking/domain/briefing.py +108 -0
- memoryking/domain/briefing_text.py +222 -0
- memoryking/domain/checkpoint.py +118 -0
- memoryking/domain/compression.py +64 -0
- memoryking/domain/delta.py +129 -0
- memoryking/domain/embeddings.py +90 -0
- memoryking/domain/hints.py +465 -0
- memoryking/domain/http_status.py +45 -0
- memoryking/domain/learning.py +62 -0
- memoryking/domain/local.py +65 -0
- memoryking/domain/plans.py +140 -0
- memoryking/domain/repository.py +118 -0
- memoryking/domain/selectors.py +356 -0
- memoryking/domain/summary.py +88 -0
- memoryking/domain/usage.py +163 -0
- memoryking/embedding_loop.py +98 -0
- memoryking/embedding_worker.py +131 -0
- memoryking/harness.py +882 -0
- memoryking/harness_context.py +376 -0
- memoryking/hooks.py +171 -0
- memoryking/host_hooks.py +454 -0
- memoryking/lean.py +352 -0
- memoryking/memory_tool.py +776 -0
- memoryking/migration.py +194 -0
- memoryking/model_install.py +78 -0
- memoryking/observability.py +101 -0
- memoryking/observability_metrics.py +100 -0
- memoryking/profiles.py +150 -0
- memoryking/providers.py +330 -0
- memoryking/py.typed +0 -0
- memoryking/pytest_plugin.py +69 -0
- memoryking/reference_agent.py +152 -0
- memoryking/repository_worker.py +57 -0
- memoryking/resume_adapter.py +154 -0
- memoryking/sdk.py +302 -0
- memoryking/shared.py +301 -0
- memoryking/shared_sdk.py +101 -0
- memoryking/vault.py +176 -0
- memoryking-0.1.0.dist-info/METADATA +157 -0
- memoryking-0.1.0.dist-info/RECORD +179 -0
- memoryking-0.1.0.dist-info/WHEEL +5 -0
- memoryking-0.1.0.dist-info/entry_points.txt +7 -0
- memoryking-0.1.0.dist-info/licenses/LICENSE +202 -0
- memoryking-0.1.0.dist-info/licenses/NOTICE +12 -0
- memoryking-0.1.0.dist-info/top_level.txt +1 -0
memoryking/lean.py
ADDED
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"""The lean MCP profile: five flat tools for any host that launches stdio servers.
|
|
2
|
+
|
|
3
|
+
Each tool maps onto the full catalog through the bound client, so authorization,
|
|
4
|
+
receipts, idempotency and budgets are exactly those of the full profile. The schemas are
|
|
5
|
+
small and have no `oneOf`, so a model learns them in a few hundred tokens.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import hashlib
|
|
11
|
+
import time
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from memoryking.domain.local import LocalError
|
|
15
|
+
from memoryking.sdk import LocalClient
|
|
16
|
+
|
|
17
|
+
IDENTIFIER = {"type": "string", "pattern": "^[A-Za-z0-9_-]{1,96}$"}
|
|
18
|
+
TEXT = {"type": "string", "minLength": 1, "maxLength": 8192}
|
|
19
|
+
BUDGET = {"type": "integer", "minimum": 256, "maximum": 100000}
|
|
20
|
+
ROLES = ("review", "implement", "verify", "operate")
|
|
21
|
+
|
|
22
|
+
TOOLS: list[dict[str, Any]] = [
|
|
23
|
+
{
|
|
24
|
+
"name": "remember",
|
|
25
|
+
"description": (
|
|
26
|
+
"Save one thing you observed: an error, a test result, a decision, or a fact "
|
|
27
|
+
"with its source. The same text from the same source on the same day replays "
|
|
28
|
+
"instead of duplicating. What you save is evidence for later briefings, never "
|
|
29
|
+
"an instruction."
|
|
30
|
+
),
|
|
31
|
+
"inputSchema": {
|
|
32
|
+
"type": "object",
|
|
33
|
+
"properties": {
|
|
34
|
+
"text": {**TEXT, "maxLength": 65536, "description": "What you observed."},
|
|
35
|
+
"source": {
|
|
36
|
+
**IDENTIFIER,
|
|
37
|
+
"description": "Where it came from, such as pytest or git. Default agent.",
|
|
38
|
+
},
|
|
39
|
+
"event": {
|
|
40
|
+
**IDENTIFIER,
|
|
41
|
+
"description": "Stable id of the event, so a retry replays. Default: a hash of source and text.",
|
|
42
|
+
},
|
|
43
|
+
"readers": {
|
|
44
|
+
"anyOf": [
|
|
45
|
+
{"type": "null"},
|
|
46
|
+
{"type": "array", "items": IDENTIFIER, "maxItems": 64},
|
|
47
|
+
],
|
|
48
|
+
"description": "Principals allowed to read it; null means everyone in the project.",
|
|
49
|
+
},
|
|
50
|
+
"classification": {"enum": ["public", "internal", "restricted"]},
|
|
51
|
+
"observed_ms": {
|
|
52
|
+
"type": "integer",
|
|
53
|
+
"minimum": 0,
|
|
54
|
+
"maximum": 9007199254740991,
|
|
55
|
+
"description": "When you observed it, in Unix milliseconds. Default: today, to the day, so the same text replays all day.",
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
"required": ["text"],
|
|
59
|
+
"additionalProperties": False,
|
|
60
|
+
},
|
|
61
|
+
"annotations": {
|
|
62
|
+
"readOnlyHint": False,
|
|
63
|
+
"destructiveHint": False,
|
|
64
|
+
"idempotentHint": True,
|
|
65
|
+
"openWorldHint": False,
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
"name": "recall",
|
|
70
|
+
"description": (
|
|
71
|
+
"Get a briefing before you start: constraints you must follow, then ranked "
|
|
72
|
+
"guidance with [g1]-style citations and a Sources footer, as Markdown. Read the "
|
|
73
|
+
"status line first; blocked means decide, not truncate."
|
|
74
|
+
),
|
|
75
|
+
"inputSchema": {
|
|
76
|
+
"type": "object",
|
|
77
|
+
"properties": {
|
|
78
|
+
"query": {
|
|
79
|
+
**TEXT,
|
|
80
|
+
"maxLength": 2048,
|
|
81
|
+
"description": "What you are about to work on.",
|
|
82
|
+
},
|
|
83
|
+
"budget": {**BUDGET, "description": "Token budget for the briefing. Default 6000."},
|
|
84
|
+
"task": {
|
|
85
|
+
**IDENTIFIER,
|
|
86
|
+
"description": "Task id, when the briefing is for a specific task.",
|
|
87
|
+
},
|
|
88
|
+
"as_of": {
|
|
89
|
+
**TEXT,
|
|
90
|
+
"maxLength": 40,
|
|
91
|
+
"description": "Brief as the project stood then: a date (YYYY-MM-DD) or ISO "
|
|
92
|
+
"date-time. Omit for now.",
|
|
93
|
+
},
|
|
94
|
+
"salience": {
|
|
95
|
+
"type": "boolean",
|
|
96
|
+
"description": "Let your own recent use of memories nudge the ranking "
|
|
97
|
+
"(bounded, reported per item). Default false.",
|
|
98
|
+
},
|
|
99
|
+
"rerank": {
|
|
100
|
+
"type": "boolean",
|
|
101
|
+
"description": "Let the service's local cross-encoder reorder the top "
|
|
102
|
+
"candidates by relevance to the query, when one is installed (reported "
|
|
103
|
+
"per item). Default false.",
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
"required": ["query"],
|
|
107
|
+
"additionalProperties": False,
|
|
108
|
+
},
|
|
109
|
+
"annotations": {"readOnlyHint": True, "openWorldHint": False},
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "save_progress",
|
|
113
|
+
"description": (
|
|
114
|
+
"Save where a task stands before you stop or hand over. Objective and current "
|
|
115
|
+
"state are enough; add next actions, findings, failed attempts and blockers as "
|
|
116
|
+
"you have them. Sections you leave out are recorded as gaps, not as empty facts."
|
|
117
|
+
),
|
|
118
|
+
"inputSchema": {
|
|
119
|
+
"type": "object",
|
|
120
|
+
"properties": {
|
|
121
|
+
"task": {**IDENTIFIER, "description": "Task id, stable across sessions."},
|
|
122
|
+
"objective": TEXT,
|
|
123
|
+
"current_state": TEXT,
|
|
124
|
+
"next_actions": {"type": "array", "items": TEXT, "maxItems": 32},
|
|
125
|
+
"findings": {"type": "array", "items": TEXT, "maxItems": 32},
|
|
126
|
+
"failed_attempts": {
|
|
127
|
+
"type": "array",
|
|
128
|
+
"maxItems": 32,
|
|
129
|
+
"items": {
|
|
130
|
+
"type": "object",
|
|
131
|
+
"properties": {"action": TEXT, "outcome": TEXT, "do_not_repeat_when": TEXT},
|
|
132
|
+
"required": ["action", "outcome"],
|
|
133
|
+
"additionalProperties": False,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
"blockers": {"type": "array", "items": TEXT, "maxItems": 32},
|
|
137
|
+
"hard_constraints": {"type": "array", "items": TEXT, "maxItems": 32},
|
|
138
|
+
"run": {
|
|
139
|
+
"anyOf": [IDENTIFIER, {"type": "null"}],
|
|
140
|
+
"description": "Run id within the task, or null.",
|
|
141
|
+
},
|
|
142
|
+
"share_with": {
|
|
143
|
+
"type": "array",
|
|
144
|
+
"items": IDENTIFIER,
|
|
145
|
+
"maxItems": 31,
|
|
146
|
+
"uniqueItems": True,
|
|
147
|
+
"description": "Other principals who may read this task's progress, such as a reviewer you will hand off to. Omit it to keep the readers from the previous save.",
|
|
148
|
+
},
|
|
149
|
+
},
|
|
150
|
+
"required": ["task", "objective", "current_state"],
|
|
151
|
+
"additionalProperties": False,
|
|
152
|
+
},
|
|
153
|
+
"annotations": {
|
|
154
|
+
"readOnlyHint": False,
|
|
155
|
+
"destructiveHint": False,
|
|
156
|
+
"idempotentHint": False,
|
|
157
|
+
"openWorldHint": False,
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
"name": "resume",
|
|
162
|
+
"description": (
|
|
163
|
+
"Pick up a task from its latest saved progress: a Markdown handover note with "
|
|
164
|
+
"where it stands, next actions, what not to repeat, blockers, open operations "
|
|
165
|
+
"and the gaps that were never written down."
|
|
166
|
+
),
|
|
167
|
+
"inputSchema": {
|
|
168
|
+
"type": "object",
|
|
169
|
+
"properties": {
|
|
170
|
+
"task": IDENTIFIER,
|
|
171
|
+
"run": {"anyOf": [IDENTIFIER, {"type": "null"}]},
|
|
172
|
+
"budget": {**BUDGET, "description": "Token budget. Default 12000."},
|
|
173
|
+
},
|
|
174
|
+
"required": ["task"],
|
|
175
|
+
"additionalProperties": False,
|
|
176
|
+
},
|
|
177
|
+
"annotations": {"readOnlyHint": True, "openWorldHint": False},
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"name": "hand_off",
|
|
181
|
+
"description": (
|
|
182
|
+
"Pass a task's latest saved progress to another principal under their current "
|
|
183
|
+
"permissions. The recipient must already be among the task's readers "
|
|
184
|
+
"(save_progress share_with); anything they may not read is left out and "
|
|
185
|
+
"reported, and access is never widened."
|
|
186
|
+
),
|
|
187
|
+
"inputSchema": {
|
|
188
|
+
"type": "object",
|
|
189
|
+
"properties": {
|
|
190
|
+
"task": IDENTIFIER,
|
|
191
|
+
"to": {**IDENTIFIER, "description": "The recipient principal."},
|
|
192
|
+
"role": {"enum": list(ROLES), "description": "Default review."},
|
|
193
|
+
"stage": {**IDENTIFIER, "description": "Default handoff."},
|
|
194
|
+
"ttl_minutes": {
|
|
195
|
+
"type": "integer",
|
|
196
|
+
"minimum": 1,
|
|
197
|
+
"maximum": 1440,
|
|
198
|
+
"description": "Default 60.",
|
|
199
|
+
},
|
|
200
|
+
"run": {"anyOf": [IDENTIFIER, {"type": "null"}]},
|
|
201
|
+
},
|
|
202
|
+
"required": ["task", "to"],
|
|
203
|
+
"additionalProperties": False,
|
|
204
|
+
},
|
|
205
|
+
"annotations": {
|
|
206
|
+
"readOnlyHint": False,
|
|
207
|
+
"destructiveHint": False,
|
|
208
|
+
"idempotentHint": False,
|
|
209
|
+
"openWorldHint": False,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
]
|
|
213
|
+
|
|
214
|
+
CATALOG: dict[str, Any] = {"protocol_version": "2025-11-25", "transport": "stdio", "tools": TOOLS}
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
DAY_MS = 86_400_000
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
def _event(source: str, text: str, observed_ms: int, project: str) -> str:
|
|
221
|
+
return (
|
|
222
|
+
"ev-"
|
|
223
|
+
+ hashlib.sha256(f"{source}\n{project}\n{observed_ms}\n{text}".encode()).hexdigest()[:40]
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def call(client: LocalClient, name: str, arguments: dict[str, Any]) -> dict[str, Any]:
|
|
228
|
+
"""Run a lean tool through the full-profile client."""
|
|
229
|
+
if name == "remember":
|
|
230
|
+
source = arguments.get("source", "agent")
|
|
231
|
+
# Replay needs identical bytes, so the default observed time is the day, not the
|
|
232
|
+
# millisecond, and the derived event id folds the day in; the store's own event
|
|
233
|
+
# log keeps the exact time of the capture.
|
|
234
|
+
observed = arguments.get("observed_ms")
|
|
235
|
+
if observed is None:
|
|
236
|
+
observed = int(time.time() * 1000) // DAY_MS * DAY_MS
|
|
237
|
+
event = arguments.get("event") or _event(
|
|
238
|
+
source, arguments["text"], observed, client.project
|
|
239
|
+
)
|
|
240
|
+
return client.tool(
|
|
241
|
+
"memory_capture",
|
|
242
|
+
{
|
|
243
|
+
"key": event,
|
|
244
|
+
"request": {
|
|
245
|
+
"source": source,
|
|
246
|
+
"source_event": event,
|
|
247
|
+
"text": arguments["text"],
|
|
248
|
+
"readers": arguments.get("readers"),
|
|
249
|
+
"classification": arguments.get("classification", "internal"),
|
|
250
|
+
"observed_at_ms": observed,
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
)
|
|
254
|
+
if name == "recall":
|
|
255
|
+
args: dict[str, Any] = {
|
|
256
|
+
"query": arguments["query"],
|
|
257
|
+
"max_output_tokens": arguments.get("budget", 6000),
|
|
258
|
+
"format": "text",
|
|
259
|
+
}
|
|
260
|
+
if "task" in arguments:
|
|
261
|
+
args["task"] = arguments["task"]
|
|
262
|
+
if "as_of" in arguments:
|
|
263
|
+
from memoryking.hooks import as_of_ms
|
|
264
|
+
|
|
265
|
+
args["as_of_ms"] = as_of_ms(arguments["as_of"])
|
|
266
|
+
if arguments.get("salience"):
|
|
267
|
+
args["salience"] = "on"
|
|
268
|
+
if arguments.get("rerank"):
|
|
269
|
+
args["rerank"] = "on"
|
|
270
|
+
return client.tool("memory_brief", {"action": "brief", "args": args})
|
|
271
|
+
if name == "save_progress":
|
|
272
|
+
principal = client.binding[2]
|
|
273
|
+
checkpoint: dict[str, Any] = {
|
|
274
|
+
"objective": arguments["objective"],
|
|
275
|
+
"current_state": arguments["current_state"],
|
|
276
|
+
}
|
|
277
|
+
if "next_actions" in arguments:
|
|
278
|
+
checkpoint["next_actions"] = arguments["next_actions"]
|
|
279
|
+
if "hard_constraints" in arguments:
|
|
280
|
+
checkpoint["hard_constraints"] = arguments["hard_constraints"]
|
|
281
|
+
if "findings" in arguments:
|
|
282
|
+
checkpoint["findings"] = [
|
|
283
|
+
{"text": text, "kind": "note", "evidence": []} for text in arguments["findings"]
|
|
284
|
+
]
|
|
285
|
+
if "failed_attempts" in arguments:
|
|
286
|
+
checkpoint["failed_attempts"] = [
|
|
287
|
+
{
|
|
288
|
+
"action": item["action"],
|
|
289
|
+
"outcome": item["outcome"],
|
|
290
|
+
"do_not_repeat_when": item.get(
|
|
291
|
+
"do_not_repeat_when", "conditions are unchanged"
|
|
292
|
+
),
|
|
293
|
+
}
|
|
294
|
+
for item in arguments["failed_attempts"]
|
|
295
|
+
]
|
|
296
|
+
if "blockers" in arguments:
|
|
297
|
+
checkpoint["blockers"] = [
|
|
298
|
+
{"text": text, "owner": principal} for text in arguments["blockers"]
|
|
299
|
+
]
|
|
300
|
+
save_args: dict[str, Any] = {
|
|
301
|
+
"task": arguments["task"],
|
|
302
|
+
"run": arguments.get("run"),
|
|
303
|
+
"checkpoint": checkpoint,
|
|
304
|
+
}
|
|
305
|
+
if arguments.get("share_with"):
|
|
306
|
+
save_args["readers"] = sorted({principal, *arguments["share_with"]})
|
|
307
|
+
return client.tool("memory_checkpoint", {"action": "save", "args": save_args})
|
|
308
|
+
if name == "resume":
|
|
309
|
+
return client.tool(
|
|
310
|
+
"memory_resume",
|
|
311
|
+
{
|
|
312
|
+
"action": "resume",
|
|
313
|
+
"args": {
|
|
314
|
+
"task": arguments["task"],
|
|
315
|
+
"run": arguments.get("run"),
|
|
316
|
+
"checkpoint": None,
|
|
317
|
+
"max_output_tokens": arguments.get("budget", 12000),
|
|
318
|
+
"format": "text",
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
)
|
|
322
|
+
if name == "hand_off":
|
|
323
|
+
latest = client.tool(
|
|
324
|
+
"memory_resume",
|
|
325
|
+
{
|
|
326
|
+
"action": "resume",
|
|
327
|
+
"args": {
|
|
328
|
+
"task": arguments["task"],
|
|
329
|
+
"run": arguments.get("run"),
|
|
330
|
+
"checkpoint": None,
|
|
331
|
+
"max_output_tokens": 2048,
|
|
332
|
+
},
|
|
333
|
+
},
|
|
334
|
+
)
|
|
335
|
+
if not latest.get("checkpoint"):
|
|
336
|
+
raise LocalError("checkpoint_unavailable")
|
|
337
|
+
return client.tool(
|
|
338
|
+
"memory_handoff",
|
|
339
|
+
{
|
|
340
|
+
"action": "prepare",
|
|
341
|
+
"args": {
|
|
342
|
+
"task": arguments["task"],
|
|
343
|
+
"run": arguments.get("run"),
|
|
344
|
+
"checkpoint": latest["checkpoint"]["id"],
|
|
345
|
+
"recipient": arguments["to"],
|
|
346
|
+
"role": arguments.get("role", "review"),
|
|
347
|
+
"stage": arguments.get("stage", "handoff"),
|
|
348
|
+
"ttl_ms": arguments.get("ttl_minutes", 60) * 60_000,
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
)
|
|
352
|
+
raise LocalError("unknown_tool")
|