feat(langgraph): drop tags from TracePolicy (#8402)

This commit is contained in:
ccurme
2026-07-21 15:57:18 -04:00
committed by GitHub
parent 8b39db3875
commit f02c0f0ce5
3 changed files with 3 additions and 30 deletions
+1 -4
View File
@@ -700,8 +700,7 @@ class StateGraph(Generic[StateT, ContextT, InputT, OutputT]):
trace_policy: Optional policy controlling how this node's run is traced. Its trace_policy: Optional policy controlling how this node's run is traced. Its
`process_inputs` callable transforms the node's input before it is `process_inputs` callable transforms the node's input before it is
recorded (e.g. to omit or summarize large message history) without recorded (e.g. to omit or summarize large message history) without
changing the value passed to the node, and `tags` attaches tags to the changing the value passed to the node. Does not affect execution.
run (e.g. to hide it from the trace tree). Does not affect execution.
destinations: Destinations that indicate where a node can route to. destinations: Destinations that indicate where a node can route to.
Useful for edgeless graphs with nodes that return `Command` objects. Useful for edgeless graphs with nodes that return `Command` objects.
@@ -1529,7 +1528,6 @@ class CompiledStateGraph(
if node.defer if node.defer
else EphemeralValue(Any, guard=False) else EphemeralValue(Any, guard=False)
) )
trace_tags = node.trace_policy.tags if node.trace_policy else None
self.nodes[key] = PregelNode( self.nodes[key] = PregelNode(
triggers=[branch_channel], triggers=[branch_channel],
# read state keys and managed values # read state keys and managed values
@@ -1538,7 +1536,6 @@ class CompiledStateGraph(
mapper=mapper, mapper=mapper,
# publish to state keys # publish to state keys
writers=[ChannelWrite(write_entries)], writers=[ChannelWrite(write_entries)],
tags=list(trace_tags) if trace_tags else None,
metadata=node.metadata, metadata=node.metadata,
retry_policy=node.retry_policy, retry_policy=node.retry_policy,
cache_policy=node.cache_policy, cache_policy=node.cache_policy,
+1 -4
View File
@@ -3,7 +3,7 @@ from __future__ import annotations
import sys import sys
from collections import deque from collections import deque
from collections.abc import Callable, Hashable, Sequence from collections.abc import Callable, Hashable, Sequence
from dataclasses import asdict, dataclass, field from dataclasses import asdict, dataclass
from datetime import timedelta from datetime import timedelta
from typing import ( from typing import (
TYPE_CHECKING, TYPE_CHECKING,
@@ -547,9 +547,6 @@ class TracePolicy:
node's trace run. Use to omit or summarize large payloads (e.g. message history). node's trace run. Use to omit or summarize large payloads (e.g. message history).
Does not affect the value passed to the node.""" Does not affect the value passed to the node."""
tags: list[str] = field(default_factory=list)
"""Tags to attach to this node's trace run."""
_DEFAULT_INTERRUPT_ID = "placeholder-id" _DEFAULT_INTERRUPT_ID = "placeholder-id"
+1 -22
View File
@@ -1,4 +1,4 @@
"""End-to-end tests for `TracePolicy` (input processing + hidden tag) on node runs.""" """End-to-end tests for `TracePolicy` input processing on node trace runs."""
from typing import Any from typing import Any
@@ -86,24 +86,3 @@ async def test_trace_policy_transforms_recorded_inputs_async() -> None:
run = _node_run(tracer, "n") run = _node_run(tracer, "n")
assert run.inputs == {"scrubbed_in": True} assert run.inputs == {"scrubbed_in": True}
assert run.outputs == {"value": 6} assert run.outputs == {"value": 6}
def test_trace_policy_tags_applied_to_run() -> None:
graph = (
StateGraph(State)
.add_node("shown", _incr)
.add_node(
"hush", _incr, trace_policy=TracePolicy(tags=["langsmith:hidden_middleware"])
)
.add_edge(START, "shown")
.add_edge("shown", "hush")
.add_edge("hush", END)
.compile()
)
tracer = FakeTracer()
graph.invoke({"value": 0}, {"callbacks": [tracer]})
# the policy's tags land on the node's run; other nodes are unaffected
assert "langsmith:hidden_middleware" in _node_run(tracer, "hush").tags
assert "langsmith:hidden_middleware" not in _node_run(tracer, "shown").tags