From c3ca39b57339255100e860a96c4df03730f78e30 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 10:40:42 +0000 Subject: [PATCH] Make powerfx import conditional in _declarative_base.py Co-authored-by: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com> --- .../_workflows/_declarative_base.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/python/packages/declarative/agent_framework_declarative/_workflows/_declarative_base.py b/python/packages/declarative/agent_framework_declarative/_workflows/_declarative_base.py index 9bb868135b..426cb36859 100644 --- a/python/packages/declarative/agent_framework_declarative/_workflows/_declarative_base.py +++ b/python/packages/declarative/agent_framework_declarative/_workflows/_declarative_base.py @@ -37,7 +37,14 @@ from agent_framework._workflows import ( WorkflowContext, ) from agent_framework._workflows._state import State -from powerfx import Engine + +try: + from powerfx import Engine + + _powerfx_available = True +except (ImportError, RuntimeError): + _powerfx_available = False + Engine = None # type: ignore[assignment, misc] if sys.version_info >= (3, 11): from typing import TypedDict # type: ignore # pragma: no cover @@ -363,6 +370,14 @@ class DeclarativeWorkflowState: # Replace them with their evaluated results before sending to PowerFx formula = self._preprocess_custom_functions(formula) + # Check if powerfx is available + if not _powerfx_available: + raise ImportError( + "The 'powerfx' package is required to evaluate PowerFx expressions. " + "Please install .NET and the 'powerfx' package to use PowerFx expressions. " + "See https://github.com/microsoft/agent-framework for installation instructions." + ) + engine = Engine() symbols = self._to_powerfx_symbols() try: