Download the PHP package agentphp/sdk without Composer
On this page you can find all versions of the php package agentphp/sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package sdk
Short Description A comprehensive PHP SDK for building AI conversational agents with support for multiple LLM providers (OpenAI, Anthropic, Google), tools, streaming, and human-in-the-loop workflows
License MIT
Homepage https://github.com/agentphp/sdk
Informations about the package sdk
AgentPHP SDK
A comprehensive PHP SDK for building AI conversational agents with support for multiple LLM providers (OpenAI, Anthropic, Google), tools, streaming, and human-in-the-loop workflows.
Features
- Multiple LLM Providers: OpenAI (GPT-4), Anthropic (Claude), Google (Gemini)
- Tool System: Define and execute custom tools with automatic validation
- Streaming: Real-time token streaming for responsive UIs
- Middleware Pipeline: Logging, retry, rate limiting, caching
- Memory Management: Conversation and sliding window memory
- Human-in-the-Loop: Approval workflows for sensitive operations
- Framework Integration: Laravel and Symfony support
Requirements
- PHP 8.0 or higher
- Composer
- Guzzle HTTP client
Installation
Quick Start
Table of Contents
- Standalone Usage (Legacy PHP)
- Laravel Integration
- Symfony Integration
- Providers
- System Prompts
- Tools
- Streaming
- Middleware
- Human-in-the-Loop
- Error Handling
Standalone Usage (Legacy PHP)
Basic Chat
Conversation Memory
Configuration Options
Complete Standalone Example
Laravel Integration
Installation
The service provider is auto-discovered. For manual registration:
Publish Configuration
Configuration
Environment Variables
Using the Facade
Using Dependency Injection
Using AgentBuilder in Laravel
Registering Tools in Laravel
You can register tools directly on the Agent instance:
Or register a single tool:
Alternatively, you can register tools globally in the ServiceProvider (less recommended):
Laravel Streaming Response
Symfony Integration
Installation
Enable the Bundle
Configuration
Environment Variables
Using in Controllers
Symfony Streaming Response
Using AgentBuilder in Symfony
Registering Tools as Services
Providers
OpenAI
Anthropic (Claude)
Google (Gemini)
Custom Provider
Provider Factory
System Prompts
System prompts define the behavior and personality of your agent.
Basic System Prompt
Detailed System Prompt
Dynamic System Prompts
Multi-Language Support
Role-Based System Prompts
Tools
Tools allow your agent to perform actions and access external data.
Creating a Tool
Extend AbstractTool and implement the handle() method:
The AbstractTool base class:
- Provides
execute(array $arguments): ToolResultwhich wraps yourhandle()result - Automatically converts your return value to a
ToolResult::success() - Catches exceptions and converts them to
ToolResult::failure() - Sets
requiresApproval()tofalseby default (override if needed)
Registering Tools
Tool Schema Builder
Tool with Approval Required
For sensitive operations, set $requiresApproval = true:
Using Tools with Agent
Tool Registry
Manual Tool Execution
Streaming
Streaming allows you to receive tokens in real-time as they are generated. All providers (OpenAI, Anthropic, Google) support streaming.
How Streaming Works
When you call $agent->chatStream(), it returns a StreamInterface object. This object provides methods to iterate over chunks of text as they arrive from the LLM provider, instead of waiting for the complete response.
Legacy PHP - Terminal/CLI Streaming
Complete example for running in terminal:
Run it:
Legacy PHP - Web Browser SSE Streaming
Complete example for streaming to a web browser using Server-Sent Events (SSE):
Backend (stream.php):
Frontend (index.html):
Legacy PHP - AJAX POST Streaming
For POST requests with the Fetch API:
Backend (api_stream.php):
Frontend JavaScript (Fetch API):
StreamChunk Methods
Each chunk in the stream provides these methods:
Getting the Complete Response After Streaming
Streaming with Different Providers
All providers use the same streaming interface:
Error Handling in Streams
Nginx Configuration for SSE
If using nginx, add this to your location block:
Apache Configuration for SSE
For Apache with mod_php, streaming should work out of the box. If using PHP-FPM:
Middleware
Middleware allows you to intercept and modify requests/responses.
Built-in Middleware
Logging Middleware
Retry Middleware
Rate Limit Middleware
Timeout Middleware
Combining Middleware
Custom Middleware
Authentication Middleware
Content Filter Middleware
Human-in-the-Loop
Enable approval workflows for sensitive operations.
Basic Setup
Custom Approval Handler
Auto-Approval for Development
Error Handling
Development
Setup
Testing
Contributing
Contributions are welcome! Please read our Contributing Guide for details.
License
The MIT License (MIT). Please see License File for more information.
Security
If you discover any security-related issues, please email [email protected] instead of using the issue tracker.
All versions of sdk with dependencies
guzzlehttp/guzzle Version ^7.0
psr/http-client Version ^1.0
psr/log Version ^1.1 || ^2.0 || ^3.0
psr/simple-cache Version ^3.0