Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/uipath_langchain/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
)

from uipath_langchain.runtime.factory import UiPathLangGraphRuntimeFactory
from uipath_langchain.runtime.runtime import UiPathLangGraphRuntime
from uipath_langchain.runtime.runtime import UiPathLangGraphRuntime, execution_callbacks
from uipath_langchain.runtime.schema import (
get_entrypoints_schema,
get_graph_schema,
Expand Down Expand Up @@ -33,4 +33,5 @@ def create_factory(
"get_graph_schema",
"UiPathLangGraphRuntimeFactory",
"UiPathLangGraphRuntime",
"execution_callbacks",
]
15 changes: 14 additions & 1 deletion src/uipath_langchain/runtime/runtime.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
from contextvars import ContextVar
from typing import Any, AsyncGenerator
from uuid import uuid4

Expand Down Expand Up @@ -31,6 +32,12 @@

logger = logging.getLogger(__name__)

# Context var for per-execution callback injection (set by wrappers like TelemetryRuntimeWrapper)
# This allows injecting callbacks at execution time without mutating self.callbacks
execution_callbacks: ContextVar[list[BaseCallbackHandler] | None] = ContextVar(
"uipath_execution_callbacks", default=None
)


class UiPathLangGraphRuntime:
"""
Expand Down Expand Up @@ -197,9 +204,15 @@ async def get_schema(self) -> UiPathRuntimeSchema:

def _get_graph_config(self) -> RunnableConfig:
"""Build graph execution configuration."""
# Copy callbacks to prevent mutation, extend with context callbacks
callbacks = list(self.callbacks)
ctx_callbacks = execution_callbacks.get()
if ctx_callbacks:
callbacks.extend(ctx_callbacks)

graph_config: RunnableConfig = {
"configurable": {"thread_id": self.runtime_id},
"callbacks": self.callbacks,
"callbacks": callbacks,
}

# Add optional config from environment
Expand Down
Loading