langchain-agentx-python 2.5.0__py3-none-any.whl → 2.5.2__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.
- langchain_agentx/__init__.py +1 -1
- langchain_agentx/loop/graph/factory.py +37 -6
- langchain_agentx/loop/subagent/context.py +10 -1
- langchain_agentx/memory/instruction/read_state_seeder.py +6 -1
- langchain_agentx/session/agent_session.py +34 -0
- langchain_agentx/session/conversation_factory.py +6 -0
- langchain_agentx/session/conversation_session.py +36 -1
- langchain_agentx/tool_runtime/post_compact_restore.py +462 -0
- langchain_agentx/tool_runtime/read_state_lifecycle.py +165 -0
- langchain_agentx/tool_runtime/session_store.py +32 -8
- langchain_agentx/tools/workflow/backend.py +17 -3
- langchain_agentx/tools/workflow/observe/__init__.py +3 -1
- langchain_agentx/tools/workflow/observe/host_panel.py +12 -0
- langchain_agentx/tools/workflow/observe/nesting_link.py +61 -0
- langchain_agentx/tools/workflow/observe/task_bridge.py +80 -6
- langchain_agentx/tools/workflow/tool.py +46 -0
- {langchain_agentx_python-2.5.0.dist-info → langchain_agentx_python-2.5.2.dist-info}/METADATA +1 -1
- {langchain_agentx_python-2.5.0.dist-info → langchain_agentx_python-2.5.2.dist-info}/RECORD +21 -18
- {langchain_agentx_python-2.5.0.dist-info → langchain_agentx_python-2.5.2.dist-info}/LICENSE +0 -0
- {langchain_agentx_python-2.5.0.dist-info → langchain_agentx_python-2.5.2.dist-info}/WHEEL +0 -0
- {langchain_agentx_python-2.5.0.dist-info → langchain_agentx_python-2.5.2.dist-info}/top_level.txt +0 -0
langchain_agentx/__init__.py
CHANGED
|
@@ -1593,17 +1593,48 @@ class LoopGraphBuilder:
|
|
|
1593
1593
|
patch["compaction_pipeline_meta"] = meta
|
|
1594
1594
|
meta["compact_progress"] = progress_events
|
|
1595
1595
|
|
|
1596
|
+
@staticmethod
|
|
1597
|
+
def _messages_truly_evaporated(patch: dict[str, Any]) -> bool:
|
|
1598
|
+
"""委托 ``read_state_lifecycle.messages_truly_evaporated``(供单测/外部复用)。"""
|
|
1599
|
+
from langchain_agentx.tool_runtime.read_state_lifecycle import (
|
|
1600
|
+
messages_truly_evaporated,
|
|
1601
|
+
)
|
|
1602
|
+
|
|
1603
|
+
return messages_truly_evaporated(patch)
|
|
1604
|
+
|
|
1596
1605
|
def _clear_file_reads_after_message_compaction(self, patch: dict[str, Any]) -> None:
|
|
1597
|
-
"""
|
|
1606
|
+
"""真·蒸发后清空 last_read(对齐 CC ``readFileState.clear()`` on compact)。
|
|
1598
1607
|
|
|
1599
1608
|
防止 Read dedup 返回 file_unchanged 却断言「内容仍在本会话」(A2)。
|
|
1609
|
+
常驻裁剪(snip 等)不动读状态(BUG-20261109-32 / CC microCompact)。
|
|
1600
1610
|
"""
|
|
1601
|
-
|
|
1602
|
-
|
|
1611
|
+
from langchain_agentx.tool_runtime.read_state_lifecycle import (
|
|
1612
|
+
clear_file_reads_if_evaporated,
|
|
1613
|
+
)
|
|
1614
|
+
from langchain_agentx.workspace.plans import resolve_plans_directory
|
|
1615
|
+
|
|
1603
1616
|
store = getattr(self, "_session_store", None)
|
|
1604
|
-
|
|
1605
|
-
|
|
1606
|
-
|
|
1617
|
+
if store is None:
|
|
1618
|
+
return
|
|
1619
|
+
workspace_cfg = getattr(self, "_workspace_cfg", None)
|
|
1620
|
+
plans_dir = None
|
|
1621
|
+
memory_paths: list[str] = []
|
|
1622
|
+
if workspace_cfg is not None:
|
|
1623
|
+
try:
|
|
1624
|
+
plans_dir = resolve_plans_directory(workspace_cfg)
|
|
1625
|
+
except Exception:
|
|
1626
|
+
plans_dir = None
|
|
1627
|
+
entry = getattr(workspace_cfg, "memory_entrypoint", None)
|
|
1628
|
+
if entry is not None:
|
|
1629
|
+
memory_paths.append(str(entry))
|
|
1630
|
+
clear_file_reads_if_evaporated(
|
|
1631
|
+
store,
|
|
1632
|
+
patch,
|
|
1633
|
+
plans_dir=plans_dir,
|
|
1634
|
+
memory_paths=memory_paths or None,
|
|
1635
|
+
session_id=getattr(self, "_session_id", None),
|
|
1636
|
+
workspace_cfg=workspace_cfg,
|
|
1637
|
+
)
|
|
1607
1638
|
|
|
1608
1639
|
def _apply_prune_and_compress(self, state: dict[str, Any]) -> dict[str, Any]:
|
|
1609
1640
|
if self._session_memory_compact_bridge is not None:
|
|
@@ -427,10 +427,19 @@ class ForkedParentRuntime:
|
|
|
427
427
|
|
|
428
428
|
|
|
429
429
|
def _clone_parent_session_store(parent_store: Any) -> Any:
|
|
430
|
+
"""后台 fork 专用:继承父读缓存(调用方必带父消息,见 ``build_for_background``)。
|
|
431
|
+
|
|
432
|
+
显式 ``inherit_file_reads=True``,禁止依赖 clone 默认值——plain/Skill 路径
|
|
433
|
+
不得复用本函数(须走 ``create_subagent_context(fork_from_parent=…)``)。
|
|
434
|
+
"""
|
|
430
435
|
from langchain_agentx.tool_runtime.session_store import AgentSessionStore
|
|
431
436
|
|
|
432
437
|
if isinstance(parent_store, AgentSessionStore):
|
|
433
|
-
return parent_store.clone(
|
|
438
|
+
return parent_store.clone(
|
|
439
|
+
file_state_only=True,
|
|
440
|
+
inherit_grants=True,
|
|
441
|
+
inherit_file_reads=True,
|
|
442
|
+
)
|
|
434
443
|
return parent_store
|
|
435
444
|
|
|
436
445
|
|
|
@@ -3,7 +3,8 @@ memory/instruction/read_state_seeder.py — 指令注入 read-state 播种
|
|
|
3
3
|
|
|
4
4
|
职责:
|
|
5
5
|
将 Layer 1 规则文件注入 prompt 时同步写入 ``AgentSessionStore.file_read_state``;
|
|
6
|
-
注入内容与磁盘不一致时标记 ``is_partial_view``(对齐 CC attachments memoryFilesToAttachments
|
|
6
|
+
注入内容与磁盘不一致时标记 ``is_partial_view``(对齐 CC attachments memoryFilesToAttachments);
|
|
7
|
+
同步 ``loaded_nested_memory_paths.add``(对齐 CC 非淘汰去重轨)。
|
|
7
8
|
|
|
8
9
|
链路位置:
|
|
9
10
|
LoopGraphBuilder 初始化 → InstructionMemoryBootstrap.seed_injected_read_state()。
|
|
@@ -53,6 +54,9 @@ class InstructionReadStateSeeder:
|
|
|
53
54
|
injected_content: str,
|
|
54
55
|
) -> None:
|
|
55
56
|
path = str(file_path.resolve())
|
|
57
|
+
# 对齐 CC memoryFilesToAttachments:nested Set 或 readFileState 命中则跳过
|
|
58
|
+
if session_store.has_nested_memory_loaded(path):
|
|
59
|
+
return
|
|
56
60
|
if session_store.has_been_read(path):
|
|
57
61
|
return
|
|
58
62
|
try:
|
|
@@ -76,3 +80,4 @@ class InstructionReadStateSeeder:
|
|
|
76
80
|
if content_differs:
|
|
77
81
|
entry["is_partial_view"] = True
|
|
78
82
|
session_store.upsert_last_read_from_bridge_entry(path, entry)
|
|
83
|
+
session_store.mark_nested_memory_loaded(path)
|
|
@@ -408,7 +408,15 @@ class AgentSession:
|
|
|
408
408
|
return self._dispatcher
|
|
409
409
|
|
|
410
410
|
def clear_context(self) -> None:
|
|
411
|
+
"""清空对话消息,并对齐 CC /clear 清读状态与 skill 去重集合。"""
|
|
411
412
|
self._messages.clear()
|
|
413
|
+
store = self._resolve_session_store()
|
|
414
|
+
if store is not None:
|
|
415
|
+
from ..tool_runtime.read_state_lifecycle import (
|
|
416
|
+
clear_tool_state_on_conversation_reset,
|
|
417
|
+
)
|
|
418
|
+
|
|
419
|
+
clear_tool_state_on_conversation_reset(store)
|
|
412
420
|
|
|
413
421
|
async def compact_context(
|
|
414
422
|
self, *, progress_callback: Any = None
|
|
@@ -420,7 +428,13 @@ class AgentSession:
|
|
|
420
428
|
|
|
421
429
|
返回:
|
|
422
430
|
(before_tokens, after_tokens) 元组
|
|
431
|
+
|
|
432
|
+
真·蒸发(autocompact / session_memory)时清空 last_read,对齐 CC
|
|
433
|
+
``compact.ts`` ``readFileState.clear()``;常驻 snip 等不清。
|
|
423
434
|
"""
|
|
435
|
+
from ..tool_runtime.read_state_lifecycle import clear_file_reads_if_evaporated
|
|
436
|
+
from ..workspace.plans import resolve_plans_directory
|
|
437
|
+
|
|
424
438
|
before_tokens = total_estimated_tokens_for_messages(self._messages, num_chars_per_token=4)
|
|
425
439
|
# 注意:model=None 表示不使用 LLM 摘要,仅走 prune 路径
|
|
426
440
|
# 如果需要 LLM 摘要,调用方需要通过其他方式提供 model
|
|
@@ -429,6 +443,26 @@ class AgentSession:
|
|
|
429
443
|
model=None,
|
|
430
444
|
progress_callback=progress_callback,
|
|
431
445
|
)
|
|
446
|
+
store = self._resolve_session_store()
|
|
447
|
+
if store is not None:
|
|
448
|
+
# 须在写入 self._messages 前执行:真蒸发会追加 post-compact 合成 Read
|
|
449
|
+
plans_dir = None
|
|
450
|
+
memory_paths: list[str] = []
|
|
451
|
+
try:
|
|
452
|
+
plans_dir = resolve_plans_directory(self._workspace_cfg)
|
|
453
|
+
except Exception:
|
|
454
|
+
plans_dir = None
|
|
455
|
+
entry = getattr(self._workspace_cfg, "memory_entrypoint", None)
|
|
456
|
+
if entry is not None:
|
|
457
|
+
memory_paths.append(str(entry))
|
|
458
|
+
clear_file_reads_if_evaporated(
|
|
459
|
+
store,
|
|
460
|
+
patch,
|
|
461
|
+
plans_dir=plans_dir,
|
|
462
|
+
memory_paths=memory_paths or None,
|
|
463
|
+
session_id=self._session_id,
|
|
464
|
+
workspace_cfg=self._workspace_cfg,
|
|
465
|
+
)
|
|
432
466
|
if isinstance(patch.get("messages"), list):
|
|
433
467
|
self._messages = list(patch["messages"])
|
|
434
468
|
after_tokens = total_estimated_tokens_for_messages(self._messages, num_chars_per_token=4)
|
|
@@ -28,6 +28,7 @@ from langchain_agentx.loop.config.loop_config import AgentLoopConfig, LoopServic
|
|
|
28
28
|
from langchain_agentx.loop.config.loop_runtime_overlay import LoopRuntimeOverlay
|
|
29
29
|
from langchain_agentx.loop.graph.factory import create_loop_agent
|
|
30
30
|
from langchain_agentx.loop.hook import HookEngine, HooksConfigSnapshot, HookRegistry, WorkspaceTrustChecker
|
|
31
|
+
from langchain_agentx.tool_runtime.session_store import AgentSessionStore
|
|
31
32
|
from langchain_agentx.workspace import resolve_agent_state_config
|
|
32
33
|
from .conversation_session import ConversationSession
|
|
33
34
|
|
|
@@ -65,6 +66,9 @@ def create_conversation_session(
|
|
|
65
66
|
cfg = replace(cfg, workspace=replace(cfg.workspace, workspace_trust_accepted=workspace_trust_accepted))
|
|
66
67
|
|
|
67
68
|
resolved_id = conversation_id or f"conv-{uuid4().hex}"
|
|
69
|
+
# graph 每轮新建,但 read 状态须跨 turn;与 AgentSession 一样持有共享 store
|
|
70
|
+
session_store = svcs.session_store or AgentSessionStore(session_id=resolved_id)
|
|
71
|
+
svcs = replace(svcs, session_store=session_store)
|
|
68
72
|
|
|
69
73
|
if hook_engine is None:
|
|
70
74
|
snapshot = svcs.hooks.build_snapshot() if svcs.hooks is not None else HooksConfigSnapshot()
|
|
@@ -84,6 +88,7 @@ def create_conversation_session(
|
|
|
84
88
|
svcs,
|
|
85
89
|
capabilities=overlay.capabilities if overlay.capabilities is not None else svcs.capabilities,
|
|
86
90
|
command_registry=command_registry,
|
|
91
|
+
session_store=session_store,
|
|
87
92
|
)
|
|
88
93
|
return create_loop_agent(model, config=runtime_cfg, services=final_svcs)
|
|
89
94
|
|
|
@@ -96,6 +101,7 @@ def create_conversation_session(
|
|
|
96
101
|
capabilities=svcs.capabilities,
|
|
97
102
|
command_registry=command_registry,
|
|
98
103
|
mcp_plugin_sink=plugin_mcp,
|
|
104
|
+
session_store=session_store,
|
|
99
105
|
)
|
|
100
106
|
|
|
101
107
|
|
|
@@ -70,6 +70,7 @@ class ConversationSession:
|
|
|
70
70
|
capabilities: RuntimeCapabilities | None = None,
|
|
71
71
|
command_registry: CommandRegistry | None = None,
|
|
72
72
|
mcp_plugin_sink: list[Any] | None = None,
|
|
73
|
+
session_store: Any | None = None,
|
|
73
74
|
) -> None:
|
|
74
75
|
self._graph_factory = graph_factory
|
|
75
76
|
self._conversation_id = conversation_id
|
|
@@ -80,6 +81,8 @@ class ConversationSession:
|
|
|
80
81
|
self._container_type = "conversation"
|
|
81
82
|
self._session_memory_manager: Any | None = None
|
|
82
83
|
self._capabilities = capabilities
|
|
84
|
+
# 跨 turn 共享 store(graph 每轮新建);供 /clear · /compact 清读状态
|
|
85
|
+
self._session_store = session_store
|
|
83
86
|
self._skill_registry = SkillRegistry(workspace_root=workspace_cfg.workspace_root)
|
|
84
87
|
self._command_registry = PluginCommandRegistry()
|
|
85
88
|
self._agent_registry = AgentRegistry()
|
|
@@ -361,11 +364,42 @@ class ConversationSession:
|
|
|
361
364
|
return self._dispatcher
|
|
362
365
|
|
|
363
366
|
def clear_context(self) -> None:
|
|
367
|
+
"""清空对话消息;若能解析到 session_store 则对齐 CC /clear 清工具状态。"""
|
|
364
368
|
self._messages.clear()
|
|
369
|
+
store = self._resolve_session_store()
|
|
370
|
+
if store is not None:
|
|
371
|
+
from ..tool_runtime.read_state_lifecycle import (
|
|
372
|
+
clear_tool_state_on_conversation_reset,
|
|
373
|
+
)
|
|
374
|
+
|
|
375
|
+
clear_tool_state_on_conversation_reset(store)
|
|
365
376
|
|
|
366
377
|
async def compact_context(self) -> tuple[int, int]:
|
|
378
|
+
"""压缩上下文;真·蒸发时清空 last_read(对齐 CC compact.ts)。"""
|
|
379
|
+
from ..tool_runtime.read_state_lifecycle import clear_file_reads_if_evaporated
|
|
380
|
+
from ..workspace.plans import resolve_plans_directory
|
|
381
|
+
|
|
367
382
|
before_tokens = total_estimated_tokens_for_messages(self._messages, num_chars_per_token=4)
|
|
368
383
|
patch = default_loop_context_compaction().run({"messages": self._messages})
|
|
384
|
+
store = self._resolve_session_store()
|
|
385
|
+
if store is not None:
|
|
386
|
+
plans_dir = None
|
|
387
|
+
memory_paths: list[str] = []
|
|
388
|
+
try:
|
|
389
|
+
plans_dir = resolve_plans_directory(self._workspace_cfg)
|
|
390
|
+
except Exception:
|
|
391
|
+
plans_dir = None
|
|
392
|
+
entry = getattr(self._workspace_cfg, "memory_entrypoint", None)
|
|
393
|
+
if entry is not None:
|
|
394
|
+
memory_paths.append(str(entry))
|
|
395
|
+
clear_file_reads_if_evaporated(
|
|
396
|
+
store,
|
|
397
|
+
patch,
|
|
398
|
+
plans_dir=plans_dir,
|
|
399
|
+
memory_paths=memory_paths or None,
|
|
400
|
+
session_id=self._conversation_id,
|
|
401
|
+
workspace_cfg=self._workspace_cfg,
|
|
402
|
+
)
|
|
369
403
|
if isinstance(patch.get("messages"), list):
|
|
370
404
|
self._messages = list(patch["messages"])
|
|
371
405
|
after_tokens = total_estimated_tokens_for_messages(self._messages, num_chars_per_token=4)
|
|
@@ -421,7 +455,8 @@ class ConversationSession:
|
|
|
421
455
|
return catalog.list_skills_menu(dynamic_catalog=dynamic)
|
|
422
456
|
|
|
423
457
|
def _resolve_session_store(self) -> Any | None:
|
|
424
|
-
|
|
458
|
+
"""跨 turn 共享的 AgentSessionStore(工厂注入;无则 None)。"""
|
|
459
|
+
return self._session_store
|
|
425
460
|
|
|
426
461
|
async def _execute_hook(self, event: HookEvent) -> None:
|
|
427
462
|
ctx = HookContext(event=event, state={}, session_id=self._conversation_id)
|