Step class represents multi-modal messages that can contain multiple types of content including text, images, tool uses, and tool results. This is useful for complex interactions that combine different content types in a single message.
Step
A message containing an array of content items (text, images, tool uses, tool results). Location:src/Magic/Chat/Messages/Step.php:10
Constructor
The role of the message sender (User, Assistant, or System)
Array of content items (Text, Image, ToolUse, or ToolResult instances)
Static Methods
user()
Create a user step message with content.Either a string (converted to Text) or array of ContentInterface items
assistant()
Create an assistant step message.Either a string (converted to Text) or array of ContentInterface items
base64Image()
Create a user step with a base64-encoded image.The base64-encoded image data
The MIME type of the image (e.g., ‘image/jpeg’, ‘image/png’)
base64()
Alias forbase64Image(). Create a user step with a base64-encoded image.
The base64-encoded image data
The MIME type of the image
Instance Methods
toArray()
Convert the step to an array representation.fromArray()
Create a Step instance from an array.Array containing role and content data
Content Types
Content types implement theContentInterface and represent different kinds of content within a Step message.
Interface Location: src/Magic/Chat/Messages/Step/ContentInterface.php:8
Text
Text content within a step message. Location:src/Magic/Chat/Messages/Step/Text.php:7
Constructor
The text content
Static Methods
make()
Create a Text content instance.The text content
fromArray()
Create from an array representation.Array with ‘text’ key
Usage Example
Image
Image content within a step message. Supports multiple input sources. Location:src/Magic/Chat/Messages/Step/Image.php:8
Constructor
The base64-encoded image data
The MIME type of the image (e.g., ‘image/jpeg’, ‘image/png’, ‘image/webp’)
Static Methods
path()
Create an Image from a file path.The file system path to the image
raw()
Create an Image from raw image contents.The raw image data
The MIME type of the image
url()
Create an Image from a URL.The URL of the image to fetch
disk()
Create an Image from a Laravel storage disk.The storage disk name
The path on the disk
base64()
Create an Image from base64-encoded data.The base64-encoded image data
The MIME type
fromArray()
Create from an array representation.Array with source information
Deprecated Methods
The following methods are deprecated but still available:fromPath()- Usepath()insteadfromContents()- Useraw()insteadfromUrl()- Useurl()insteadfromDisk()- Usedisk()instead
Usage Example
ToolUse
Represents a tool use request within a step message. Location:src/Magic/Chat/Messages/Step/ToolUse.php:8
Constructor
The ToolCall instance containing the tool name, arguments, and ID
Static Methods
call()
Create a ToolUse from a ToolCall instance.The tool call to wrap
make()
Create a ToolUse with inline parameters.The name of the tool to use
The arguments to pass to the tool
Optional unique identifier for the tool use
fromArray()
Create from an array representation.Array with ‘call’ key containing ToolCall data
Usage Example
ToolResult
Represents the result of a tool execution within a step message. Location:src/Magic/Chat/Messages/Step/ToolResult.php:8
Constructor
The original ToolCall that this result corresponds to
The result of the tool execution (can be string, array, or other data)
Static Methods
output()
Create a ToolResult with the execution output.The original tool call
The tool execution result
fromArray()
Create from an array representation.Array with ‘call’ and ‘output’ keys