Download the PHP package utopia-php/agents without Composer
On this page you can find all versions of the php package utopia-php/agents. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download utopia-php/agents
More information about utopia-php/agents
Files in utopia-php/agents
Informations about the package agents
Utopia Agents
Utopia Agents is a simple and lite library for building and managing AI agents in PHP applications. This library provides a collection of tools and utilities for creating, managing, and orchestrating AI agents with support for multiple AI providers. This library is maintained by the Appwrite team.
Although this library is part of the Utopia Framework project it is dependency free and can be used as standalone with any other PHP project or framework.
Getting Started
Install using composer:
System Requirements
Utopia Framework requires PHP 8.0 or later. We recommend using the latest PHP version whenever possible.
Features
- Multiple AI Providers - Support for OpenAI, Anthropic, Deepseek, Perplexity, XAI, Gemini, and OpenRouter APIs
- Flexible Message Types - Support for text and structured content in messages
- Message Attachments - Attach files (for example images) directly to conversation turns
- Conversation Management - Easy-to-use conversation handling between agents and users
- Model Selection - Choose from various AI models (GPT-4, Claude 3, Deepseek Chat, Sonar, Grok, etc.)
- Parameter Control - Fine-tune model behavior with temperature and token controls
- Streaming Output - Consume incremental model output through callback-driven Server-Sent Events (SSE) streams
Usage
Basic Example
Using Different AI Providers
OpenAI
Available OpenAI Models:
MODEL_GPT_5_NANO: GPT-5 Nano - Small GPT-5 variant optimized for low latency and cost-sensitive workloadsMODEL_GPT_4_5_PREVIEW: GPT-4.5 Preview - OpenAI's most advanced model with enhanced reasoning, broader knowledge, and improved instruction followingMODEL_GPT_4_1: GPT-4.1 - Advanced large language model with strong reasoning capabilities and improved context handlingMODEL_GPT_4O: GPT-4o - Multimodal model optimized for both text and image processing with faster response timesMODEL_O4_MINI: o4-mini - Compact version of GPT-4o offering good performance with higher throughput and lower latencyMODEL_O3: o3 - Balanced model offering good performance for general language tasks with efficient resource usageMODEL_O3_MINI: o3-mini - Streamlined model optimized for speed and efficiency while maintaining good capabilities for routine tasks
Anthropic
Available Anthropic Models:
MODEL_CLAUDE_4_OPUS: Flagship model with exceptional reasoning for the most demanding tasksMODEL_CLAUDE_3_OPUS: Premium model with superior performance on complex analysis and creative workMODEL_CLAUDE_4_SONNET: Intelligent and responsive model optimized for productivity workflowsMODEL_CLAUDE_3_7_SONNET: Enhanced model with improved reasoning and coding capabilitiesMODEL_CLAUDE_3_5_SONNET: Versatile model balancing capability and speed for general useMODEL_CLAUDE_3_5_HAIKU: Ultra-fast model for quick responses and lightweight processingMODEL_CLAUDE_3_HAIKU: Rapid model designed for speed and efficiency on straightforward tasks
Deepseek
Available Deepseek Models:
MODEL_DEEPSEEK_CHAT: General-purpose chat modelMODEL_DEEPSEEK_CODER: Specialized for code-related tasks
Perplexity
Available Perplexity Models:
MODEL_SONAR: General-purpose search modelMODEL_SONAR_PRO: Enhanced search modelMODEL_SONAR_DEEP_RESEARCH: Advanced search modelMODEL_SONAR_REASONING: Reasoning modelMODEL_SONAR_REASONING_PRO: Enhanced reasoning model
XAI
Available XAI Models:
MODEL_GROK_3: Latest Grok modelMODEL_GROK_3_MINI: Mini version of Grok modelMODEL_GROK_2_IMAGE: Latest Grok model with image support
OpenRouter
- Named constants are provided for popular models from major providers (OpenAI, Anthropic, Google, Meta, DeepSeek, Mistral, xAI)
Models::MODELScontains the full model catalog; the adapter defaults toopenai/gpt-4o- Arbitrary model IDs like
'openai/gpt-5-nano'or'anthropic/claude-sonnet-4'are also accepted directly httpRefererandxTitleare optional and enable OpenRouter app attribution headers- To re-sync constants from the live OpenRouter API, run
php scripts/sync-openrouter-models.php
Managing Conversations
Streaming Responses (SSE)
The conversation layer supports incremental output streaming through Conversation::listen(callable $listener).
The callback receives each text delta as it arrives from the provider's SSE stream, while send() still returns the final aggregated Message.
Streaming in CLI / Worker Contexts
Exposing Model Output as HTTP SSE
Operational Notes
- Streaming is adapter-dependent and available for chat-capable providers that expose incremental output.
- The listener is optional; if omitted, responses are still collected and returned as a single final message.
- Keep callbacks non-blocking and lightweight to avoid slowing downstream token delivery.
- When serving SSE over HTTP, send
Content-Type: text/event-stream, flush frequently, and disable intermediary buffering where applicable. - Usage metrics (input/output tokens and cache counters, where supported) remain available after
send()completes.
Working with Messages
Attachment Examples
Attachment Limits and Validation
Attachment validation is enforced by default in Conversation::message(...).
Guardrail values come from the selected adapter (not from conversation-level user configuration).
Default adapter guardrails:
- Max attachments per message:
10 - Max binary size per attachment:
5_000_000bytes (~5 MB) - Max total attachment payload per turn:
20_000_000bytes (~20 MB) - MIME allowlist:
image/png,image/jpeg,image/webp,image/gif - Reject empty or unreadable payloads
- Adapter compatibility checks (attachment type must be supported by the selected adapter)
To customize limits, create an adapter subclass and override limit methods:
Schema and Schema Objects
You can use the Schema class to define a schema for a structured output. The Schema class utilizes SchemaObjects to define each property of the schema, following the JSON Schema format.
Tests
To run all unit tests, use the following Docker command:
To run static code analysis, use the following Psalm command:
Security
We take security seriously. If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
Contributing
All code contributions - including those of people having commit access - must go through a pull request and be approved by a core developer before being merged. This is to ensure a proper review of all the code.
We truly ❤️ pull requests! If you wish to help, you can learn more about how you can contribute to this project in the contribution guide.
Copyright and license
The MIT License (MIT) http://www.opensource.org/licenses/mit-license.php