Search by

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

This package is auto-updated.

Last update: 2026-11-30 04:43:13 UTC


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) over ext-curl with magic-byte-verified Attachment::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 + UntrustedInput structural isolation, canary exfiltration blocking, and EvalRunner.
  • Governed Agents, RAG & MCP: AgentPrincipal / AgentRunner with #[RequiresApproval] and hard USD/token caps, 5-line KnowledgeBase RAG (MemoryVectorStore or optional PgVectorStore + HybridSearch), and native JSON-RPC 2.0 McpServer.

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