Skip to content

Python: [Bug]: UserMessage/AgentMessage return different shapes from WorkflowState and DeclarativeWorkflowState #9041

Closed

Description

@he-yufeng

Language

Python

What happened?

The same declarative formula produces two different message shapes depending on which public state class evaluates it:

from agent_framework_declarative._workflows._state import WorkflowState

WorkflowState().eval('=UserMessage("hi")')
# {'role': 'user', 'content': 'hi'}

WorkflowState (standalone) routes to _powerfx_functions.user_message, which returns a flat content key (python/packages/declarative/agent_framework_declarative/_workflows/_powerfx_functions.py:107, same for assistant_message / agent_message / system_message).

DeclarativeWorkflowState (what factory-created workflows use) routes to _eval_custom_function, which returns a flat text key for UserMessage / AgentMessage:

return {"role": "user", "text": str(text) if text else ""}  # _declarative_base.py:755

The two MessageText implementations each read only their own side's shape, so a message that crosses paths silently extracts nothing:

  • _declarative_base._eval_and_replace_message_text reads text first, then a contents list; it never reads content (_declarative_base.py:858-885). A content-shaped message yields "".
  • _powerfx_functions.message_text reads content, so on a text-shaped message it returns "":
from agent_framework_declarative._workflows._powerfx_functions import message_text

message_text([{"role": "user", "text": "hi"}])     # ''
message_text([{"role": "user", "content": "hi"}])  # 'hi'

The agent-side consumer is more tolerant (_executors_agents.py:716 reads content then text), which papers over the split for agent invocations but not for MessageText.

For reference, the .NET canonical shape is a structured record (dotnet/src/Microsoft.Agents.AI.Workflows.Declarative/PowerFx/Functions/MessageFunction.cs): {__type__, Role, Content: [{Type: "Text", Value: ...}]}, i.e. neither flat Python shape. Feeding that shape to the fallback message_text today stringifies the content table:

message_text([{"role": "user", "content": [{"type": "text", "value": "hi"}]}])
# "[{'type': 'text', 'value': 'hi'}]"

Verified on current main (e9857bd75a21843803431a2e7dfa41ee9b017ac7) with agent-framework-declarative installed from source; the .NET shape was read from the in-repo dotnet sources.

What should happen?

One canonical message shape for the Python package, with both eval paths producing it and both MessageText implementations reading it. Which key wins (flat text, flat content, or the structured .NET-style content list) looks like a maintainer call; happy to send the PR once there is a direction.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 4, 2026
  2. added
    needs-maintainer-triageUsage: [Issues], Target: all issues that the automated triage flow failed to process
    on Oct 4, 2026
  3. added
    triageUsage: [Issues], Target: All issues that still need to be triaged
    needs-maintainer-triageUsage: [Issues], Target: all issues that the automated triage flow failed to process
    vnextUsage: [Issues, PRs], Target: breaking-change features deferred to the next major release
    and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    needs-maintainer-triageUsage: [Issues], Target: all issues that the automated triage flow failed to process
    on Oct 5, 2026
  4. he-yufeng commented on Oct 6, 2026

    @he-yufeng
    ContributorAuthor

    Two days without a triage response, so I went ahead with the half that does not need the shape decision: making both MessageText readers accept all three shapes (flat content, flat text, and the structured .NET content list). Both producer shapes are pinned by existing tests (test_powerfx_functions.py pins content, test_powerfx_yaml_compatibility.py pins text), so converging production would break observable behavior one way or the other; that question stays open here for a maintainer ruling. The reader-side fix closes the silent-"" extraction and the content-table stringification regardless of which key eventually wins. PR incoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

pythonUsage: [Issues, PRs], Target: PythonvnextUsage: [Issues, PRs], Target: breaking-change features deferred to the next major release

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions