Download the PHP package hudhaifas/silverstripe-ai without Composer
On this page you can find all versions of the php package hudhaifas/silverstripe-ai. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hudhaifas/silverstripe-ai
More information about hudhaifas/silverstripe-ai
Files in hudhaifas/silverstripe-ai
Package silverstripe-ai
Short Description Context-aware AI agent for SilverStripe 5 — NeuronAI integration, Human-in-the-Loop, usage tracking, and multi-provider support
License BSD-3-Clause
Homepage https://github.com/hudhaifas/silverstripe-ai
Informations about the package silverstripe-ai
silverstripe-ai
AI-powered features for SilverStripe 5: a context-aware chatbot agent and a human-in-the-loop content generation system.
What you get out of the box
- Agent Widget — a chat sidebar that knows which DataObject the user is viewing, can call tools to read or write data, and asks for confirmation before making changes
- Content Widget — generate AI content for any DataObject field with mandatory user review before saving
- REST API — endpoints under
/api/ai/agentand/api/ai/content - Human-in-the-Loop (HITL) — write tools and content generation pause for user approval
- Zero-dependency storage — conversation history and workflow state use SilverStripe's built-in cache; swap to Redis with one YAML line
- Multi-provider — OpenAI and Anthropic (with prompt caching for up to 90% cost reduction)
- Credit system — free monthly credits + purchasable credits per member, with automatic model tier selection
- Usage logging — every request logged with token counts, cost, and cache metrics
How it works
Agent Widget
Content Widget
Quick start
1. Install
Set your API keys in .env:
2. Configure default models in the CMS
Go to Settings → AI and pick a free-tier model (e.g. gpt-4o-mini) and a paid-tier model (e.g.
claude-sonnet-4-5). Models are seeded automatically on dev/build.
What's auto-configured
The module auto-applies these via YAML — no manual setup required:
| Component | Auto-applied to | Purpose |
|---|---|---|
MemberAIExtension |
Member |
Credit management, model selection, usage tracking |
SiteConfigAIExtension |
SiteConfig |
Default model configuration in Settings → AI |
| API routes | /api/ai/agent/*, /api/ai/content/* |
REST endpoints |
| Cache backends | ChatHistoryInterface, PersistenceInterface |
Conversation history + HITL state |
You only need to create your custom agents, tools, and content extensions.
Agent Widget
1. Create your agent
2. Register the mapping
3. Add the widget to your page
Include $AgentWidget in your template and the JS/CSS loads automatically.
Template example:
The widget reads data-entity-class, data-entity-id, and data-entity-name from the template context.
4. Create tools
Tools are PHP classes that the LLM can call. Each tool defines its name, description, parameters, and execution logic.
Read-only tool (runs immediately):
Write tool (requires HITL approval):
Tools listed in ToolApproval middleware will pause for user confirmation before __invoke() runs.
Content Widget
1. Create a content extension
Extend ContentExtension and implement the four required methods:
2. Apply the extensions
Include $ContentWidget in your template.
Template example:
The content widget requires explicit template variables. Create a method in your controller or use a custom include:
3. Batch generation (skip review)
For bulk operations where you don't want HITL interrupts:
Human-in-the-Loop (HITL)
Agent HITL
HITL is driven by ToolApproval middleware attached to ToolNode::class. No code is needed inside the tool
itself — the interrupt is automatic.
When the LLM calls a tool listed in ToolApproval, the agent pauses before executing it and returns a
resume_token plus a description of the pending action. The frontend shows a confirmation card. The user approves
or rejects. A POST to /api/ai/agent/resume continues the workflow.
The agent's summariseAction() method generates the human-readable description shown in the confirmation card.
Override it in your subclass to customise the message per tool.
Content HITL
Generated content always pauses for review (unless skipReview: true). The workflow returns a resumeToken and
the generated content. Users can:
- Approve — content saved as-is
- Edit — modify the content, then save
- Reject — discard, nothing saved
API Routes
All endpoints are under /api/ai/:
| Endpoint | Method | Description |
|---|---|---|
/api/ai/agent/chat |
POST | Send a message to the agent |
/api/ai/agent/resume |
POST | Resume after HITL approval/rejection |
/api/ai/content/generate |
POST | Generate content for an entity |
/api/ai/content/resume |
POST | Resume with user decision (approve/edit/reject) |
/api/ai/content/save |
POST | Save manually edited content (no AI) |
Request/Response formats
Agent chat:
Agent resume:
Content generate:
Content resume:
Storage backends
Out of the box, conversation history and HITL workflow state are stored in SilverStripe's built-in cache pool (
silverstripe-cache/). This works on any shared hosting or server without Redis.
Optional: Redis
If you want persistent history that survives PHP-FPM restarts, or you're running multiple web nodes, swap to Redis:
RedisChatHistory and RedisPersistence require hudhaifas/silverstripe-cache-helpers (which provides the Redis
connection).
Custom backend
Both backends are resolved through the SilverStripe Injector, so you can bind any implementation:
Credit system
Each member gets a configurable free monthly credit allowance (default $2.00). When free credits run out, the
agent automatically falls back to the free-tier model. Members can purchase additional credits to unlock the
paid-tier model.
Admins can override the model per-member and top up credits from the CMS member record.
CMS Admin UI
Model Usage Statistics
Track cost, tokens, and cache metrics per model over time.
Member AI Credits
Manage per-member usage, free/purchased credits, and model overrides.
Prompt caching (Anthropic)
When using an Anthropic model, the static part of your system prompt (getStaticInstructions()) is automatically
cached. On repeated requests within 5 minutes, cache hits cost ~90% less than regular input tokens. No
configuration needed.
Environment variables
| Variable | Description | Default |
|---|---|---|
OPENAI_API_KEY |
OpenAI API key | — |
ANTHROPIC_API_KEY |
Anthropic API key | — |
AI_VERBOSE_LOGGING |
Log full NeuronAI traces | true |
Configuration reference
Session locking
By default the controller does not call session_write_close() before dispatching to the agent. If you use PHP
file-based sessions and notice other browser tabs blocking during long agent calls, enable this:
Not needed when using database or Redis sessions.
Requirements
- PHP 8.1+
- SilverStripe Framework 5.x
- neuron-core/neuron-ai 3.x
Optional:
hudhaifas/silverstripe-cache-helpers— required only if using the Redis storage backend
License
BSD-3-Clause