@@ -37,9 +37,8 @@ Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP ve
3737<?php
3838
3939use Utopia\Agents\Agent;
40+ use Utopia\Agents\Message;
4041use Utopia\Agents\Roles\User;
41- use Utopia\Agents\Messages\Text;
42- use Utopia\Agents\Messages\Image;
4342use Utopia\Agents\Conversation;
4443use Utopia\Agents\Adapters\OpenAI;
4544
@@ -53,7 +52,7 @@ $user = new User('user-1', 'John');
5352// Start a conversation
5453$conversation = new Conversation($agent);
5554$conversation
56- ->message($user, new Text ('What is artificial intelligence?'))
55+ ->message($user, new Message ('What is artificial intelligence?'))
5756 ->send();
5857```
5958
@@ -185,7 +184,7 @@ $openrouter = new OpenRouter(
185184``` php
186185use Utopia\Agents\Roles\User;
187186use Utopia\Agents\Roles\Assistant;
188- use Utopia\Agents\Messages\Text ;
187+ use Utopia\Agents\Message ;
189188
190189// Create a conversation with system instructions
191190$agent = new Agent($adapter);
@@ -200,15 +199,15 @@ $assistant = new Assistant('assistant-1');
200199
201200$conversation = new Conversation($agent);
202201$conversation
203- ->message($user, new Text ('Hello!'))
204- ->message($assistant, new Text ('Hi! How can I help you today?'))
205- ->message($user, new Text ('What is the capital of France?'));
202+ ->message($user, new Message ('Hello!'))
203+ ->message($assistant, new Message ('Hi! How can I help you today?'))
204+ ->message($user, new Message ('What is the capital of France?'));
206205
207206// Add a user message with attachments
208207$conversation->message(
209208 $user,
210- new Text ('Please summarize this screenshot'),
211- [new Image ($imageBinaryContent)]
209+ new Message ('Please summarize this screenshot'),
210+ [new Message ($imageBinaryContent)]
212211);
213212
214213// Send and get response
@@ -226,8 +225,8 @@ The callback receives each text delta as it arrives from the provider's SSE stre
226225use Utopia\Agents\Agent;
227226use Utopia\Agents\Conversation;
228227use Utopia\Agents\Adapters\OpenAI;
228+ use Utopia\Agents\Message;
229229use Utopia\Agents\Roles\User;
230- use Utopia\Agents\Messages\Text;
231230
232231$agent = new Agent(new OpenAI('your-api-key', OpenAI::MODEL_GPT_4O));
233232$conversation = new Conversation($agent);
@@ -237,7 +236,7 @@ $conversation
237236 ->listen(function (string $chunk): void {
238237 echo $chunk; // render partial output as soon as it is received
239238 })
240- ->message($user, new Text ('Explain vector databases in one paragraph.'));
239+ ->message($user, new Message ('Explain vector databases in one paragraph.'));
241240
242241$final = $conversation->send(); // final, complete assistant message
243242```
@@ -248,8 +247,8 @@ $final = $conversation->send(); // final, complete assistant message
248247use Utopia\Agents\Agent;
249248use Utopia\Agents\Conversation;
250249use Utopia\Agents\Adapters\OpenAI;
250+ use Utopia\Agents\Message;
251251use Utopia\Agents\Roles\User;
252- use Utopia\Agents\Messages\Text;
253252
254253header('Content-Type: text/event-stream');
255254header('Cache-Control: no-cache');
@@ -269,7 +268,7 @@ $conversation
269268 }
270269 flush();
271270 })
272- ->message($user, new Text ('Write a short release note for today''s deployment.'));
271+ ->message($user, new Message ('Write a short release note for today''s deployment.'));
273272
274273$final = $conversation->send();
275274
@@ -291,26 +290,24 @@ flush();
291290### Working with Messages
292291
293292``` php
294- use Utopia\Agents\Messages\Text;
295- use Utopia\Agents\Messages\Image;
293+ use Utopia\Agents\Message;
296294
297- // Text message
298- $textMessage = new Text ('Hello, how are you?');
295+ // Message content is always text
296+ $textMessage = new Message ('Hello, how are you?');
299297
300- // Image message
301- $imageMessage = new Image ($imageBinaryContent);
298+ // Attachments are binary payloads (for example images)
299+ $imageMessage = new Message ($imageBinaryContent);
302300$mimeType = $imageMessage->getMimeType(); // Get the MIME type of the image
303301
304302// Attach image to a text prompt
305- $message = (new Text ('Describe this image'))->addAttachment($imageMessage);
303+ $message = (new Message ('Describe this image'))->addAttachment($imageMessage);
306304```
307305
308306### Attachment Examples
309307
310308``` php
311309use Utopia\Agents\Conversation;
312- use Utopia\Agents\Messages\Image;
313- use Utopia\Agents\Messages\Text;
310+ use Utopia\Agents\Message;
314311use Utopia\Agents\Roles\User;
315312
316313$conversation = new Conversation($agent);
@@ -319,23 +316,23 @@ $user = new User('user-1', 'John');
319316// 1) Attach a single image in the same turn
320317$conversation->message(
321318 $user,
322- new Text ('What is shown here?'),
323- [new Image (file_get_contents(__DIR__.'/images/screenshot.png'))]
319+ new Message ('What is shown here?'),
320+ [new Message (file_get_contents(__DIR__.'/images/screenshot.png'))]
324321);
325322
326323// 2) Attach multiple images in one turn
327324$conversation->message(
328325 $user,
329- new Text ('Compare these two images and list differences.'),
326+ new Message ('Compare these two images and list differences.'),
330327 [
331- new Image (file_get_contents(__DIR__.'/images/before.png')),
332- new Image (file_get_contents(__DIR__.'/images/after.png')),
328+ new Message (file_get_contents(__DIR__.'/images/before.png')),
329+ new Message (file_get_contents(__DIR__.'/images/after.png')),
333330 ]
334331);
335332
336333// 3) Build and reuse a message object with attachments
337- $prompt = (new Text ('Extract visible text from this receipt'))
338- ->addAttachment(new Image (file_get_contents(__DIR__.'/images/receipt.jpg')));
334+ $prompt = (new Message ('Extract visible text from this receipt'))
335+ ->addAttachment(new Message (file_get_contents(__DIR__.'/images/receipt.jpg')));
339336
340337$conversation->message($user, $prompt);
341338```
0 commit comments