Skip to content

Python: Handle dict input for MagenticStartMessage - #1446

Closed
tonybaloney wants to merge 3 commits into
microsoft:mainfrom
tonybaloney:patch-1
Closed

Python: Handle dict input for MagenticStartMessage#1446
tonybaloney wants to merge 3 commits into
microsoft:mainfrom
tonybaloney:patch-1

Conversation

@tonybaloney

Copy link
Copy Markdown

Fixes #1310

@markwallace-microsoft markwallace-microsoft added the python Usage: [Issues, PRs], Target: Python label Oct 13, 2025
@github-actions github-actions Bot changed the title Handle dict input for MagenticStartMessage Python: Handle dict input for MagenticStartMessage Oct 13, 2025
@markwallace-microsoft

markwallace-microsoft commented Oct 13, 2025

Copy link
Copy Markdown
Contributor

@tonybaloney
tonybaloney marked this pull request as ready for review October 14, 2025 00:14
Copilot AI review requested due to automatic review settings October 14, 2025 00:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for handling dictionary input when starting a Magentic workflow, specifically for dictionaries containing an "input" key. The change allows the workflow to accept dictionary messages and extract the text content from the "input" field.

  • Added dictionary input handling for MagenticStartMessage creation
  • Extracts text from dict["input"] and converts it to a MagenticStartMessage using the existing from_string method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

message = MagenticStartMessage.from_string(message)
elif isinstance(message, ChatMessage):
message = MagenticStartMessage(task=message)
elif isinstance(message, dict) and "input" in message:

Copilot AI Oct 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dict input handling lacks validation. Consider validating that message['input'] is a string before passing it to from_string(), as the method expects a string parameter but could receive any type from the dict.

Suggested change
elif isinstance(message, dict) and "input" in message:
elif isinstance(message, dict) and "input" in message:
if not isinstance(message["input"], str):
raise TypeError(f"Expected 'input' to be a string, got {type(message['input']).__name__}")

Copilot uses AI. Check for mistakes.
@moonbox3

Copy link
Copy Markdown
Contributor

Hi @tonybaloney, thanks for working on this. I've done some refactoring to improve the orchestration start message types for Magentic, Concurrent, and Sequential patterns to be more reflective of agent patterns (and the input types they accept). This now allows for DevUI to properly introspect the Magentic input message type.

You can find this in an open PR I have: #1538

image

@moonbox3

Copy link
Copy Markdown
Contributor

There's been a lot of movement/changes related to Magnetic. Please have a look at the latest public APIs. Because the pattern is running agents, we've standardized input to what an agent can handle - str | list[str] | ChatMessage | list[ChatMessage]. Closing this PR.

@moonbox3 moonbox3 closed this Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

devui support for Magentic workflow

5 participants