langchain-agentx-python 2.1.8__py3-none-any.whl → 2.1.9__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/tool_runtime/adapter.py +6 -1
- langchain_agentx/tool_runtime/cancel_projection.py +85 -0
- langchain_agentx/tool_runtime/pipeline.py +6 -1
- langchain_agentx/tools/agent/tool.py +29 -3
- {langchain_agentx_python-2.1.8.dist-info → langchain_agentx_python-2.1.9.dist-info}/METADATA +1 -1
- {langchain_agentx_python-2.1.8.dist-info → langchain_agentx_python-2.1.9.dist-info}/RECORD +10 -9
- {langchain_agentx_python-2.1.8.dist-info → langchain_agentx_python-2.1.9.dist-info}/LICENSE +0 -0
- {langchain_agentx_python-2.1.8.dist-info → langchain_agentx_python-2.1.9.dist-info}/WHEEL +0 -0
- {langchain_agentx_python-2.1.8.dist-info → langchain_agentx_python-2.1.9.dist-info}/top_level.txt +0 -0
langchain_agentx/__init__.py
CHANGED
|
@@ -653,10 +653,15 @@ class LangChainAdapter:
|
|
|
653
653
|
|
|
654
654
|
@staticmethod
|
|
655
655
|
def _envelope_to_event_artifact_dict(env: ToolResultEnvelope) -> dict[str, Any]:
|
|
656
|
+
from langchain_agentx.tool_runtime.cancel_projection import (
|
|
657
|
+
resolve_artifact_terminal_state,
|
|
658
|
+
)
|
|
659
|
+
|
|
656
660
|
raw = asdict(env)
|
|
657
661
|
raw["schema_version"] = "2"
|
|
658
662
|
result = LangChainAdapter._json_safe_value(raw)
|
|
659
|
-
result
|
|
663
|
+
meta = result.get("meta") if isinstance(result.get("meta"), dict) else {}
|
|
664
|
+
result["terminal_state"] = resolve_artifact_terminal_state(meta=meta)
|
|
660
665
|
# B1/C3 方案 B:blocks/hints/artifacts 同时落 meta.envelope_extensions,
|
|
661
666
|
# CLI Bridge 只消费 meta/display/payload,不扩字段面。
|
|
662
667
|
extensions: dict[str, Any] = {}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""
|
|
2
|
+
tool_runtime/cancel_projection.py — 工具取消投影(层 C · D-TR)
|
|
3
|
+
|
|
4
|
+
职责:判定取消窄条件,解析 artifact ``terminal_state`` 与 model payload 双轨哨兵。
|
|
5
|
+
链路位置:``AgentRuntimeTool.present`` → adapter/pipeline ``envelope → artifact``。
|
|
6
|
+
对照 CC:``CANCEL_MESSAGE`` / ``INTERRUPT_MESSAGE_FOR_TOOL_USE``;设计 D-TR-1…4。
|
|
7
|
+
当前裁剪:不扩 ``ToolResultEnvelope.status``;禁止仅凭散文含 cancel 推断。
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from typing import Any, Literal, Mapping
|
|
13
|
+
|
|
14
|
+
from langchain_agentx.loop.exit.reason_codes import (
|
|
15
|
+
TERMINAL_REASON_ABORTED_STREAMING,
|
|
16
|
+
TERMINAL_REASON_ABORTED_TOOLS,
|
|
17
|
+
TERMINAL_REASON_HOOK_STOPPED,
|
|
18
|
+
)
|
|
19
|
+
from langchain_agentx.tool_runtime.messages import (
|
|
20
|
+
CANCEL_MESSAGE,
|
|
21
|
+
INTERRUPT_MESSAGE_FOR_TOOL_USE,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
CANCEL_ERROR_KINDS = frozenset({"aborted", "user_cancelled", "cancelled"})
|
|
25
|
+
|
|
26
|
+
ABORT_LIKE_TERMINAL_REASONS = frozenset(
|
|
27
|
+
{
|
|
28
|
+
TERMINAL_REASON_ABORTED_STREAMING,
|
|
29
|
+
TERMINAL_REASON_ABORTED_TOOLS,
|
|
30
|
+
TERMINAL_REASON_HOOK_STOPPED,
|
|
31
|
+
}
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def is_cancel_projection(
|
|
36
|
+
*,
|
|
37
|
+
source_status: str | None = None,
|
|
38
|
+
error_kind: str | None = None,
|
|
39
|
+
terminal_reason: str | None = None,
|
|
40
|
+
) -> bool:
|
|
41
|
+
"""D-TR-3:满足其一即视为用户取消投影(窄条件)。"""
|
|
42
|
+
if source_status == "interrupted":
|
|
43
|
+
return True
|
|
44
|
+
if error_kind in CANCEL_ERROR_KINDS:
|
|
45
|
+
return True
|
|
46
|
+
if terminal_reason in ABORT_LIKE_TERMINAL_REASONS:
|
|
47
|
+
return True
|
|
48
|
+
return False
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def resolve_cancel_model_payload(*, error_kind: str | None) -> str:
|
|
52
|
+
"""D-TR-4:Stop 轨 ``user_cancelled`` → CANCEL;其余取消 → INTERRUPT_FOR_TOOL_USE。"""
|
|
53
|
+
if error_kind == "user_cancelled":
|
|
54
|
+
return CANCEL_MESSAGE
|
|
55
|
+
return INTERRUPT_MESSAGE_FOR_TOOL_USE
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def resolve_artifact_terminal_state(
|
|
59
|
+
*,
|
|
60
|
+
meta: Mapping[str, Any] | None = None,
|
|
61
|
+
terminal_reason: str | None = None,
|
|
62
|
+
) -> Literal["completed", "cancelled"]:
|
|
63
|
+
"""adapter/pipeline 共用:取消 → ``cancelled``,否则 ``completed``。"""
|
|
64
|
+
m = meta if isinstance(meta, Mapping) else {}
|
|
65
|
+
reason = terminal_reason if terminal_reason is not None else m.get("terminal_reason")
|
|
66
|
+
kind = m.get("error_kind")
|
|
67
|
+
source = m.get("source_status")
|
|
68
|
+
if is_cancel_projection(
|
|
69
|
+
source_status=str(source) if source is not None else None,
|
|
70
|
+
error_kind=str(kind) if kind is not None else None,
|
|
71
|
+
terminal_reason=str(reason) if reason is not None else None,
|
|
72
|
+
):
|
|
73
|
+
return "cancelled"
|
|
74
|
+
return "completed"
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
__all__ = [
|
|
78
|
+
"ABORT_LIKE_TERMINAL_REASONS",
|
|
79
|
+
"CANCEL_ERROR_KINDS",
|
|
80
|
+
"CANCEL_MESSAGE",
|
|
81
|
+
"INTERRUPT_MESSAGE_FOR_TOOL_USE",
|
|
82
|
+
"is_cancel_projection",
|
|
83
|
+
"resolve_artifact_terminal_state",
|
|
84
|
+
"resolve_cancel_model_payload",
|
|
85
|
+
]
|
|
@@ -684,7 +684,12 @@ class ToolExecutorPipeline:
|
|
|
684
684
|
|
|
685
685
|
artifact = json_safe(asdict(envelope))
|
|
686
686
|
artifact["schema_version"] = "2"
|
|
687
|
-
|
|
687
|
+
from langchain_agentx.tool_runtime.cancel_projection import (
|
|
688
|
+
resolve_artifact_terminal_state,
|
|
689
|
+
)
|
|
690
|
+
|
|
691
|
+
meta = artifact.get("meta") if isinstance(artifact.get("meta"), dict) else {}
|
|
692
|
+
artifact["terminal_state"] = resolve_artifact_terminal_state(meta=meta)
|
|
688
693
|
|
|
689
694
|
# display 可选(CC renderToolResultMessage?);无 Output 跳过;抛错不炸 pipeline
|
|
690
695
|
if (
|
|
@@ -17,6 +17,10 @@ import logging
|
|
|
17
17
|
from typing import Any, Literal
|
|
18
18
|
|
|
19
19
|
from langchain_agentx.tool_runtime.base import RuntimeTool
|
|
20
|
+
from langchain_agentx.tool_runtime.cancel_projection import (
|
|
21
|
+
is_cancel_projection,
|
|
22
|
+
resolve_cancel_model_payload,
|
|
23
|
+
)
|
|
20
24
|
from langchain_agentx.tool_runtime.models import (
|
|
21
25
|
AuthorizationDecision,
|
|
22
26
|
L1PermissionResult,
|
|
@@ -355,7 +359,14 @@ class AgentRuntimeTool(RuntimeTool):
|
|
|
355
359
|
},
|
|
356
360
|
)
|
|
357
361
|
if out.status == "error":
|
|
358
|
-
|
|
362
|
+
if is_cancel_projection(
|
|
363
|
+
error_kind=out.error_kind,
|
|
364
|
+
terminal_reason=out.terminal_reason,
|
|
365
|
+
):
|
|
366
|
+
return self._present_cancelled(inp, out, source_status="error")
|
|
367
|
+
payload = out.error_message or (
|
|
368
|
+
out.errors[0] if out.errors else "Subagent execution failed"
|
|
369
|
+
)
|
|
359
370
|
return ToolResultEnvelope(
|
|
360
371
|
status="error",
|
|
361
372
|
tool_name=self.name,
|
|
@@ -368,16 +379,31 @@ class AgentRuntimeTool(RuntimeTool):
|
|
|
368
379
|
**_agent_termination_meta(out),
|
|
369
380
|
},
|
|
370
381
|
)
|
|
382
|
+
# interrupted(及未知非 completed/async)→ 取消投影(D-TR-3/4)
|
|
383
|
+
return self._present_cancelled(inp, out, source_status="interrupted")
|
|
384
|
+
|
|
385
|
+
def _present_cancelled(
|
|
386
|
+
self,
|
|
387
|
+
inp: AgentToolInput,
|
|
388
|
+
out: AgentToolOutput,
|
|
389
|
+
*,
|
|
390
|
+
source_status: str,
|
|
391
|
+
) -> ToolResultEnvelope:
|
|
392
|
+
"""层 C:取消双轨 payload;Envelope.status 仍为 error(D-TR-2)。"""
|
|
393
|
+
error_kind = out.error_kind or "aborted"
|
|
394
|
+
term = _agent_termination_meta(out)
|
|
395
|
+
term["error_kind"] = error_kind
|
|
371
396
|
return ToolResultEnvelope(
|
|
372
397
|
status="error",
|
|
373
398
|
tool_name=self.name,
|
|
374
399
|
summary=f"Agent({inp.subagent_type}) interrupted",
|
|
375
|
-
payload=
|
|
400
|
+
payload=resolve_cancel_model_payload(error_kind=error_kind),
|
|
376
401
|
meta={
|
|
377
402
|
"agent_id": out.agent_id,
|
|
378
403
|
"terminal_reason": out.terminal_reason,
|
|
379
404
|
"mode": self._mode,
|
|
380
|
-
|
|
405
|
+
"source_status": source_status,
|
|
406
|
+
**term,
|
|
381
407
|
},
|
|
382
408
|
)
|
|
383
409
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
langchain_agentx/__init__.py,sha256=
|
|
1
|
+
langchain_agentx/__init__.py,sha256=Ap7xVSHcnVF6vuJw2G3SKTcI2QDzn2JSGQZSj-zuHjY,1614
|
|
2
2
|
langchain_agentx/command/__init__.py,sha256=Ej260S5uFQcmEtGZQG_NH7BYjHoStrpBLtGUsBTxyZk,631
|
|
3
3
|
langchain_agentx/command/allowed_tools.py,sha256=TVA0VM8rm98H-QbLK_GRiX5RhEAZFxKawliMi4kk96A,3359
|
|
4
4
|
langchain_agentx/command/context.py,sha256=DIGOGPBw5UGDBm0WNNJlKx1h_9rCRmcdROv4DT61Qug,731
|
|
@@ -390,9 +390,10 @@ langchain_agentx/task_runtime/tasks/trace_cleanup/executor.py,sha256=qez3WnzBTag
|
|
|
390
390
|
langchain_agentx/task_runtime/tasks/trace_cleanup/scheduler.py,sha256=lqWlCqucs26fhr4M9LfgY8I0xuNDxwSLkre6XjAJDhA,6877
|
|
391
391
|
langchain_agentx/tool_runtime/__init__.py,sha256=C4ZrS6UWSL65ErfNWMvBuZBnht6ZuGb0PBXwA0Xke74,5144
|
|
392
392
|
langchain_agentx/tool_runtime/accept_edits_fast_path.py,sha256=UMCOF9Ws7hx3pcYvL-Kq7vzIAGvOGdEfx69ccUDXT-k,2281
|
|
393
|
-
langchain_agentx/tool_runtime/adapter.py,sha256=
|
|
393
|
+
langchain_agentx/tool_runtime/adapter.py,sha256=rM-Y2zSZ--N-TIvx1HtI1J7ralPU0w4jJuX3bBvIVxM,33847
|
|
394
394
|
langchain_agentx/tool_runtime/agent_home_bypass.py,sha256=na9xQPgJ02qA3YiJ1F8jN0Uv4uBDPzqRk3lfPPE089g,8010
|
|
395
395
|
langchain_agentx/tool_runtime/base.py,sha256=Ez9W42DsaiZcWDDO8UfRKv3E7_Z6WBcABkwdAi6qTK8,21390
|
|
396
|
+
langchain_agentx/tool_runtime/cancel_projection.py,sha256=81_Bvg8ZiuPdl1usePt7ykXFuO6Sg7UXogYQBX6aysQ,2788
|
|
396
397
|
langchain_agentx/tool_runtime/capabilities.py,sha256=KHwu5KLqrpPKLOTwHhnvIIs9MTmQYeuS2hAFmI_Nsy8,3837
|
|
397
398
|
langchain_agentx/tool_runtime/classifier_denial_bridge.py,sha256=Wv40rYc5U3Mn7G3H7sUWrcG78HyLKnrRXvv7Yv9wI5U,2743
|
|
398
399
|
langchain_agentx/tool_runtime/classifier_denial_limit.py,sha256=RVLELUNO346_0ssg46bap52TRTp1dVzCOqdfjpuOpek,3793
|
|
@@ -420,7 +421,7 @@ langchain_agentx/tool_runtime/permission_rules.py,sha256=ev6-Hm3N8YtbJO3SLGpoGMU
|
|
|
420
421
|
langchain_agentx/tool_runtime/permission_settings_loader.py,sha256=Xu6dso0ghh4pb7Puf8nj20nXxjGeQvL4kIGycavwG_o,5624
|
|
421
422
|
langchain_agentx/tool_runtime/permission_settings_sync.py,sha256=g6TvjWwa7D0kw5rDznPsoMv7xylESPOyWA2vZW4HDm0,4590
|
|
422
423
|
langchain_agentx/tool_runtime/permission_snapshot.py,sha256=xFoi9fIcZjSw_zrIoyglneM-vJsDOLCEjiVoazr5Ack,1947
|
|
423
|
-
langchain_agentx/tool_runtime/pipeline.py,sha256=
|
|
424
|
+
langchain_agentx/tool_runtime/pipeline.py,sha256=b4ZlEMH5i3_rqWjPx3g7BD6Yv2hvk-R6qgKFgo-b3eU,54284
|
|
424
425
|
langchain_agentx/tool_runtime/policy.py,sha256=PLk_-5wu69_Gjqig0pj71brcu6VfLvGSIHsAUHOiYIQ,30068
|
|
425
426
|
langchain_agentx/tool_runtime/policy_decorator.py,sha256=XWbgh_TRlPJ-J-RFo1FKjIN_n_Z9rtLTfSwBQoyLTTg,2264
|
|
426
427
|
langchain_agentx/tool_runtime/process_loader.py,sha256=1YMn6ntnpdbIHJbO7wF1xuz7gNKYxK0UJAOxq96dZX4,6166
|
|
@@ -506,7 +507,7 @@ langchain_agentx/tools/agent/models.py,sha256=jPxah6JgPt0UlZVyrAQxQeZmVUDOBV7xyl
|
|
|
506
507
|
langchain_agentx/tools/agent/prompt.py,sha256=QQA40AfA5sEIl_LG7kn7UlUKFBOzsHSs_M8c5n-p7YU,8093
|
|
507
508
|
langchain_agentx/tools/agent/prompt_scope.py,sha256=xQup3hosuN0B6TFq7jYV5SE6gzZNwR6BOQ552dfef5I,2677
|
|
508
509
|
langchain_agentx/tools/agent/scope.py,sha256=6F2ZJgSvt-gFeciyKIQxaIiW5PBW9zUeTj3P0uxqrrg,6324
|
|
509
|
-
langchain_agentx/tools/agent/tool.py,sha256=
|
|
510
|
+
langchain_agentx/tools/agent/tool.py,sha256=h6yw2vDsla6teu47D5drOlVOn0KO_e973n_aih24qSU,17972
|
|
510
511
|
langchain_agentx/tools/agent/built_in/__init__.py,sha256=4YUHj8nUcUOvJW9p158W_t_RBoQt8Uh7eTt0idnCTE4,657
|
|
511
512
|
langchain_agentx/tools/agent/built_in/agentx_guide.py,sha256=Wz4791lK_URpAGtKWceEMvJlD_cu79KfmNQka5yXeUs,2719
|
|
512
513
|
langchain_agentx/tools/agent/built_in/explore.py,sha256=H5757yjmudceFVaMN0O4YDH267DKfFPMSxGR83waNkk,3504
|
|
@@ -758,8 +759,8 @@ langchain_agentx/workspace/root_grant_manager.py,sha256=W3gy8HTevbERbXqIgRcjzOXO
|
|
|
758
759
|
langchain_agentx/workspace/tool_boundary.py,sha256=UDwX6swpSLsx9HNkYuuRRiV5o7ZZG_Bru2Yn0c5kNX8,5724
|
|
759
760
|
langchain_agentx/workspace/validators.py,sha256=tQt-6TOcL8Fw7Ig5ebA9S7vGWh1rby920eFW6x8Tk9E,1439
|
|
760
761
|
langchain_agentx/workspace/view.py,sha256=PGasqTaqhlD03SXXazHuw4RHfV681AIdlsYqL70pEjc,4774
|
|
761
|
-
langchain_agentx_python-2.1.
|
|
762
|
-
langchain_agentx_python-2.1.
|
|
763
|
-
langchain_agentx_python-2.1.
|
|
764
|
-
langchain_agentx_python-2.1.
|
|
765
|
-
langchain_agentx_python-2.1.
|
|
762
|
+
langchain_agentx_python-2.1.9.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
763
|
+
langchain_agentx_python-2.1.9.dist-info/METADATA,sha256=6jvj-EwhulXBUBtaJgpJEaiyiFDPgxUnU7nX6dvS6Zk,24250
|
|
764
|
+
langchain_agentx_python-2.1.9.dist-info/WHEEL,sha256=51RkbunBAw4BWsgaQWTpPhg4Diwp3c9P5iaLk67Hdtg,92
|
|
765
|
+
langchain_agentx_python-2.1.9.dist-info/top_level.txt,sha256=Ge284pniNt8xea0OLk2o9o32GqVpDhOYk20fwE-0xxA,17
|
|
766
|
+
langchain_agentx_python-2.1.9.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
{langchain_agentx_python-2.1.8.dist-info → langchain_agentx_python-2.1.9.dist-info}/top_level.txt
RENAMED
|
File without changes
|