Skip to content

Commit e52b5c7

Browse files
jpalvarezlCopilot
andcommitted
Python: preserve expression results in SendActivity output
Emit evaluated expressions as data while retaining authored-template interpolation. Add regression coverage for string and mapping activity forms. Co-authored-by: Copilot App <[email protected]>
1 parent 703fbce commit e52b5c7

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

‎python/packages/declarative/agent_framework_declarative/_workflows/_executors_basic.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ class SendActivityExecutor(DeclarativeActionExecutor):
224224
"""Executor for the SendActivity action.
225225
226226
Sends a text message or activity as workflow output.
227+
Authored text starting with ``=`` is evaluated and its result is emitted as data.
228+
Other authored text supports ``{Variable.Path}`` template interpolation.
227229
"""
228230

229231
@handler
@@ -244,11 +246,7 @@ async def handle_action(
244246
text = activity
245247

246248
if isinstance(text, str):
247-
# First evaluate any =expression syntax
248-
text = state.eval_if_expression(text)
249-
# Then interpolate any {Variable.Path} template syntax
250-
if isinstance(text, str):
251-
text = state.interpolate_string(text)
249+
text = state.eval_if_expression(text) if text.startswith("=") else state.interpolate_string(text)
252250

253251
# Yield the text as workflow output
254252
if text:

‎python/packages/declarative/tests/test_graph_coverage.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,27 @@ async def test_send_activity_with_expression(self, mock_context, mock_state):
613613

614614
mock_context.yield_output.assert_called_once_with("Dynamic message")
615615

616+
@_requires_powerfx
617+
@pytest.mark.parametrize("activity", ["=Local.msg", {"text": "=Local.msg"}])
618+
async def test_send_activity_preserves_expression_result(
619+
self, mock_context: MagicMock, mock_state: MagicMock, activity: str | dict[str, str]
620+
) -> None:
621+
"""Expression results are output data, not authored templates."""
622+
from agent_framework_declarative._workflows._executors_basic import (
623+
SendActivityExecutor,
624+
)
625+
626+
state = DeclarativeWorkflowState(mock_state)
627+
state.initialize()
628+
message = "Keep {Local.marker} as text."
629+
state.set("Local.msg", message)
630+
state.set("Local.marker", "fixture value")
631+
632+
executor = SendActivityExecutor({"kind": "SendActivity", "activity": activity})
633+
await executor.handle_action(ActionTrigger(), mock_context)
634+
635+
mock_context.yield_output.assert_awaited_once_with(message)
636+
616637

617638
# ---------------------------------------------------------------------------
618639
# Agent Executors Tests - Covering _executors_agents.py gaps

0 commit comments

Comments
 (0)