power-loop 5.3.0__tar.gz → 5.4.0__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 (105) hide show
  1. {power_loop-5.3.0 → power_loop-5.4.0}/PKG-INFO +1 -1
  2. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/__init__.py +1 -1
  3. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/representation.py +17 -6
  4. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/default_manifest.py +8 -5
  5. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/default_tools.py +44 -3
  6. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop.egg-info/PKG-INFO +1 -1
  7. {power_loop-5.3.0 → power_loop-5.4.0}/LICENSE +0 -0
  8. {power_loop-5.3.0 → power_loop-5.4.0}/README.md +0 -0
  9. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/__init__.py +0 -0
  10. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/__init__.py +0 -0
  11. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/anthropic_factory.py +0 -0
  12. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/capabilities.py +0 -0
  13. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/interface.py +0 -0
  14. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/llm_factory.py +0 -0
  15. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/llm_tooling.py +0 -0
  16. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/llm_utils.py +0 -0
  17. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/_vendor/llm_client/multimodal.py +0 -0
  18. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/agent/__init__.py +0 -0
  19. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/agent/follow_up.py +0 -0
  20. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/agent/sink.py +0 -0
  21. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/agent/stateful_loop.py +0 -0
  22. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/agent/system_prompt.py +0 -0
  23. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/agent/types.py +0 -0
  24. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/__init__.py +0 -0
  25. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/errors.py +0 -0
  26. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/event_payloads.py +0 -0
  27. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/events.py +0 -0
  28. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/handlers.py +0 -0
  29. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/hook_contexts.py +0 -0
  30. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/hooks.py +0 -0
  31. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/messages.py +0 -0
  32. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/protocols.py +0 -0
  33. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contracts/tools.py +0 -0
  34. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/__init__.py +0 -0
  35. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/_redact.py +0 -0
  36. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/jsonl_sink.py +0 -0
  37. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/logging_sink.py +0 -0
  38. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/mcp.py +0 -0
  39. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/metrics_sink.py +0 -0
  40. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/contrib/otel_sink.py +0 -0
  41. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/agent_context.py +0 -0
  42. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/events.py +0 -0
  43. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/hooks.py +0 -0
  44. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/phase.py +0 -0
  45. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/pipeline.py +0 -0
  46. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/runner.py +0 -0
  47. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/core/state.py +0 -0
  48. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/py.typed +0 -0
  49. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/blackboard.py +0 -0
  50. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/budget.py +0 -0
  51. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/cancellation.py +0 -0
  52. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/compact.py +0 -0
  53. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/env.py +0 -0
  54. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/exec_backend.py +0 -0
  55. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/fold.py +0 -0
  56. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/fold_adapter.py +0 -0
  57. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/history_projector.py +0 -0
  58. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/history_sanitize.py +0 -0
  59. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/human_input.py +0 -0
  60. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/memory.py +0 -0
  61. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/notes.py +0 -0
  62. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/provider.py +0 -0
  63. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/retry.py +0 -0
  64. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/runtime_state.py +0 -0
  65. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/session_store.py +0 -0
  66. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/skills.py +0 -0
  67. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/spec.py +0 -0
  68. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/__init__.py +0 -0
  69. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/backends/__init__.py +0 -0
  70. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/backends/mysql.py +0 -0
  71. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/backends/postgres.py +0 -0
  72. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/backends/sqlite.py +0 -0
  73. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/capabilities.py +0 -0
  74. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/db.py +0 -0
  75. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/dialect.py +0 -0
  76. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/factory.py +0 -0
  77. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/schema.py +0 -0
  78. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/store.py +0 -0
  79. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/store/types.py +0 -0
  80. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/structured.py +0 -0
  81. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/stub_provider.py +0 -0
  82. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/runtime/timers.py +0 -0
  83. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/__init__.py +0 -0
  84. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/blackboard.py +0 -0
  85. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/command_policy.py +0 -0
  86. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/registry.py +0 -0
  87. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/tools/spawn_agent.py +0 -0
  88. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/__init__.py +0 -0
  89. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/api.py +0 -0
  90. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/engine.py +0 -0
  91. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/introspect.py +0 -0
  92. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/journal.py +0 -0
  93. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/result.py +0 -0
  94. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/resume.py +0 -0
  95. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/runner.py +0 -0
  96. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/spec.py +0 -0
  97. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/subprocess_executor.py +0 -0
  98. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/tool.py +0 -0
  99. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop/workflow/worker.py +0 -0
  100. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop.egg-info/SOURCES.txt +0 -0
  101. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop.egg-info/dependency_links.txt +0 -0
  102. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop.egg-info/requires.txt +0 -0
  103. {power_loop-5.3.0 → power_loop-5.4.0}/power_loop.egg-info/top_level.txt +0 -0
  104. {power_loop-5.3.0 → power_loop-5.4.0}/pyproject.toml +0 -0
  105. {power_loop-5.3.0 → power_loop-5.4.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: power-loop
3
- Version: 5.3.0
3
+ Version: 5.4.0
4
4
  Summary: Embeddable agent execution kernel — LLM loop, hooks, events, tools, dynamic sub-agents.
5
5
  Author-email: zhangran <zhangran24@126.com>
6
6
  License: MIT
@@ -15,7 +15,7 @@ Stability tiers
15
15
  无版本承诺,可随时变更或删除。
16
16
  """
17
17
 
18
- __version__ = "5.3.0"
18
+ __version__ = "5.4.0"
19
19
 
20
20
  # Public LLM contract (SDK-free) re-exported so callers (e.g. writing llm.* hooks or
21
21
  # a custom LLMService) don't reach into the internal vendored transport package (H3.4).
@@ -274,10 +274,10 @@ class ProjectedRepresentation:
274
274
  # Tool results keyed by tool_call_id, preserving ORDER and DUPLICATES (a multimap of FIFO
275
275
  # queues): a malformed/imported/resumed transcript can repeat or omit an id, so a plain
276
276
  # dict would silently collapse two results onto one id (and drop the other).
277
- results: dict[str, deque[str | None]] = {}
277
+ results: dict[str, deque[tuple[str | None, int | None]]] = {}
278
278
  for r in send_rows:
279
279
  if r.role == "tool":
280
- results.setdefault(r.tool_call_id or "", deque()).append(r.content)
280
+ results.setdefault(r.tool_call_id or "", deque()).append((r.content, r.seq))
281
281
  tools: list[dict[str, Any]] = []
282
282
  inputs: list[str | None] = []
283
283
  final_text: str | None = None
@@ -293,7 +293,7 @@ class ProjectedRepresentation:
293
293
  if r.role == "user":
294
294
  if seen_assistant:
295
295
  # Verbatim like the input (conversation content, not tool output).
296
- tools.append({"name": "__user__", "text": r.content})
296
+ tools.append({"name": "__user__", "text": r.content, "seq": r.seq})
297
297
  else:
298
298
  inputs.append(r.content)
299
299
  continue
@@ -308,8 +308,17 @@ class ProjectedRepresentation:
308
308
  name = fn.get("name") or tc.get("name")
309
309
  args = _parse_args(fn.get("arguments"))
310
310
  bucket = results.get(str(tc.get("id") or ""))
311
- result = bucket.popleft() if bucket else _NO_RESULT
312
- tools.append(self._project_tool(name, args, result, tool_registry))
311
+ result, result_seq = bucket.popleft() if bucket else (_NO_RESULT, None)
312
+ entry = self._project_tool(name, args, result, tool_registry)
313
+ # Row coordinates (5.4.0): every projected tool entry carries the pl_messages seq of
314
+ # its RESULT row (``seq``) and of the assistant row that issued the call
315
+ # (``call_seq``), so a host renderer can print a self-contained
316
+ # "recall_send(send_index=N, seq=S)" pointer on each line — the model should never
317
+ # have to scan other sends to find where a dropped body lives.
318
+ if isinstance(entry, dict):
319
+ entry.setdefault("seq", result_seq)
320
+ entry.setdefault("call_seq", r.seq)
321
+ tools.append(entry)
313
322
  seqs = [r.seq for r in send_rows]
314
323
  rows: list[ProjectedRow] = []
315
324
  if inputs:
@@ -462,7 +471,9 @@ class ProjectedRepresentation:
462
471
  # A mid-send user injection (reminder / finalize / steering) at its
463
472
  # chronological position in the timeline — not a tool call.
464
473
  return f"[user] {t.get('text') or ''}"
465
- rest = {k: v for k, v in (t or {}).items() if k != "name"}
474
+ # Row coordinates (seq / call_seq, 5.4.0) are bookkeeping for host renderers, not part of
475
+ # the generic "name(k=v, …)" line — a host that wants a recall pointer overrides the render.
476
+ rest = {k: v for k, v in (t or {}).items() if k not in ("name", "seq", "call_seq")}
466
477
  if not rest:
467
478
  return str(name)
468
479
  body = self.render_config.tool_arg_sep.join(f"{k}={v}" for k, v in rest.items())
@@ -277,15 +277,18 @@ DEFAULT_TOOL_DEFINITIONS: list[ToolDefinition] = [
277
277
  ToolDefinition(
278
278
  name="recall_send",
279
279
  description=(
280
- "Re-expand an earlier send shown in your context only as a compact summary. When you "
281
- "need the EXACT original detail of a specific past send — its tool calls, their "
282
- "results, files touched, full text — call this with that send's index (the #N shown "
283
- "in the summary). Read-only, current session."
280
+ "Re-expand an earlier send shown in your context only as a compact summary. Each "
281
+ "summarized tool line carries a coordinate «#N·sS» (send_index N, row seq S). To get "
282
+ "ONE original tool result in full (a file you read, a skill you loaded, a vision answer, "
283
+ "a command's output), call recall_send(send_index=N, seq=S) — that returns just that row "
284
+ "with a large cap. Without seq it lists every row of send #N (each body cut at 2000 "
285
+ "chars) — use that only to see what happened, not to fetch a body. Read-only, current session."
284
286
  ),
285
287
  input_schema={
286
288
  "type": "object",
287
289
  "properties": {
288
- "send_index": {"type": "integer", "description": "The #N of the past send to expand."},
290
+ "send_index": {"type": "integer", "description": "The #N of the past send."},
291
+ "seq": {"type": "integer", "description": "Optional: the sS row coordinate from a summary line → return that single row in full."},
289
292
  },
290
293
  "required": ["send_index"],
291
294
  },
@@ -1696,16 +1696,21 @@ async def run_recall_compacted(
1696
1696
  # ── recall_send: re-expand a send the projection layer summarized ──────────────
1697
1697
 
1698
1698
  RECALL_SEND_CONTENT_CHARS = 2000
1699
+ # Single-row recall (``recall_send(send_index, seq=…)``) returns the ORIGINAL body — a skill file,
1700
+ # a read file, a vision answer — so its cap is generous. The send-level view keeps the small cap
1701
+ # because it lists every row of the send.
1702
+ RECALL_SEND_ROW_CHARS = 40_000
1699
1703
 
1700
1704
 
1701
- async def run_recall_send(send_index: int) -> str:
1705
+ async def run_recall_send(send_index: int, seq: int | None = None) -> str:
1702
1706
  """Re-expand one past send the send-context projection summarized.
1703
1707
 
1704
1708
  When ``AgentLoopConfig.history_projector`` is set, finished sends appear in context as a
1705
1709
  compact projected summary while their FULL detail stays in ``pl_messages`` (the immutable
1706
1710
  audit). This returns that send's original messages — assistant text, tool calls (by name)
1707
1711
  and their results — read-only, current session, by the ``send_index`` (the ``#N`` the
1708
- summary shows).
1712
+ summary shows). With ``seq`` it returns just THAT row (the ``sS`` coordinate a projected
1713
+ tool line carries) with a much larger body cap — plus the assistant call that produced it.
1709
1714
  """
1710
1715
  ctx = get_tool_runtime_context(required=True)
1711
1716
  store, sid = ctx.store, ctx.session_id
@@ -1720,6 +1725,18 @@ async def run_recall_send(send_index: int) -> str:
1720
1725
  if not rows:
1721
1726
  return f"No messages found for send #{target} in this session."
1722
1727
 
1728
+ if seq is not None:
1729
+ try:
1730
+ want = int(seq)
1731
+ except (TypeError, ValueError):
1732
+ return f"Invalid seq: {seq!r} (expected an integer)."
1733
+ hit = next((r for r in rows if r.seq == want), None)
1734
+ if hit is None:
1735
+ lo, hi = min(r.seq for r in rows), max(r.seq for r in rows)
1736
+ return (f"No row seq {want} in send #{target} (its rows span seq {lo}–{hi}). "
1737
+ "Use the exact «sS» coordinate from the summary line, or omit seq to list the whole send.")
1738
+ return _render_recall_row(hit, rows, cap=RECALL_SEND_ROW_CHARS, head=f"send #{target} · seq {want}")
1739
+
1723
1740
  def _tc_name(tc: dict[str, Any]) -> str:
1724
1741
  # ``function`` is normally a dict, but a malformed/imported tool_call can carry a
1725
1742
  # non-dict (e.g. a bare string); guard so name extraction never raises (the tool
@@ -1752,6 +1769,30 @@ async def run_recall_send(send_index: int) -> str:
1752
1769
  return f"send #{target} — {len(rows)} message(s):\n\n" + "\n\n".join(blocks)
1753
1770
 
1754
1771
 
1772
+ def _render_recall_row(hit: Any, rows: list[Any], *, cap: int, head: str) -> str:
1773
+ """One original row in full (capped at ``cap`` chars, remainder counted), preceded by the
1774
+ assistant call that produced it when the row is a tool result."""
1775
+ blocks: list[str] = []
1776
+ if hit.role == "tool" and hit.tool_call_id:
1777
+ for a in rows:
1778
+ for tc in (a.tool_calls or []) if a.role == "assistant" else []:
1779
+ if str(tc.get("id") or "") == str(hit.tool_call_id):
1780
+ fn = tc.get("function")
1781
+ fn = fn if isinstance(fn, dict) else {}
1782
+ blocks.append(
1783
+ f"[seq {a.seq} · assistant call · {fn.get('name') or tc.get('name') or '?'}]\n"
1784
+ f"{fn.get('arguments') or ''}"
1785
+ )
1786
+ break
1787
+ body = hit.content or ""
1788
+ total = len(body)
1789
+ if total > cap:
1790
+ body = body[:cap] + f" …[truncated: {total - cap} more chars of {total}]"
1791
+ label = f"[seq {hit.seq} · {hit.role}" + (f" · {hit.name}" if hit.name else "") + "]"
1792
+ blocks.append(f"{label}\n{body}")
1793
+ return f"{head} — original row ({total} chars):\n\n" + "\n\n".join(blocks)
1794
+
1795
+
1755
1796
  # Async tool handlers are registered as ``async def`` adapters (NOT sync lambdas that
1756
1797
  # merely return a coroutine): the registry uses ``inspect.iscoroutinefunction`` to decide
1757
1798
  # sync-vs-async dispatch and to keep the per-call ``runtime_env_context`` held across the
@@ -1783,7 +1824,7 @@ async def _h_recall_compacted(**kw: Any) -> Any:
1783
1824
 
1784
1825
 
1785
1826
  async def _h_recall_send(**kw: Any) -> Any:
1786
- return await run_recall_send(kw["send_index"])
1827
+ return await run_recall_send(kw["send_index"], kw.get("seq"))
1787
1828
 
1788
1829
 
1789
1830
  async def _h_background_run(**kw: Any) -> Any:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: power-loop
3
- Version: 5.3.0
3
+ Version: 5.4.0
4
4
  Summary: Embeddable agent execution kernel — LLM loop, hooks, events, tools, dynamic sub-agents.
5
5
  Author-email: zhangran <zhangran24@126.com>
6
6
  License: MIT
File without changes
File without changes
File without changes
File without changes