feat: propagate reference hierarchy context from LangGraph runtime#901
Open
jepadil23 wants to merge 1 commit into
Open
feat: propagate reference hierarchy context from LangGraph runtime#901jepadil23 wants to merge 1 commit into
jepadil23 wants to merge 1 commit into
Conversation
UiPathLangGraphRuntime._push_reference_context() reads any parent ReferenceContext set by upstream (e.g. agents-python start_agent_run), appends a "langgraph" entry from UIPATH_AGENT_ID / UIPATH_PROCESS_VERSION, and activates it via ReferenceContextAccessor. Both execute() and stream() call this at entry and reset in finally, so all child spans emitted during the run carry the full hierarchy in their Context.referenceHierarchy wire payload. Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
|
There was a problem hiding this comment.
Pull request overview
This PR adds propagation of an ambient ReferenceContext for UiPathLangGraphRuntime runs so that downstream tracing can attribute spans to a langgraph service entry layered on top of any parent reference hierarchy.
Changes:
- Add
UiPathLangGraphRuntime._push_reference_context()and wrapexecute()/stream()with push/reset intry/finally. - Introduce a new test module covering context stacking behavior and ensuring the context is reset after
execute()/stream()(including error paths).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
src/uipath_langchain/runtime/runtime.py |
Pushes a langgraph entry into ReferenceContextAccessor during execute()/stream() and resets it in finally. |
tests/runtime/test_reference_context_wiring.py |
Adds tests for _push_reference_context() and for context reset after runtime execution/streaming. |
| self.chat.client_side_tools = self._get_client_side_tools() | ||
| self._middleware_node_names: set[str] = self._detect_middleware_nodes() | ||
|
|
||
| def _push_reference_context(self) -> contextvars.Token: |
Comment on lines
+11
to
+14
| from uipath.platform.common._reference_context import ( | ||
| ReferenceContext, | ||
| ReferenceContextAccessor, | ||
| ) |
Comment on lines
+3
to
+5
| import os | ||
| import tempfile | ||
| from typing import Any, TypedDict |
Comment on lines
+34
to
+36
| def _clear_accessor() -> None: | ||
| token = ReferenceContextAccessor.set(None) | ||
| ReferenceContextAccessor.reset(token) |
| monkeypatch.setenv("UIPATH_AGENT_ID", "550e8400-e29b-41d4-a716-446655440020") | ||
| monkeypatch.delenv("UIPATH_PROCESS_VERSION", raising=False) | ||
|
|
||
| from langgraph.graph import StateGraph |
Comment on lines
+142
to
+144
| with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f: | ||
| db = f.name | ||
|
|
Comment on lines
+171
to
+173
| with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f: | ||
| db = f.name | ||
|
|
Comment on lines
+195
to
+197
| with tempfile.NamedTemporaryFile(suffix=".db", delete=False) as f: | ||
| db = f.name | ||
|
|
| @@ -0,0 +1,205 @@ | |||
| """Tests for ReferenceContext wiring in UiPathLangGraphRuntime.""" | |||
danflorescu96
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
UiPathLangGraphRuntime._push_reference_context()pushes a"langgraph"entry intoReferenceContextAccessorduringexecute()andstream(), resets infinallymaestro → agent → langgraph) in theirContext.referenceHierarchywire payloadDependencies
Requires
uipath-pythonPR #1708 (ReferenceContext/ReferenceContextAccessortypes).Test plan
tests/runtime/test_reference_context_wiring.py— verifiesreferenceHierarchyis present in LangGraph runtime spans with correctserviceType="langgraph"entry🤖 Generated with Claude Code