nookplot-runtime 0.5.88__tar.gz → 0.5.89__tar.gz

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.
Files changed (33) hide show
  1. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/PKG-INFO +1 -1
  2. nookplot_runtime-0.5.89/nookplot_runtime/knowledge_context.py +103 -0
  3. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/pyproject.toml +1 -1
  4. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/.gitignore +0 -0
  5. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/README.md +0 -0
  6. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/SKILL.md +0 -0
  7. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/__init__.py +0 -0
  8. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/action_catalog.py +0 -0
  9. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/action_catalog_generated.py +0 -0
  10. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/artifact_embeddings.py +0 -0
  11. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/autonomous.py +0 -0
  12. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/client.py +0 -0
  13. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/cognitive_workspace.py +0 -0
  14. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/content_safety.py +0 -0
  15. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/cro.py +0 -0
  16. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/embedding_exchange.py +0 -0
  17. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/evaluator.py +0 -0
  18. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/events.py +0 -0
  19. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/formatters.py +0 -0
  20. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/manifest.py +0 -0
  21. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/signal_action_map.py +0 -0
  22. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/nookplot_runtime/types.py +0 -0
  23. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/requirements.lock +0 -0
  24. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/__init__.py +0 -0
  25. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/helpers/__init__.py +0 -0
  26. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/helpers/mock_runtime.py +0 -0
  27. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_autonomous_action_dispatch.py +0 -0
  28. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_autonomous_dedup.py +0 -0
  29. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_autonomous_lifecycle.py +0 -0
  30. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_client.py +0 -0
  31. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_content_safety.py +0 -0
  32. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_get_available_actions.py +0 -0
  33. {nookplot_runtime-0.5.88 → nookplot_runtime-0.5.89}/tests/test_latent_space.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nookplot-runtime
3
- Version: 0.5.88
3
+ Version: 0.5.89
4
4
  Summary: Python Agent Runtime SDK for Nookplot — persistent connection, events, memory bridge, and economy for AI agents on Base
5
5
  Project-URL: Homepage, https://nookplot.com
6
6
  Project-URL: Repository, https://github.com/nookprotocol
@@ -0,0 +1,103 @@
1
+ """
2
+ Knowledge Context — auto-retrieves relevant compiled knowledge for task augmentation.
3
+
4
+ Before an agent processes a task, call ``get_knowledge_context(runtime, task_description)``
5
+ to fetch the top relevant items from the agent's compiled knowledge graph. Returns a
6
+ compact markdown string (~400 tokens) ready for injection into the agent's prompt.
7
+
8
+ Usage::
9
+
10
+ from nookplot_runtime.knowledge_context import get_knowledge_context
11
+
12
+ ctx = await get_knowledge_context(runtime, "review this code for security issues")
13
+ if ctx["available"]:
14
+ prompt = ctx["markdown"] + "\\n\\n" + original_prompt
15
+ """
16
+
17
+ from __future__ import annotations
18
+
19
+ from typing import Any
20
+ from urllib.parse import quote
21
+
22
+
23
+ # Defaults
24
+ MAX_ITEMS = 5
25
+ MIN_SCORE = 0.6
26
+ MIN_QUALITY = 50
27
+ MAX_SNIPPET = 120
28
+
29
+
30
+ async def get_knowledge_context(
31
+ runtime: Any,
32
+ task_description: str,
33
+ *,
34
+ max_items: int = MAX_ITEMS,
35
+ min_score: float = MIN_SCORE,
36
+ min_quality: float = MIN_QUALITY,
37
+ ) -> dict[str, Any]:
38
+ """Retrieve relevant compiled knowledge for a task.
39
+
40
+ Returns a dict with:
41
+ markdown (str): Compact markdown context for prompt injection
42
+ item_ids (list[str]): Item UUIDs for citation tracking
43
+ count (int): Number of items retrieved
44
+ available (bool): Whether any relevant context was found
45
+ """
46
+ empty: dict[str, Any] = {"markdown": "", "item_ids": [], "count": 0, "available": False}
47
+
48
+ if not task_description or len(task_description.strip()) < 3:
49
+ return empty
50
+
51
+ try:
52
+ q = quote(task_description[:200], safe="")
53
+ data = await runtime._http.request(
54
+ "GET",
55
+ f"/v1/agents/me/knowledge?q={q}&limit={max_items * 2}&include_public=false",
56
+ )
57
+
58
+ results = data.get("results", []) if isinstance(data, dict) else []
59
+ if not results:
60
+ return empty
61
+
62
+ # Filter by relevance + quality
63
+ filtered = []
64
+ for r in results:
65
+ score = r.get("score", 0)
66
+ item = r.get("item", {})
67
+ qs = item.get("qualityScore")
68
+ if score >= min_score and (qs is None or qs >= min_quality):
69
+ filtered.append(r)
70
+ if len(filtered) >= max_items:
71
+ break
72
+
73
+ if not filtered:
74
+ return empty
75
+
76
+ # Build compact markdown
77
+ lines = ["## Your compiled knowledge (auto-retrieved)", ""]
78
+ item_ids: list[str] = []
79
+
80
+ for i, r in enumerate(filtered):
81
+ item = r.get("item", {})
82
+ title = item.get("title") or (item.get("contentText", "")[:60])
83
+ domain = item.get("domain")
84
+ domain_prefix = f"[{domain}] " if domain else ""
85
+ snippet = item.get("contentText", "")[:MAX_SNIPPET].replace("\n", " ").strip()
86
+ lines.append(f"{i + 1}. {domain_prefix}**{title}** — {snippet}")
87
+ item_ids.append(item.get("id", ""))
88
+
89
+ return {
90
+ "markdown": "\n".join(lines),
91
+ "item_ids": item_ids,
92
+ "count": len(filtered),
93
+ "available": True,
94
+ }
95
+
96
+ except Exception as exc:
97
+ # Non-fatal — agent proceeds without knowledge context
98
+ # Log for debugging (don't raise — context injection is advisory)
99
+ import logging
100
+ logging.getLogger("nookplot_runtime").warning(
101
+ "Knowledge context retrieval failed: %s", exc
102
+ )
103
+ return empty
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "nookplot-runtime"
7
- version = "0.5.88"
7
+ version = "0.5.89"
8
8
  description = "Python Agent Runtime SDK for Nookplot — persistent connection, events, memory bridge, and economy for AI agents on Base"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10"