This file provides guidance to AI Coding Agents when working with code in this repository.
Neuron AI is a PHP framework for creating AI agents with features like chat history, tool integration, RAG (Retrieval Augmented Generation), structured output, and workflow orchestration. The codebase follows PSR-12 standards with strict typing and modern PHP 8.1+ features.
# Run tests
composer test
# or directly: vendor/bin/phpunit --colors=always
# Run static analysis (PHPStan level 5)
composer analyse
# or directly: vendor/bin/phpstan analyse --memory-limit=1G -v
# Fix code style (PHP CS Fixer with PSR-12)
composer format
# or directly: php-cs-fixer fix --allow-risky=yes
# Refactor code (Rector)
composer refactor
# or directly: vendor/bin/rector
# Install dependencies
composer install# Run specific test class
vendor/bin/phpunit tests/AgentTest.php
# Run specific test method
vendor/bin/phpunit --filter testMethodName
# Run tests with coverage
vendor/bin/phpunit --coverage-html coverage/Each module is placed in its own namespace under src/. Sub-modules are grouped into sub-namespaces.
Agent System: The framework revolves around three main entity types:
Agent(src/Agent.php) - Base agent class with chat, streaming, and structured output capabilitiesRAG(src/RAG/RAG.php) - Extends Agent with vector search and document retrievalWorkflow(src/Workflow/Workflow.php) - Node-based execution graphs for complex agentic processes
Provider Architecture: Abstracted AI provider system supporting multiple LLM services:
- All providers implement
AIProviderInterface(src/Providers/AIProviderInterface.php) - Supported: Anthropic, OpenAI, Gemini, Ollama, HuggingFace, Mistral, Grok
- Each provider has its own MessageMapper for API-specific formatting
Tool System: Extensible tool framework for agent capabilities:
- Individual tools implement
ToolInterface(src/Tools/ToolInterface.php) - Toolkits group related tools (src/Tools/Toolkits/)
- Built-in toolkits: Calculator, MySQL, PostgreSQL, Tavily, Zep, AWS SES, Jina, Riza, Supadata
RAG Components:
- Vector stores: Support for Pinecone, Chroma, Elasticsearch, Qdrant, Typesense, and more
- Embeddings providers: OpenAI, Gemini, Ollama, Voyage
- Document loaders: PDF, HTML, text files with chunking strategies
- Pre/post processors for query transformation and document reranking
Chat History: Pluggable memory systems (InMemory, File, SQL-based)
Structured Output: JSON schema-based extraction with PHP class mapping using attributes
MCP Integration: Model Context Protocol server connector for external tool integration
The codebase uses PHP traits extensively for modular functionality:
StaticConstructor- Providesmake()static factory methodObservable- Observer pattern implementation for monitoringResolveProvider,ResolveTools,ResolveChatHistory- Dependency resolution
All major components support the Observer pattern for monitoring and debugging, integrating with Inspector APM.
src/- Main source code with PSR-4 autoloading underNeuronAI\namespacesrc/Providers/- AI provider implementationssrc/Tools/- Tool system and built-in toolkitssrc/RAG/- RAG system componentssrc/Workflow/- Workflow orchestration systemsrc/Chat/- Chat messaging and history managementsrc/Observability/- Monitoring and event systemtests/- PHPUnit tests mirroring src/ structure
- Strict typing enforced (
declare(strict_types=1)) - PSR-12 coding standard
- PHPStan level 5 static analysis
- 100% type coverage requirements (return, param, property)
- All classes use constructor property promotion where applicable
- Extensive use of PHP 8.1+ features (enums, readonly properties, etc.)
Key environment variables for development:
INSPECTOR_INGESTION_KEY- For monitoring/observability- Various provider API keys (ANTHROPIC_API_KEY, OPENAI_API_KEY, etc.)
- Database connection strings for vector store testing