Skip to content

Commit c325251

Browse files
committed
fix: use step-internal context for debug breakpoints in llamaindex runtime
the breakpoint wrapper was reading the workflow-level ExternalContext via self.context instead of the per-step InternalContext passed by the workflows framework as a kwarg. wait_for_event requires InternalContext, so debug mode always raised ContextStateError.
1 parent feccaf7 commit c325251

2 files changed

Lines changed: 6 additions & 14 deletions

File tree

packages/uipath-llamaindex/src/uipath_llamaindex/runtime/breakpoints.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from __future__ import annotations
66

77
import functools
8-
from typing import Any, Protocol, cast
8+
from typing import Any, cast
99

1010
from workflows import Context, Workflow
1111
from workflows.decorators import StepFunction
@@ -17,10 +17,6 @@
1717
from uipath_llamaindex.runtime.schema import get_step_config
1818

1919

20-
class DebuggableWorkflow(Protocol):
21-
context: Context | None = None
22-
23-
2420
class BreakpointEvent(InputRequiredEvent):
2521
"""Event emitted when a breakpoint is hit (before step execution)."""
2622

@@ -75,11 +71,13 @@ def make_wrapper(
7571
"""
7672
Return a wrapped step function that pauses on breakpoints.
7773
"""
74+
step_config = original._step_config
75+
ctx_param: str | None = step_config.context_parameter if step_config else None
7876

7977
@functools.wraps(original)
8078
async def wrapper(self, *args: Any, **kwargs: Any) -> Any:
81-
# Grab ctx from the workflow, as wired by UiPathLlamaIndexRuntime
82-
ctx: Context | None = getattr(self, "context", None)
79+
# Grab the internal context passed by the workflows framework to this step.
80+
ctx: Context | None = kwargs.get(ctx_param) if ctx_param else None
8381

8482
if isinstance(ctx, Context):
8583
bp_event = BreakpointEvent(

packages/uipath-llamaindex/src/uipath_llamaindex/runtime/runtime.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
import json
55
import logging
6-
from typing import Any, AsyncGenerator, cast
6+
from typing import Any, AsyncGenerator
77
from uuid import uuid4
88

99
from llama_index.core.agent.workflow.workflow_events import (
@@ -40,7 +40,6 @@
4040
from uipath_llamaindex.runtime.breakpoints import (
4141
BreakpointEvent,
4242
BreakpointResumeEvent,
43-
DebuggableWorkflow,
4443
inject_breakpoints,
4544
)
4645
from uipath_llamaindex.runtime.chat import UiPathChatMessagesMapper
@@ -144,11 +143,6 @@ async def _run_workflow(
144143

145144
self._context = await self._load_context()
146145

147-
# Make the Context discoverable from inside steps
148-
if self.debug_mode and self._context is not None:
149-
debug_workflow = cast(DebuggableWorkflow, self.workflow)
150-
debug_workflow.context = self._context
151-
152146
if is_resuming:
153147
handler: WorkflowHandler = self.workflow.run(ctx=self._context)
154148
if workflow_input:

0 commit comments

Comments
 (0)