Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,5 @@ Each component uses:
- Add @author tags to newly introduced classes by the user
- Prefer classic if statements over short-circuit evaluation when possible
- Define array shapes for parameters and return types
- Use project specific exceptions instead of global exception classes like \RuntimeException, \InvalidArgumentException etc.
- Use project specific exceptions instead of global exception classes like \RuntimeException, \InvalidArgumentException etc.
- NEVER mention Claude as co-author in commits
103 changes: 103 additions & 0 deletions demo/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is a Symfony 7.3 demo application showcasing AI integration capabilities using Symfony AI components. The application demonstrates various AI use cases including RAG (Retrieval Augmented Generation), streaming chat, multimodal interactions, and MCP (Model Context Protocol) server functionality.

## Architecture

### Core Components
- **Chat Systems**: Multiple specialized chat implementations in `src/` (Blog, YouTube, Wikipedia, Audio, Stream)
- **Twig LiveComponents**: Interactive UI components using Symfony UX for real-time chat interfaces
- **AI Agents**: Configured agents with different models, tools, and system prompts
- **Vector Store**: ChromaDB integration for embedding storage and similarity search
- **MCP Tools**: Model Context Protocol tools for extending agent capabilities

### Key Technologies
- Symfony 7.3 with UX components (LiveComponent, Turbo, Typed)
- OpenAI GPT-4o-mini models and embeddings
- ChromaDB vector database
- FrankenPHP runtime
- Docker Compose for ChromaDB service

## Development Commands

### Environment Setup
```bash
# Start ChromaDB service
docker compose up -d

# Install dependencies
composer install

# Set OpenAI API key
echo "OPENAI_API_KEY='sk-...'" > .env.local

# Initialize vector store
symfony console app:blog:embed -vv

# Test vector store
symfony console app:blog:query

# Start development server
symfony serve -d
```

### Testing
```bash
# Run all tests
vendor/bin/phpunit

# Run specific test
vendor/bin/phpunit tests/SmokeTest.php

# Run with coverage
vendor/bin/phpunit --coverage-text
```

### Code Quality
```bash
# Fix code style (uses PHP CS Fixer via Shim)
vendor/bin/php-cs-fixer fix

# Static analysis
vendor/bin/phpstan analyse
```

### MCP Server
```bash
# Start MCP server
symfony console mcp:server

# Test MCP server (paste in terminal)
{"method":"tools/list","jsonrpc":"2.0","id":1}
```

## Configuration Structure

### AI Configuration (`config/packages/ai.yaml`)
- **Agents**: Multiple pre-configured agents (blog, stream, youtube, wikipedia, audio)
- **Platform**: OpenAI integration with API key from environment
- **Store**: ChromaDB vector store for similarity search
- **Indexer**: Text embedding model configuration

### Chat Implementations
Each chat type follows the pattern:
- `Chat` class: Handles message flow and session management
- `TwigComponent` class: LiveComponent for UI interaction
- Agent configuration in `ai.yaml`

### Session Management
Chat history stored in Symfony sessions with component-specific keys (e.g., 'blog-chat', 'stream-chat').

## Development Notes

- Uses PHP 8.4+ with strict typing and modern PHP features
- All AI agents use OpenAI GPT-4o-mini by default
- Vector embeddings use OpenAI's text-ada-002 model
- ChromaDB runs on port 8080 (mapped from container port 8000)
- Application follows Symfony best practices with dependency injection
- LiveComponents provide real-time UI updates without custom JavaScript
- MCP server enables tool integration for AI agents
71 changes: 71 additions & 0 deletions examples/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

This is the examples directory of the Symfony AI monorepo, containing standalone examples demonstrating component usage across different AI platforms. The examples serve as both reference implementations and integration tests.

## Development Commands

### Setup
```bash
# Install dependencies
composer install

# Link local AI components for development
../link

# Start Docker services for store examples
docker compose up -d
```

### Running Examples

#### Standalone Examples
```bash
# Run a specific example
php openai/chat.php

# Run with verbose output to see HTTP and tool calls
php openai/toolcall-stream.php -vvv
```

#### Example Runner
```bash
# Run all examples in parallel
./runner

# Run examples from specific subdirectories
./runner openai mistral

# Filter examples by name pattern
./runner --filter=toolcall
```

### Environment Configuration
Examples require API keys configured in `.env.local`. Copy from `.env` template and add your keys for the platforms you want to test.

## Architecture

### Directory Structure
- Each subdirectory represents a different AI platform (openai/, anthropic/, gemini/, etc.)
- `misc/` contains cross-platform examples
- `rag/` contains RAG (Retrieval Augmented Generation) examples
- `toolbox/` contains utility tools and integrations
- `bootstrap.php` provides common setup and utilities for all examples

### Common Patterns
- All examples use the shared `bootstrap.php` for setup
- Examples follow a consistent structure with platform-specific clients
- Verbose output (`-vv`, `-vvv`) shows detailed HTTP requests and responses
- Examples demonstrate both synchronous and streaming capabilities

### Dependencies
Examples use `@dev` versions of Symfony AI components:
- `symfony/ai-platform`
- `symfony/ai-agent`
- `symfony/ai-store`

## Testing
Examples serve as integration tests. The runner executes them in parallel to verify all components work correctly across different platforms.
94 changes: 94 additions & 0 deletions src/agent/CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in the Agent component.

## Component Overview

The Agent component provides a framework for building AI agents that interact with users and perform tasks. It sits on top of the Platform component and optionally integrates with the Store component for memory capabilities.

## Architecture

The Agent component follows a processor-based architecture:

### Core Classes
- **Agent** (`src/Agent.php`): Main agent class that orchestrates input/output processing
- **AgentInterface** (`src/AgentInterface.php`): Contract for agent implementations
- **Chat** (`src/Chat.php`): High-level chat interface with conversation management
- **Input/Output** (`src/Input.php`, `src/Output.php`): Data containers for processing pipeline

### Processing Pipeline
- **InputProcessorInterface** (`src/InputProcessorInterface.php`): Contract for input processors
- **OutputProcessorInterface** (`src/OutputProcessorInterface.php`): Contract for output processors

### Key Features
- **Memory System** (`src/Memory/`): Conversation memory with embedding support
- **Toolbox** (`src/Toolbox/`): Tool integration for function calling capabilities
- **Structured Output** (`src/StructuredOutput/`): Support for typed responses
- **Message Stores** (`src/Chat/MessageStore/`): Persistence for chat conversations

## Development Commands

### Testing
```bash
# Run all tests
vendor/bin/phpunit

# Run specific test
vendor/bin/phpunit tests/AgentTest.php

# Run tests with coverage
vendor/bin/phpunit --coverage-html coverage/
```

### Code Quality
```bash
# Static analysis (from component directory)
vendor/bin/phpstan analyse

# Code style fixing (from monorepo root)
cd ../../.. && vendor/bin/php-cs-fixer fix src/agent/
```

## Component-Specific Architecture

### Input/Output Processing Chain
The agent uses a middleware-like pattern:
1. Input processors modify requests before sending to the platform
2. Platform processes the request
3. Output processors modify responses before returning

### Built-in Processors
- **SystemPromptInputProcessor**: Adds system prompts to conversations
- **ModelOverrideInputProcessor**: Allows runtime model switching
- **MemoryInputProcessor**: Adds conversation context from memory providers

### Memory Providers
- **StaticMemoryProvider**: Simple in-memory storage
- **EmbeddingProvider**: Vector-based semantic memory using Store component

### Tool Integration
The Toolbox system enables function calling:
- Tools are auto-discovered via attributes
- Fault-tolerant execution with error handling
- Event system for tool lifecycle management

## Dependencies

The Agent component depends on:
- **Platform component**: Required for AI model communication
- **Store component**: Optional, for embedding-based memory
- **Symfony components**: HttpClient, Serializer, PropertyAccess, Clock

## Testing Patterns

- Use `MockHttpClient` for HTTP mocking instead of response mocking
- Test processors independently from the main Agent class
- Use fixtures from `/fixtures` for multimodal content testing
- Prefer `self::assert*` over `$this->assert*` in tests

## Development Notes

- All new classes should have `@author` tags
- Use component-specific exceptions from `src/Exception/`
- Follow Symfony coding standards with `@Symfony` PHP CS Fixer rules
- The component is marked as experimental and subject to BC breaks
Loading