How raedbari/ai-agent-platform works
Purpose and Runtime
This is a Laravel/PHP application for configuring AI agents, clients, and knowledge bases, then serving retrieval-augmented chat responses. Laravel HTTP, Eloquent, queues, Artisan, and Filament provide the runtime surfaces. The primary application is rooted at artisan, bootstrap/app.php, and public/index.php; ai-agent-rag-v2-patch/ and rag-phase-backup-20260721-100426/ are bundled patch/backup trees rather than the main runtime source.
Entry Points and Interfaces
HTTP routing is defined in routes/web.php and routes/api.php; agent-facing request handling converges on app/Http/Controllers/AgentController.php. A browser-facing playground/chat preview is provided by resources/views/playground.blade.php and resources/views/components/chat-preview.blade.php. Administrative management is implemented through the Filament panel provider and resources:
• app/Providers/Filament/NezarPanelProvider.php
• app/Filament/Resources/Agents/AgentResource.php
• app/Filament/Resources/Clients/ClientResource.php
Domain and Persistence Boundary
Eloquent models define the core domain: agents hold behavior/rules, clients provide tenancy/ownership context, knowledge bases are source documents, and chunks are the retrieval unit.
• app/Models/Agent.php
• app/Models/Client.php
• app/Models/KnowledgeBase.php
• app/Models/KnowledgeChunk.php
Database migrations establish these entities, agent-to-knowledge-base evolution, and chunk persistence, notably database/migrations/2026_07_20_131430_create_knowledge_chunks_table.php and database/migrations/2026_02_23_195623_upgrade_knowledge_bases_for_agents.php. The relational database is the system of record for document metadata, indexing state, chunk text, and embeddings.
Knowledge Indexing Pipeline
Knowledge-base lifecycle events are observed and dispatched to background indexing, separating document writes from potentially expensive extraction and embedding work:
• app/Observers/KnowledgeBaseObserver.php
• app/Jobs/IndexKnowledgeBase.php
• app/Services/KnowledgePipelineService.php
The pipeline obtains source content, splits it into bounded chunks, generates embeddings, and persists KnowledgeChunk records:
• app/Services/KnowledgeContentService.php
• app/Services/KnowledgeChunker.php
• app/Services/EmbeddingService.php
• app/Services/KnowledgeIndexingService.php
Queue infrastructure is configured through config/queue.php; the knowledge:reindex-style operational entry point is app/Console/Commands/ReindexKnowledge.php.
Retrieval and RAG Assembly
At chat time, the controller/service layer resolves the target agent and its permitted knowledge bases, embeds the user query, scores stored chunks, and selects relevant context. Retrieval is encapsulated in app/Services/KnowledgeRetrievalService.php, with RAG controls in config/rag.php. This is an application-managed vector workflow over database-stored embeddings rather than a separately visible vector-database integration.
The selected context, agent instructions/critical rules, and user message are passed to the AI layer. This boundary is centered on:
• app/Http/Controllers/AgentController.php
• app/Services/AIService.php
• app/Services/KnowledgeRetrievalService.php
External Services and Configuration
The application has explicit Gemini and embeddings configuration, indicating external model/embedding-provider calls are isolated behind service classes rather than embedded in controllers:
• config/gemini.php
• config/embeddings.php
• app/Services/AIService.php
• app/Services/EmbeddingService.php
Credentials and deployment-specific provider settings belong in environment configuration (.env.example). Laravel cache, database, filesystem, queue, and Sanctum configuration provide the main infrastructure boundaries in config/.
Administrative Control Flow
Filament resources manage agents and clients, while relation managers attach knowledge bases to those scopes:
• app/Filament/Resources/Agents/RelationManagers/KnowledgeBasesRelationManager.php
• app/Filament/Resources/Clients/RelationManagers/KnowledgeBasesRelationManager.php
Thus, administrative changes flow from Filament/Eloquent writes through the knowledge-base observer into asynchronous indexing; runtime chat flows independently through API/controller retrieval and AI generation.
Main entry points: KnowledgePipelineService.php Knowledge pipeline · KnowledgeRetrievalService.php Knowledge retrieval · KnowledgeBase.php Agent, client & knowledge models · AgentController.php Agent controller
Components 19
Interfaces
- Laravel application · HTTP, Artisan, queues, and Eloquent runtime.
bootstrap/app.php - Web & API routes
routes/api.php - Chat playground
resources/views/playground.blade.php - Filament admin panel
app/Providers/Filament/NezarPanelProvider.php - Agent administration
app/Filament/Resources/Agents/AgentResource.php - Client administration
app/Filament/Resources/Clients/ClientResource.php
Domain & Storage
- Agent, client & knowledge models · Defines tenancy, agents, knowledge bases, and chunks.
app/Models/KnowledgeBase.php - Relational database · Stores metadata, indexing state, chunks, and embeddings.
database/migrations/2026_07_20_131430_create_knowledge_chunks_table.php
Knowledge Indexing
- Knowledge base observer
app/Observers/KnowledgeBaseObserver.php - Index knowledge-base job
app/Jobs/IndexKnowledgeBase.php - Knowledge pipeline · Coordinates extraction, chunking, embedding, and persistence.
app/Services/KnowledgePipelineService.php - Content extraction
app/Services/KnowledgeContentService.php - Knowledge chunker
app/Services/KnowledgeChunker.php - Embedding service · Generates document and query embeddings.
app/Services/EmbeddingService.php - Knowledge reindex command
app/Console/Commands/ReindexKnowledge.php
Chat & RAG
- Agent controller · Converges agent-facing chat requests.
app/Http/Controllers/AgentController.php - Knowledge retrieval · Scores stored chunks and selects permitted context.
app/Services/KnowledgeRetrievalService.php - AI generation service · Builds generation requests from instructions, context, and message.
app/Services/AIService.php - Gemini & embedding providers
config/gemini.php
Connections 23
- Laravel application → Web & API routes: serves
- Web & API routes → Agent controller: chat requests
- Chat playground → Agent controller: chat preview
- Filament admin panel → Agent administration: hosts
- Filament admin panel → Client administration: hosts
- Agent administration → Agent, client & knowledge models: manages
- Client administration → Agent, client & knowledge models: manages
- Agent, client & knowledge models → Relational database: persists
- Agent, client & knowledge models → Knowledge base observer: knowledge-base events
- Knowledge base observer → Index knowledge-base job: dispatches
- Knowledge reindex command → Index knowledge-base job: queues reindexing
- Index knowledge-base job → Knowledge pipeline: runs
- Knowledge pipeline → Content extraction: extracts source
- Knowledge pipeline → Knowledge chunker: splits content
- Knowledge pipeline → Embedding service: embeds chunks
- Knowledge pipeline → Relational database: stores chunks
- Embedding service → Gemini & embedding providers: embedding calls
- Agent controller → Knowledge retrieval: retrieves context
- Knowledge retrieval → Embedding service: embeds query
- Knowledge retrieval → Relational database: scores chunks
- Agent controller → AI generation service: requests response
- Knowledge retrieval → AI generation service: selected context
- AI generation service → Gemini & embedding providers: generation calls