|
12 | 12 | from llama_index.core.tools import AsyncBaseTool, BaseTool |
13 | 13 | from pyvis.network import Network |
14 | 14 | from workflows import Workflow |
| 15 | +from workflows.context.external_context import ExternalContext |
15 | 16 | from workflows.events import ( |
16 | 17 | Event, |
17 | 18 | StartEvent, |
@@ -46,15 +47,15 @@ def _get_node_color(node: WorkflowGraphNode) -> str: |
46 | 47 | elif node.node_type == "resource": |
47 | 48 | return "#DDA0DD" # Plum/light purple for resources |
48 | 49 | elif node.node_type == "event": |
49 | | - if node.is_subclass_of("StartEvent"): |
| 50 | + if node.is_subclass_of("StartEvent"): # type: ignore[possibly-missing-attribute] |
50 | 51 | return "#E27AFF" # Pink for start events |
51 | | - elif node.is_subclass_of("StopEvent"): |
| 52 | + elif node.is_subclass_of("StopEvent"): # type: ignore[possibly-missing-attribute] |
52 | 53 | return "#FFA07A" # Orange for stop events |
53 | 54 | return "#90EE90" # Light green for other events |
54 | 55 | elif node.node_type == "agent": |
55 | | - if node.is_subclass_of("ReActAgent"): |
| 56 | + if node.is_subclass_of("ReActAgent"): # type: ignore[possibly-missing-attribute] |
56 | 57 | return "#E27AFF" |
57 | | - elif node.is_subclass_of("CodeActAgent"): |
| 58 | + elif node.is_subclass_of("CodeActAgent"): # type: ignore[possibly-missing-attribute] |
58 | 59 | return "#66ccff" |
59 | 60 | return "#90EE90" |
60 | 61 | elif node.node_type == "tool": |
@@ -172,15 +173,15 @@ def _get_mermaid_css_class(node: WorkflowGraphNode) -> str: |
172 | 173 | elif node.node_type == "resource": |
173 | 174 | return "resourceStyle" |
174 | 175 | elif node.node_type == "event": |
175 | | - if node.is_subclass_of("StartEvent"): |
| 176 | + if node.is_subclass_of("StartEvent"): # type: ignore[possibly-missing-attribute] |
176 | 177 | return "startEventStyle" |
177 | | - elif node.is_subclass_of("StopEvent"): |
| 178 | + elif node.is_subclass_of("StopEvent"): # type: ignore[possibly-missing-attribute] |
178 | 179 | return "stopEventStyle" |
179 | 180 | return "defaultEventStyle" |
180 | 181 | elif node.node_type == "agent": |
181 | | - if node.is_subclass_of("ReActAgent"): |
| 182 | + if node.is_subclass_of("ReActAgent"): # type: ignore[possibly-missing-attribute] |
182 | 183 | return "reactAgentStyle" |
183 | | - elif node.is_subclass_of("CodeActAgent"): |
| 184 | + elif node.is_subclass_of("CodeActAgent"): # type: ignore[possibly-missing-attribute] |
184 | 185 | return "codeActAgentStyle" |
185 | 186 | return "defaultAgentStyle" |
186 | 187 | elif node.node_type == "tool": |
@@ -435,10 +436,12 @@ def _extract_execution_graph( |
435 | 436 | handler: WorkflowHandler, max_label_length: int | None = None |
436 | 437 | ) -> Tuple[Dict[str, Tuple[str, str, type | None]], List[Tuple[str, str]]]: |
437 | 438 | """Helper to extract nodes and edges from the workflow handler's tick log.""" |
438 | | - if handler.ctx is None or handler.ctx._broker_run is None: |
439 | | - raise ValueError("No context/run info in this handler. Has it been run yet?") |
440 | 439 |
|
441 | | - ticks: List[WorkflowTick] = handler.ctx._broker_run._tick_log |
| 440 | + ticks: List[WorkflowTick] = [] |
| 441 | + if handler.ctx is not None: |
| 442 | + face = handler.ctx._face |
| 443 | + if isinstance(face, ExternalContext): |
| 444 | + ticks = face._tick_log |
442 | 445 | nodes: Dict[str, Tuple[str, str, type | None]] = {} |
443 | 446 | edges: List[Tuple[str, str]] = [] |
444 | 447 | event_node_by_identity: Dict[int, str] = {} |
|
0 commit comments