kongono / ai
Kongono v1 standalone PHP 8.5 multi-provider AI SDK (OpenAI, Anthropic Claude, Google Gemini, Groq, Ollama), live streaming, structured DTO extraction, PromptGuard canary injection defense, EvalRunner, RAG KnowledgeBase, governed AgentRunner, and JSON-RPC 2.0 MCP server.
v1.25.0
2026-11-26 18:20 UTC
Requires
- php: >=8.5.13
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- kongono/core: ^1.23
- kongono/validation: ^1.23
Requires (Dev)
None
Suggests
- kongono/database: Required only when using PgVectorStore (PostgreSQL pgvector) or HybridSearch (RRF).
Provides
None
Conflicts
None
Replaces
None
README
Read-only subtree split of
kongono/framework. Open issues and pull requests in the main monorepo.
Standalone, zero-Symfony PHP 8.5.13+ multi-provider AI SDK, prompt-injection defense, RAG engine, eval harness, and Model Context Protocol (MCP) server usable in any PHP application:
- 5 Native Providers + Failover, Streaming & Multimodal Vision/PDF: OpenAI, Anthropic Claude, Google Gemini, Groq, and local Ollama (
AiClient::fromEnv(),FallbackProvider) overext-curlwith magic-byte-verifiedAttachment::image()/Attachment::pdf()support for Receipt OCR, photo triage, and document extraction. - Typed Structured Outputs: Extract validated PHP 8.5 readonly DTOs directly from text, images, or PDFs via
$ai->structured($prompt, MyDto::class, attachments: [Attachment::image($bytes, 'image/jpeg')]). - Prompt Injection Defense & Red-Team Evals:
PromptGuard+UntrustedInputstructural isolation, canary exfiltration blocking, andEvalRunner. - Governed Agents, RAG & MCP:
AgentPrincipal/AgentRunnerwith#[RequiresApproval]and hard USD/token caps, 5-lineKnowledgeBaseRAG (MemoryVectorStoreor optionalPgVectorStore+HybridSearch), and native JSON-RPC 2.0McpServer.
Installation
composer require kongono/ai
Example
<?php declare(strict_types=1); use Kongono\Ai\{AiClient, Message}; use Kongono\Ai\Security\{PromptGuard, UntrustedInput}; $ai = AiClient::fromEnv(); // OPENAI_API_KEY, ANTHROPIC_API_KEY, GEMINI_API_KEY, GROQ_API_KEY, or OLLAMA_HOST $guard = new PromptGuard(); $protected = $guard->buildProtectedSystemPrompt('Summarize the user ticket concisely.'); $reply = $ai->chat([ Message::system($protected['prompt']), Message::user($guard->wrapUntrusted(new UntrustedInput($rawTicket, 'ticket'))), ]);
Documentation & License
- Full documentation: https://kongono.com/docs.html#ai-rag
- Monorepo & issues: https://github.com/kongono/framework
- License: MIT