Make powerfx import conditional in _declarative_base.py

Co-authored-by: markwallace-microsoft <127216156+markwallace-microsoft@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-11 10:40:42 +00:00
Unverified
parent f6db799779
commit c3ca39b573
@@ -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: