Python: Handle dict input for MagenticStartMessage - #1446
Conversation
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
| 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__}") |
|
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
|
|
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. |

Fixes #1310