### Setup commands Source: https://github.com/symfony/ai/blob/main/examples/AGENTS.md Install dependencies, link local AI components, and start Docker for store examples. ```bash composer install ../link # Link local AI components docker compose up -d # For store examples ``` -------------------------------- ### Start Docker services for store examples Source: https://github.com/symfony/ai/blob/main/examples/README.md Start the required Docker services for store examples that need locally running services. ```bash docker compose up -d ``` -------------------------------- ### Install AI Bundle and Agent Component with Composer Source: https://github.com/symfony/ai/blob/main/docs/index.rst Run this command to install the symfony/ai-bundle and symfony/ai-agent packages, which are required for the quick start example. ```terminal $ composer require symfony/ai-bundle symfony/ai-agent ``` -------------------------------- ### Start demo application Source: https://github.com/symfony/ai/blob/main/AGENTS.md Set up and start the demo Symfony application. Requires composer install and symfony server:start. ```bash cd demo composer install symfony server:start ``` -------------------------------- ### Run example with verbose output Source: https://github.com/symfony/ai/blob/main/examples/README.md Run an example with -vv or -vvv to get more insights into HTTP and tool calls. ```bash php openai/toolcall-stream.php -vvv ``` -------------------------------- ### Clone repository and start Symfony app Source: https://github.com/symfony/ai/blob/main/demo/README.md Checkout the repository, start the Docker environment, and install dependencies. After running these commands, the chatbot UI should be available at https://localhost:8000/. ```shell git clone git@github.com:symfony/ai-demo.git cd ai-demo composer install docker compose up -d symfony serve -d ``` -------------------------------- ### Setup Commands for Symfony AI Demo Source: https://github.com/symfony/ai/blob/main/demo/AGENTS.md Initial setup for the Symfony AI demo: starts PostgreSQL with pgvector, installs dependencies, sets the OpenAI API key (HUGGINGFACE_API_KEY only if wiring HF agents), sets up and indexes the vector store, and serves the app at https://localhost:8000/. ```bash docker compose up -d # Start PostgreSQL (pgvector) composer install echo "OPENAI_API_KEY='sk-...'" > .env.local # HUGGINGFACE_API_KEY only if you wire HF agents # Vector store must be set up before indexing symfony console ai:store:setup blog symfony console ai:store:index blog -vv symfony console ai:store:retrieve blog "Week of Symfony" symfony serve -d # https://localhost:8000/ ``` -------------------------------- ### Add a tool dynamically (partial example) Source: https://github.com/symfony/ai/blob/main/docs/cookbook/dynamic-tools.rst Starts the example for adding a new 'echo' tool dynamically. The source shows the imports and the beginning of the getTools() method, but the full implementation is not displayed on this page. ```php use Symfony\AI\Platform\Tool\ExecutionReference; use Symfony\AI\Platform\Tool\Tool; // ...existing code... public function getTools(): array { $tools = $this->innerToolbox->getTools(); // ... (rest of the method is not shown in the source) } ``` -------------------------------- ### Start Ollama server Source: https://github.com/symfony/ai/blob/main/examples/ollama/README.md Starts the Ollama server, which the examples expect to run on localhost:11434. ```bash ollama serve ``` -------------------------------- ### Install Symfony AI Platform and Agent packages Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/runtime-driven-tool-parameters.html Install the required Symfony AI components for the schema provider example. The AI Bundle is recommended for autoconfiguration. ```bash $ composer require symfony/ai-platform symfony/ai-agent ``` -------------------------------- ### ai:store:setup Command Usage Source: https://github.com/symfony/ai/blob/main/docs/bundles/ai-bundle.rst Prepares the required infrastructure for a store, such as creating database tables, indexes, and collections. Example shows setting up the default chromadb store. ```terminal $ php bin/console ai:store:setup # Setup the chromadb store $ php bin/console ai:store:setup default ``` -------------------------------- ### Run ElevenLabs text-to-speech example with mpg123 Source: https://github.com/symfony/ai/blob/main/examples/elevenlabs/README.md Runs the text-to-speech example and pipes its output to mpg123 for audio playback. Requires the mpg123 tool to be installed. ```bash php elevenlabs/text-to-speech.php | mpg123 - ``` -------------------------------- ### Start MCP Server with Symfony Console Source: https://github.com/symfony/ai/blob/main/demo/README.md Run this command to start the MCP server for testing. ```shell symfony console mcp:server ``` -------------------------------- ### Run examples Source: https://github.com/symfony/ai/blob/main/AGENTS.md Run self-contained examples individually. Many examples require environment variables (see .env files in example directories). ```bash cd examples php anthropic/chat.php php openai/toolcall.php ``` -------------------------------- ### Change to examples directory Source: https://github.com/symfony/ai/blob/main/examples/README.md Navigate into the examples directory before running any commands. ```bash cd examples ``` -------------------------------- ### Install and Initialize AI Mate Source: https://github.com/symfony/ai/blob/main/demo/README.md Install AI Mate as a dev dependency, initialize its configuration, and discover available tools. `mate init` writes instructions to `mate/AGENT_INSTRUCTIONS.md` and a managed block in `AGENTS.md`, and installs skills into `.agents/skills/` with a mirror in `.claude/skills/`. ```shell # Install AI Mate composer require --dev symfony/ai-mate # Initialize configuration vendor/bin/mate init # Discover available tools vendor/bin/mate discover ``` -------------------------------- ### Run store setup and indexing commands Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html Prepares the store infrastructure and runs the indexer from the console. The indexer command uses the 'docs' indexer and a source file path. ```bash $ php bin/console ai:store:setup knowledge_base $ php bin/console ai:store:index docs --source=/path/to/document.txt ``` -------------------------------- ### Run MiniMax text-to-speech examples Source: https://github.com/symfony/ai/blob/main/examples/minimax/README.md Run the MiniMax text-to-speech examples. The synchronous example outputs audio as binary, so pipe it to a player like mpg123. The asynchronous example saves audio to minimax/minimax-speech.mp3. ```bash php minimax/text-to-speech.php | mpg123 - php minimax/text-to-speech-async.php ``` -------------------------------- ### Run MiniMax image, music, and video examples Source: https://github.com/symfony/ai/blob/main/examples/minimax/README.md Run the MiniMax image, music, and video generation examples. The music example outputs audio as binary, so pipe it to a player like mpg123. ```bash php minimax/text-to-image.php php minimax/music.php | mpg123 - php minimax/text-to-video.php ``` -------------------------------- ### Run a standalone example Source: https://github.com/symfony/ai/blob/main/examples/README.md Execute a standalone PHP example script from the command line. ```bash php openai/chat.php ``` -------------------------------- ### Run the example runner Source: https://github.com/symfony/ai/blob/main/examples/README.md Execute the example runner to run examples in parallel sub-processes. ```bash ./runner ``` -------------------------------- ### Running examples Source: https://github.com/symfony/ai/blob/main/examples/AGENTS.md Run individual examples or batch execution with the runner script. Use filters to select specific platforms or patterns. ```bash # Single example php openai/chat.php php openai/toolcall-stream.php -vvv # Batch execution ./runner # All examples ./runner openai mistral # Specific platforms ./runner --filter=toolcall # Pattern filter ``` -------------------------------- ### Run a specific example standalone Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Runs a single example script directly, e.g., object detection. ```bash # Or run a specific example standalone, e.g., object detection: php huggingface/object-detection.php ``` -------------------------------- ### Install Symfony AI Store Component Source: https://github.com/symfony/ai/blob/main/docs/components/store.rst Install the Store component using Composer. This is the required setup step before using any of the store features. ```terminal $ composer require symfony/ai-store ``` -------------------------------- ### Run MiniMax chat examples Source: https://github.com/symfony/ai/blob/main/examples/minimax/README.md Run the MiniMax chat examples: standard chat, streaming chat, and chat with token usage. Requires MINI_MAX_API_KEY in examples/.env.local. ```bash php minimax/chat.php php minimax/chat-as-stream.php php minimax/chat-with-token-usage.php ``` -------------------------------- ### List warm models Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Lists models that are currently warm (available without cold start). ```bash php huggingface/_model.php ai:huggingface:model-list --warm ``` -------------------------------- ### Run Venice examples scripts Source: https://github.com/symfony/ai/blob/main/examples/venice/README.md Shows the commands to execute the provided Venice example scripts: chat, stream, text-to-image, and text-to-video. All require VENICE_API_KEY. ```bash php venice/chat.php php venice/stream.php php venice/text-to-image.php php venice/text-to-video.php ``` -------------------------------- ### Run all examples with runner Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Executes all Hugging Face examples using the provided runner script. ```bash # Run all example with runner: ./runner huggingface ``` -------------------------------- ### Replay recorded examples Source: https://github.com/symfony/ai/blob/main/examples/README.md Replay all recorded examples offline and compare against goldens; no API keys needed. ```bash vendor/bin/phpunit ``` -------------------------------- ### Move store setup options to constructor arguments Source: https://github.com/symfony/ai/blob/main/UPGRADE.md The `setup()` method of the Elasticsearch, MariaDB, MongoDB, OpenSearch, Pinecone, Postgres, Redis, and S3 Vectors stores no longer accepts options. Instead, pass the index definition as constructor arguments. `setup()` now throws an `InvalidArgumentException` if it receives options. The diff shows the change for a Postgres store, moving `vector_size` and `vector_type` to `dimensions` and `vectorType` constructor arguments. ```diff ```diff -$store = new Store($pdo, 'documents'); -$store->setup(['vector_size' => 1024, 'vector_type' => 'halfvec']); +$store = new Store($pdo, 'documents', dimensions: 1024, vectorType: 'halfvec'); +$store->setup(); ``` ``` -------------------------------- ### Development Commands Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/AGENTS.md Development commands for the ai.symfony.com website: install dependencies, start the server, clear cache, list asset paths, and add JS/CSS dependencies via importmap. ```bash # Install dependencies composer install # Start development server symfony server:start # Clear cache bin/console cache:clear # List available asset paths bin/console debug:asset-map # Add a new JS/CSS dependency via importmap bin/console importmap:require ``` -------------------------------- ### Install built-in tools via Composer Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html Several built-in tools ship as standalone packages with Flex recipes; installing them makes them available. ```bash $ composer require symfony/ai-brave-tool $ composer require symfony/ai-wikipedia-tool $ composer require symfony/ai-open-meteo-tool ``` -------------------------------- ### Install and verify an extension with composer and mate debug:capabilities Source: https://github.com/symfony/ai/blob/main/docs/components/mate/creating-extensions.rst Installs the extension as a dev dependency and lists its capabilities. In a project that ran mate init, the Composer plugin runs mate discover after install, adding the extension to mate/extensions.php enabled by default. Without the plugin, run vendor/bin/mate discover manually. ```terminal $ composer require --dev vendor/my-extension $ vendor/bin/mate debug:capabilities --extension=vendor/my-extension ``` -------------------------------- ### Inject and use McpClientInterface with #[Target] Source: https://github.com/symfony/ai/blob/main/docs/bundles/mcp-bundle.rst Autowire a client by parameter name or with #[Target]. The example injects the 'research' client, gets the 'filesystem' connection, lists its tools, and calls the 'read_file' tool. ```php use Symfony\AI\McpBundle\Client\McpClientInterface; use Symfony\Component\DependencyInjection\Attribute\Target; class ResearchService { public function __construct( #[Target('research')] private McpClientInterface $client, ) { } public function run(string $path): string { $connection = $this->client->get('filesystem'); foreach ($connection->getTools() as $tool) { // $tool is an Mcp\Schema\Tool } $result = $connection->callTool('read_file', ['path' => $path]); return $result->content[0]->text; } } ``` -------------------------------- ### Install root dependencies Source: https://github.com/symfony/ai/blob/main/CONTRIBUTING.md Run this command in the repository root to install dependencies, enabling the use of the ./link script. ```bash composer install ``` -------------------------------- ### Install symfony/ai-vertex-ai-platform Source: https://github.com/symfony/ai/blob/main/docs/components/platform/vertexai.rst Install the Symfony AI Vertex AI platform component using Composer. ```terminal $ composer require symfony/ai-vertex-ai-platform ``` -------------------------------- ### Configure a single AI platform (openai) in config/packages/ai.yaml Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html Define a platform under the 'platform' key; each entry becomes a service named 'ai.platform.'. This example configures OpenAI using the OPENAI_API_KEY environment variable. ```yaml # config/packages/ai.yaml aio: platform: openai: api_key: '%env(OPENAI_API_KEY)%' ``` -------------------------------- ### Run tool calling example Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Runs the tool calling example using a Wikipedia tool through Symfony AI's Agent component. Uses Nscale with Qwen/Qwen3-32B; select another provider or model if unavailable. ```bash php huggingface/toolcall.php ``` -------------------------------- ### Install Symfony AI components Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/human-in-the-loop.html Install the required Symfony AI Platform, Agent, and EventDispatcher components. ```bash composer require symfony/ai-platform symfony/ai-agent symfony/event-dispatcher ``` -------------------------------- ### Setup Vector Store with $store->setup() Source: https://github.com/symfony/ai/blob/main/docs/components/store/s3-vectors.rst Create the vector bucket and index before using the store. Call this method once during setup. ```php $store->setup(); ``` -------------------------------- ### Install skills with vendor/bin/mate skills:install Source: https://github.com/symfony/ai/blob/main/docs/components/mate/skills.rst Installs the skills of every enabled extension. The Composer plugin runs this automatically after composer install and composer update; run it manually to sync. Use --dry-run to preview what would be installed, rebuilt, or removed without writing anything. ```terminal $ vendor/bin/mate skills:install ``` -------------------------------- ### Filter runner examples Source: https://github.com/symfony/ai/blob/main/examples/README.md Use the --filter option to run a specific subset of examples. ```bash ./runner --filter=toolcall ``` -------------------------------- ### Install and update dependencies Source: https://github.com/symfony/ai/blob/main/src/platform/AGENTS.md Install or update project dependencies using Composer. ```bash composer install composer update ``` -------------------------------- ### Postgres store setup Source: https://github.com/symfony/ai/blob/main/docs/components/store/bridges.rst Setup for the Postgres store using pgvector. Requires the symfony/ai-postgres-store package, pgvector extension 0.5.0+ (0.7.0 for halfvec and Metric::L1), and PHP ext-pdo. The table and index are created by setup(). Available metrics: Metric::Cosine, Metric::InnerProduct, Metric::L1, Metric::L2 (default). setup() creates a column with 1536 dimensions by default. ```terminal $ composer require symfony/ai-postgres-store ``` ```php use Symfony\AI\Store\Bridge\Postgres\Metric; use Symfony\AI\Store\Bridge\Postgres\StoreFactory; $pdo = new \PDO('pgsql:host=localhost;dbname=mydb', $user, $password); $store = StoreFactory::createStoreFromPdo($pdo, 'documents', vectorFieldName: 'embedding', metric: Metric::Cosine); // or from a Doctrine DBAL connection $store = StoreFactory::createStoreFromDbal($connection, 'documents', vectorFieldName: 'embedding', metric: Metric::Cosine); ``` -------------------------------- ### Install with Composer Source: https://github.com/symfony/ai/blob/main/docs/components/platform/models-dev.rst Install the models.dev bridge package using Composer. ```terminal $ composer require symfony/ai-models-dev-platform ``` -------------------------------- ### Set HUGGINGFACE_KEY in .env.local Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Adds your Hugging Face access token to the .env.local file in the examples directory. Required before running any example. ```bash echo 'HUGGINGFACE_KEY=hf_your_access_key' >> .env.local ``` -------------------------------- ### List models by provider Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Lists models filtered by one or more providers. Single provider example uses hf-inference; multiple providers example uses sambanova and novita. ```bash # Single provider: php huggingface/_model.php ai:huggingface:model-list --provider=hf-inference ``` ```bash # Multiple providers: php huggingface/_model.php ai:huggingface:model-list --provider=sambanova,novita ``` -------------------------------- ### Install and initialize Mate with Composer Source: https://github.com/symfony/ai/blob/main/src/mate/README.md Install the Mate component as a dev dependency, initialize it, and regenerate the autoloader. Run these commands in your project root. ```bash composer require --dev symfony/ai-mate vendor/bin/mate init composer dump-autoload ``` -------------------------------- ### Example JSON file for system prompt Source: https://github.com/symfony/ai/blob/main/docs/bundles/ai-bundle.rst Example content of a JSON file used as a system prompt. The file can be in any text format, including JSON. ```json { "role": "You are an expert code reviewer", "responsibilities": [ "Review code for bugs and potential issues", "Suggest improvements for code quality" ], "tone": "constructive and educational" } ``` -------------------------------- ### List skills Source: https://github.com/symfony/ai/blob/main/docs/components/mate/troubleshooting.rst Run this command to list installed skills. A skill in state 'disabled' is not installed. ```terminal vendor/bin/mate skills:list ``` -------------------------------- ### Install Symfony AI Platform and Agent via Composer Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/chatbot-with-memory.html Run this Composer command to install the required Symfony AI Platform and Agent components. ```bash composer require symfony/ai-platform symfony/ai-agent ``` -------------------------------- ### Pull required Ollama models Source: https://github.com/symfony/ai/blob/main/examples/ollama/README.md Downloads the models used by the examples: llama3.2, nomic-embed-text, and gemma3. Run these commands before starting the server. ```bash ollama pull llama3.2 ollama pull nomic-embed-text ollama pull gemma3 ``` -------------------------------- ### Run Decart examples Source: https://github.com/symfony/ai/blob/main/examples/decart/README.md Commands to run the Decart example scripts for text-to-image, text-to-video, animated image, and image editing. Each script saves its result next to the script. ```bash php decart/text-to-image.php php decart/text-to-video.php php decart/animated-image.php php decart/image-editing.php ``` -------------------------------- ### Install Perplexity bridge with Composer Source: https://github.com/symfony/ai/blob/main/docs/components/platform/perplexity.rst Install the symfony/ai-perplexity-platform bridge. Requires an API key starting with 'pplx-' from the Perplexity API console. ```terminal $ composer require symfony/ai-perplexity-platform ``` -------------------------------- ### Install sqlite-vec Extension Source: https://github.com/symfony/ai/blob/main/docs/components/store/sqlite.rst Install the sqlite-vec extension using the upstream install script. This drops a 'vec0.*' loadable file into the current directory. The extension must be loadable by your SQLite/PDO setup. ```shell curl -L https://github.com/asg017/sqlite-vec/releases/download/v0.1.9/install.sh | sh ``` -------------------------------- ### Initialize PostgreSQL vector store for blog Source: https://github.com/symfony/ai/blob/main/demo/README.md Set up and index the vector store for the blog chatbot context using pgvector. ```shell symfony console ai:store:setup blog symfony console ai:store:index blog -vv ``` -------------------------------- ### Install Redis message store bridge Source: https://github.com/symfony/ai/blob/main/docs/components/agent.rst Install the Redis message store bridge package to persist conversations across requests. This is a prerequisite for using the Redis MessageStore in the next example. ```terminal $ composer require symfony/ai-redis-message-store ``` -------------------------------- ### Install Supabase store bridge Source: https://github.com/symfony/ai/blob/main/docs/components/store/bridges.rst Install the Symfony AI Supabase store bridge via Composer. Requires the pgvector extension and manual database schema setup because the REST API does not allow arbitrary SQL execution. ```terminal $ composer require symfony/ai-supabase-store ``` -------------------------------- ### Example INSTRUCTIONS.md for coding agents Source: https://github.com/symfony/ai/blob/main/docs/components/mate/creating-extensions.rst Markdown file that maps CLI commands to Mate tools and states benefits. Keep it short to minimize context cost. ```markdown ## My Extension Use the Mate tools instead of the CLI for better results: | Instead of... | Use | |----------------------------|--------------------------------------------------------| | `my-cli command` | `vendor/bin/mate tools:call my-tool` | | `my-cli search "term"` | `vendor/bin/mate tools:call my-search --term="term"` | ### Benefits - Structured output that AI can parse - Better error handling and context - Integrated with project configuration ``` -------------------------------- ### Getting the model from token usage metadata Source: https://github.com/symfony/ai/blob/main/docs/components/platform/typesafe.rst Retrieves the model that answered from the token usage metadata. The model is part of the token usage, and this example shows how to access it via getMetadata()->get('token_usage')->getModel(). ```php $result->getMetadata()->get('token_usage')->getModel(); // 'jev-1.13.0' ``` -------------------------------- ### Configure location in environment file Source: https://github.com/symfony/ai/blob/main/docs/components/platform/vertexai.rst Example environment file configuration for the location, recommending us-central1 and commenting out the global location. ```bash # Recommended: Use a region with comprehensive model support GOOGLE_CLOUD_LOCATION=us-central1 # Avoid: Global location has limited model availability # GOOGLE_CLOUD_LOCATION=global ``` -------------------------------- ### Update SimilaritySearch constructor (remove promptTemplate) Source: https://github.com/symfony/ai/blob/main/UPGRADE.md `Bridge\SimilaritySearch\SimilaritySearch` now returns a `Bridge\SimilaritySearch\SimilaritySearchResult` instead of a string, and its `$promptTemplate` argument is removed. The model gets a JSON list of the documents with their id, or `[]` without results. To change what the model gets, register a normalizer for `SimilaritySearchResult`. ```diff -$similaritySearch = new SimilaritySearch($retriever, 'Here are the relevant results:'); +$similaritySearch = new SimilaritySearch($retriever); ``` -------------------------------- ### Simple system prompt as string Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html Configure the assistant agent with a plain string prompt. The model is set to 'gpt-4o-mini'. ```yaml ai: agent: assistant: model: 'gpt-4o-mini' prompt: 'You are a concise assistant for a Symfony application.' ``` -------------------------------- ### Set maxToolCalls to 75 for AgentProcessor Source: https://github.com/symfony/ai/blob/main/UPGRADE.md To raise or lower the cap, pass the desired value. This example sets the cap to 75. ```diff -$processor = new AgentProcessor($toolbox); +$processor = new AgentProcessor($toolbox, maxToolCalls: 75); ``` -------------------------------- ### Access Albert environmental impacts via 'impacts' metadata Source: https://github.com/symfony/ai/blob/main/UPGRADE.md The Albert bridge now exposes environmental impacts under `impacts` instead of `carbon`. Energy consumption is reported directly by Albert, so access it via `get('impacts')['kWh']` instead of `get('carbon')['kWh']['min']`. ```diff -$result->getMetadata()->get('carbon')['kWh']['min']; +$result->getMetadata()->get('impacts')['kWh']; ``` -------------------------------- ### Complete ai-mate configuration in composer.json Source: https://github.com/symfony/ai/blob/main/docs/components/mate/creating-extensions.rst Example of all optional configuration keys under 'extra.ai-mate' in composer.json. Paths are relative to the package root. ```json { "extra": { "ai-mate": { "scan-dirs": ["src"], "includes": ["config/services.php"], "instructions": "INSTRUCTIONS.md", "skills": ["skills"] } } } ``` -------------------------------- ### Get model information Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Displays detailed information about a specific model, including downloads, likes, task, warm status, and inference provider details. ```bash php huggingface/_model.php ai:huggingface:model-info google/vit-base-patch16-224 ``` ```text Hugging Face Model Information ============================== Model: google/vit-base-patch16-224 ----------- ----------------------------- ID google/vit-base-patch16-224 Downloads 2985836 Likes 889 Task image-classification Warm yes ----------- ----------------------------- Inference Provider: ----------------- ----------------------------- Provider hf-inference Status live Provider ID google/vit-base-patch16-224 Task image-classification Is Model Author no ----------------- ----------------------------- ``` -------------------------------- ### Create platform with API key (project-scoped) Source: https://github.com/symfony/ai/blob/main/docs/components/platform/vertexai.rst Create a platform using an API key with a project-scoped endpoint. Requires location and project ID. ```php $platform = Factory::createPlatform( $_ENV['GOOGLE_CLOUD_LOCATION'], $_ENV['GOOGLE_CLOUD_PROJECT'], apiKey: $_ENV['GOOGLE_CLOUD_VERTEX_API_KEY'], ); ``` -------------------------------- ### Run tools:list Source: https://github.com/symfony/ai/blob/main/docs/components/mate/troubleshooting.rst Run this command to establish that the tools exist. ```terminal vendor/bin/mate tools:list ``` -------------------------------- ### ReadAllowPolicy auto-allows read operations Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/human-in-the-loop.html Example policy that auto-allows tool calls whose names contain read-like patterns (read, get, list, search, find, show) and asks the user otherwise. ```php use Symfony\AI\Platform\Result\ToolCall; class ReadAllowPolicy implements PolicyInterface { public function decide(ToolCall $toolCall): PolicyDecision { $name = strtolower($toolCall->getName()); foreach (['read', 'get', 'list', 'search', 'find', 'show'] as $pattern) { if (str_contains($name, $pattern)) { return PolicyDecision::Allow; } } return PolicyDecision::AskUser; } } ``` -------------------------------- ### Define a tool with AsTool attribute Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html Any service carrying the AsTool attribute is auto-registered in the tool registry. This example defines a simple tool that returns a company name. ```php use Symfony\AI\Agent\Toolbox\Attribute\AsTool; #[AsTool('company_name', 'Provides the name of your company')] final class CompanyName { public function __invoke(): string { return 'ACME Corp.'; } } ``` -------------------------------- ### Create platform with API key (global endpoint) Source: https://github.com/symfony/ai/blob/main/docs/components/platform/vertexai.rst Create a platform using an API key with the global endpoint. Simplest setup, does not require the google/auth package. ```php $platform = Factory::createPlatform( apiKey: $_ENV['GOOGLE_CLOUD_VERTEX_API_KEY'], ); ``` -------------------------------- ### StoreInterface add method before and after signature change Source: https://github.com/symfony/ai/blob/main/UPGRADE.md The `StoreInterface::add()` method signature has changed from variadic to accept a single document or an array. The before and after versions are shown with usage examples. ```php public function add(VectorDocument ...$documents): void; // Usage $store->add($document1, $document2); $store->add(...$documents); ``` ```php public function add(VectorDocument|array $documents): void; // Usage $store->add($document); $store->add([$document1, $document2]); $store->add($documents); ``` -------------------------------- ### Initialize Mate in Your Project Source: https://github.com/symfony/ai/blob/main/docs/components/mate.rst Run mate init to set up Mate. It asks which command your coding agent should use to run Mate; answer with a wrapper like ddev exec or symfony php if needed, otherwise accept the default. Creates configuration files and directories. ```terminal $ vendor/bin/mate init ``` -------------------------------- ### Store: implement count() for StoreInterface Source: https://github.com/symfony/ai/blob/main/UPGRADE.md StoreInterface now extends \Countable, so custom stores must implement count(). This example shows adding a count() method that delegates to the underlying connection. ```diff final class MyStore implements StoreInterface { // ... + + public function count(): int + { + return $this->connection->countDocuments(); + } } ``` -------------------------------- ### Configure agent tools explicitly Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html List tools explicitly for an agent, or set 'tools: true' to inject all registered tools. Without the 'tools' option, the agent gets no tools. ```yaml ai: agent: assistant: model: 'gpt-4o-mini' tools: - 'Symfony\AI\Agent\Bridge\SimilaritySearch\SimilaritySearch' ``` -------------------------------- ### Point coding agent at Mate CLI Source: https://github.com/symfony/ai/blob/main/src/mate/README.md List available tools, inspect a tool's schema, call a tool, and read a resource. The generated mate/AGENT_INSTRUCTIONS.md guides agent configuration. ```bash vendor/bin/mate tools:list # list available tools vendor/bin/mate tools:inspect symfony-profiler-list # show a tool's parameters/schema vendor/bin/mate tools:call symfony-profiler-list --limit=1 vendor/bin/mate resources:read symfony-profiler://profile/ ``` -------------------------------- ### Initialize In-Memory Vector Store Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/rag-implementation.html Creates an in-memory store for vector embeddings using Symfony AI's InMemory Store. Ideal for testing and getting started; for production, use a persistent store. ```php use Symfony\AI\Store\InMemory\Store; $store = new Store(); ``` -------------------------------- ### Run Higgsfield text-to-image and image-to-video examples Source: https://github.com/symfony/ai/blob/main/examples/higgsfield/README.md Commands to execute the example scripts. Requires HIGGSFIELD_API_KEY and HIGGSFIELD_API_SECRET in .env.local, provided as a single : pair split at the colon. Uses short aliases like soul-2 and kling-2.5-i2v from the default CuratedModelCatalog. ```bash php higgsfield/text-to-image.php php higgsfield/image-to-video.php ``` -------------------------------- ### Use the Agent in a PHP Service (ChatService) Source: https://github.com/symfony/ai/blob/main/docs/index.rst PHP class demonstrating how to use the AgentInterface to send a chat message and retrieve the response content. It creates a MessageBag with system and user messages, calls the agent, and returns the result content. ```php namespace App\Agent; use Symfony\AI\Agent\AgentInterface; use Symfony\AI\Platform\Message\Message; use Symfony\AI\Platform\Message\MessageBag; final readonly class ChatService { public function __construct( private AgentInterface $agent, ) { } public function chat(string $userMessage): string { $messages = new MessageBag( Message::forSystem('You are a helpful assistant.'), Message::ofUser($userMessage), ); $result = $this->agent->call($messages); return $result->getContent(); } } ``` -------------------------------- ### Verify Mate tools with vendor/bin/mate tools:list Source: https://github.com/symfony/ai/blob/main/docs/components/mate/integration.rst Run this command from a Claude Code session to verify that Mate is available and its tools are listed. Works out of the box after running 'mate init'. ```terminal $ vendor/bin/mate tools:list ``` -------------------------------- ### Replicate: Client constructor drops clock Source: https://github.com/symfony/ai/blob/main/UPGRADE.md The Bridge\Replicate\Client constructor no longer accepts a clock parameter. It performs exactly one request per call and no longer throws on failed predictions; use get() for prediction lookup. ```diff -$client = new Client($httpClient, $clock, $apiKey); +$client = new Client($httpClient, $apiKey); ``` -------------------------------- ### Add getModel() to custom TokenUsage implementation Source: https://github.com/symfony/ai/blob/main/UPGRADE.md Required when upgrading to 0.14: TokenUsageInterface gained a getModel() method. Custom implementations must add this method to report the model that consumed the tokens. The example shows the addition within an existing class. ```diff final class MyTokenUsage implements TokenUsageInterface { // ... + + public function getModel(): ?string + { + return $this->model; + } } ``` -------------------------------- ### Enable tools explicitly in AI agent config Source: https://github.com/symfony/ai/blob/main/UPGRADE.md Agent tools are now opt-in. Previously, all services tagged with `ai.tool` were injected automatically. Now an agent without the `tools` option gets no toolbox. To keep the previous behavior, enable tools explicitly with `tools: true`. ```diff ai: agent: my_agent: model: 'gpt-4o-mini' + tools: true ``` -------------------------------- ### Add mate.invocation and mate.php_version to mate/config.php Source: https://github.com/symfony/ai/blob/main/UPGRADE.md Existing projects must manually add these parameters to mate/config.php. mate.invocation is the command your coding agent must use; mate.php_version records the runtime and Mate refuses to start under a different major.minor. Do not re-run mate init as it overwrites the config. ```diff // mate/config.php $container->parameters() + // The command your coding agent must use, wrapper included. + ->set('mate.invocation', 'ddev exec vendor/bin/mate') + + // The major.minor your application runs on. Leave it out to keep Mate runnable under any + // interpreter, which is what an upgraded project does until you set it. + ->set('mate.php_version', '8.3') ; ``` -------------------------------- ### Resolve MiniMax async job with JobRunner Source: https://github.com/symfony/ai/blob/main/UPGRADE.md Required when upgrading to 0.14: MiniMax bridge no longer waits for async task results. Invocations now return a JobResult; use JobRunner to wait for the job and then read the file. The example shows the new flow with MiniMaxFactory::createJobClient(). ```diff +use Symfony\AI\Platform\Job\JobRunner; + -$result = $platform->invoke('MiniMax-Hailuo-02', $prompt, ['duration' => 6]); -$result->asFile('video.mp4'); +$handle = $platform->invoke('MiniMax-Hailuo-02', $prompt, ['duration' => 6])->asJob(); + +$result = (new JobRunner())->wait(MiniMaxFactory::createJobClient($apiKey), $handle); +$result->asFile('video.mp4'); ``` -------------------------------- ### List all models Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Lists all available models using the model-list command. Limited to 1000 results by default. ```bash php huggingface/_model.php ai:huggingface:model-list ``` -------------------------------- ### Enable multiple server tools simultaneously Source: https://github.com/symfony/ai/blob/main/docs/components/platform/gemini-server-tools.rst Enables URL Context, Google Search, and Code Execution together in a single invocation. The example asks to calculate the factorial of 20 and show the code. ```php $messages = new MessageBag( Message::ofUser('Calculate the factorial of 20 and show me the code') ); $result = $platform->invoke('gemini-2.5-pro', $messages, [ 'server_tools' => [ 'url_context' => true, 'google_search' => true, 'code_execution' => true, ] ]); ``` -------------------------------- ### Configure multiple MCP servers with registry options Source: https://github.com/symfony/ai/blob/main/UPGRADE.md Example YAML defining three MCP servers, each with its own HTTP path and registry. The registry option accepts a list (applies to every capability kind) or a map to narrow each kind separately. A pattern matching no service at all is a compile-time error. ```yaml mcp: servers: public: http: { path: /mcp } registry: tools: ['App\Mcp\Public\'] resources: ['*'] editors: http: { path: /mcp/editors } registry: '*' reporting: http: { path: /mcp/reporting } registry: ['App\Mcp\Reporting\'] # every kind, from one namespace ``` -------------------------------- ### mate/config.php parameters Source: https://github.com/symfony/ai/blob/main/docs/components/mate/integration.rst Configuration file written by `mate init` that sets the `mate.invocation` and `mate.php_version` parameters. `mate.invocation` is the full command the agent must use, and `mate.php_version` is the project's PHP version as `major.minor`. ```php // mate/config.php $container->parameters() ->set('mate.invocation', 'ddev exec vendor/bin/mate') ->set('mate.php_version', '8.3') ; ``` -------------------------------- ### Build Agent with Toolbox Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/tool-calling-with-agents.html Creates a platform and agent, passing a Toolbox with a custom WeatherTool. The agent drives the tool-calling loop. ```php use App\Tool\WeatherTool; use Symfony\AI\Agent\Agent; use Symfony\AI\Agent\Toolbox\Toolbox; use Symfony\AI\Platform\Bridge\OpenAi\Factory; use Symfony\Component\HttpClient\HttpClient; $platform = Factory::createPlatform($apiKey, HttpClient::create()); $toolbox = new Toolbox([new WeatherTool()]); $agent = new Agent($platform, 'gpt-5-mini', toolbox: $toolbox); ``` -------------------------------- ### Enable Google Search server tool Source: https://github.com/symfony/ai/blob/main/docs/components/platform/gemini-server-tools.rst Configures the 'google_search' server tool to perform web searches and incorporate results. The example asks for the latest developments in quantum computing. ```php $messages = new MessageBag( Message::ofUser('What are the latest developments in quantum computing?') ); $result = $platform->invoke('gemini-2.5-pro', $messages, [ 'server_tools' => [ 'google_search' => true, ] ]); ``` -------------------------------- ### Enable URL Context server tool Source: https://github.com/symfony/ai/blob/main/docs/components/platform/gemini-server-tools.rst Configures the 'url_context' server tool to fetch and analyze content from a specified URL. The example asks for the 12-month Euribor rate from a given URL. ```php $messages = new MessageBag( Message::ofUser('What was the 12 month Euribor rate a week ago based on https://www.euribor-rates.eu/en/current-euribor-rates/4/euribor-rate-12-months/') ); $result = $platform->invoke('gemini-2.5-pro', $messages, [ 'server_tools' => [ 'url_context' => true, ] ]); ``` -------------------------------- ### Use store name instead of service id in ai:store:drop Source: https://github.com/symfony/ai/blob/main/UPGRADE.md The `ai:store:setup`, `ai:store:drop` and `ai:store:clear` commands take the configured name of the store instead of its service id, like the `ai:store:index` and `ai:store:retrieve` commands. ```diff -$ php bin/console ai:store:drop ai.store.chromadb.default --force +$ php bin/console ai:store:drop default --force ``` -------------------------------- ### Define services in config/services.php for Mate DI Source: https://github.com/symfony/ai/blob/main/docs/components/mate/creating-extensions.rst Uses the standard Symfony DI format to configure parameters and services. Expose changeable values as parameters prefixed with the extension name; projects override them in mate/config.php. %mate.root_dir% holds the project root. ```php // config/services.php use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Vendor\MyExtension\MyApiClient; return static function (ContainerConfigurator $container): void { $container->parameters() ->set('my_extension.base_url', 'https://api.example.com'); $container->services() ->set(MyApiClient::class) ->arg('$apiKey', '%env(MY_API_KEY)%') ->arg('$baseUrl', '%my_extension.base_url%'); }; ``` -------------------------------- ### Retrieve documents from blog store Source: https://github.com/symfony/ai/blob/main/demo/README.md Retrieve documents from the blog vector store using a query string. ```shell symfony console ai:store:retrieve blog "Week of Symfony" ``` -------------------------------- ### Run Mate Tools from CLI Source: https://github.com/symfony/ai/blob/main/demo/README.md List available tools, inspect the `symfony-ai-features` tool's parameters and JSON input schema, and call tools directly. Use `--limit=1` to restrict output, as shown with `symfony-profiler-list`. ```shell vendor/bin/mate tools:list # what is available vendor/bin/mate tools:inspect symfony-ai-features # parameters and JSON input schema vendor/bin/mate tools:call symfony-ai-features # run it vendor/bin/mate tools:call symfony-profiler-list --limit=1 ``` -------------------------------- ### Enable Code Execution server tool Source: https://github.com/symfony/ai/blob/main/docs/components/platform/gemini-server-tools.rst Configures the 'code_execution' server tool to run code in a sandboxed environment. The example asks to calculate the factorial of 20 and show the code. ```php $messages = new MessageBag( Message::ofUser('Calculate the factorial of 20 and show me the code') ); $result = $platform->invoke('gemini-2.5-pro', $messages, [ 'server_tools' => [ 'code_execution' => true, ] ]); ``` -------------------------------- ### Install Mate as dev dependency Source: https://github.com/symfony/ai/blob/main/src/mate/README.md Add the Mate component to your project's dev dependencies. This is the minimal installation command. ```bash composer require --dev symfony/ai-mate ``` -------------------------------- ### Example text file for system prompt Source: https://github.com/symfony/ai/blob/main/docs/bundles/ai-bundle.rst Example content of a text file used as a system prompt. The entire file content is used as the system prompt text. ```text You are a helpful and knowledgeable assistant. Guidelines: - Be clear and direct in your responses - Provide examples when appropriate - Be respectful and professional at all times ``` -------------------------------- ### Install Agent Component with Composer Source: https://github.com/symfony/ai/blob/main/src/agent/README.md Install the symfony/ai-agent package using Composer. This is the required first step to use the Agent component. ```bash composer require symfony/ai-agent ``` -------------------------------- ### Register a service Source: https://github.com/symfony/ai/blob/main/docs/components/mate/troubleshooting.rst Register a service in a file listed under 'extra.ai-mate.includes'. ```php $services->set(MyService::class) ->autowire() ->autoconfigure(); ``` -------------------------------- ### Basic usage with ADC Source: https://github.com/symfony/ai/blob/main/docs/components/platform/vertexai.rst Basic usage example using ADC authentication. Creates a platform with location and project, sends a user message, and invokes the gemini-2.5-flash model. ```php use Symfony\AI\Platform\Bridge\VertexAi\Factory; use Symfony\AI\Platform\Message\Message; use Symfony\AI\Platform\Message\MessageBag; $platform = Factory::createPlatform( $_ENV['GOOGLE_CLOUD_LOCATION'], $_ENV['GOOGLE_CLOUD_PROJECT'], httpClient: $httpClient ); $messages = new MessageBag( Message::ofUser('Hello, how are you?') ); $result = $platform->invoke('gemini-2.5-flash', $messages); echo $result->asText(); ``` -------------------------------- ### Request List of Available Tools Source: https://github.com/symfony/ai/blob/main/demo/README.md Send this JSON RPC request to list the available tools from the MCP server. ```json { "jsonrpc": "2.0", "id": 2, "method": "tools/list" } ``` -------------------------------- ### Array prompt with include_tools and file prompt Source: https://github.com/symfony/ai/blob/main/ai.symfony.com/templates/cookbook/content/ai-bundle-fast-track.html Use the array form for more control: include tool definitions in the prompt (requires 'tools') or load a long prompt from a file. Also supports translated prompts via 'enable_translation' and 'translation_domain'. ```yaml ai: agent: assistant: model: 'gpt-4o-mini' prompt: text: 'You are a concise assistant for a Symfony application.' include_tools: true tools: true reviewer: model: 'gpt-4o-mini' prompt: file: '%kernel.project_dir%/prompts/reviewer.md' ``` -------------------------------- ### Install Deepgram bridge with Composer Source: https://github.com/symfony/ai/blob/main/docs/components/platform/deepgram.rst Install the Deepgram platform bridge for Symfony AI. ```bash $ composer require symfony/ai-deepgram-platform ``` -------------------------------- ### Check vendor/bin/mate exists Source: https://github.com/symfony/ai/blob/main/docs/components/mate/troubleshooting.rst Run this command to check if the Mate binary exists. If not, run 'composer install'. ```terminal vendor/bin/mate ``` -------------------------------- ### Install the Platform component with Composer Source: https://github.com/symfony/ai/blob/main/src/platform/README.md Use this command to install the symfony/ai-platform package. The component is experimental and not covered by Symfony's Backward Compatibility Promise. ```bash composer require symfony/ai-platform ``` -------------------------------- ### Discover Mate extensions Source: https://github.com/symfony/ai/blob/main/docs/components/mate/troubleshooting.rst Run this command to discover extensions and check that the package is listed in mate/extensions.php with 'enabled' => true. ```terminal vendor/bin/mate discover ``` -------------------------------- ### Model not found error example Source: https://github.com/symfony/ai/blob/main/examples/huggingface/README.md Example error message when a model is not available in the Hugging Face ModelCatalog. The catalog only knows models served by Hugging Face Inference Providers. ```text Model "openai-community/gpt2" not found in "Symfony\AI\Platform\Bridge\HuggingFace\ModelCatalog". ``` -------------------------------- ### Multi-kernel configuration for cache, profiler, and log directories Source: https://github.com/symfony/ai/blob/main/docs/components/mate/extensions.rst Configure directory parameters as maps of context name to path for multi-kernel applications. Each tool accepts a parameter to narrow the lookup to one kernel, and results carry the context they came from. ```php // mate/config.php $container->parameters() ->set('ai_mate_symfony.cache_dir', [ 'website' => '%mate.root_dir%/var/cache/website', 'admin' => '%mate.root_dir%/var/cache/admin', ]) ->set('ai_mate_symfony.profiler_dir', [ 'website' => '%mate.root_dir%/var/cache/website/dev/profiler', 'admin' => '%mate.root_dir%/var/cache/admin/dev/profiler', ]) ->set('ai_mate_monolog.log_dir', [ 'website' => '%mate.root_dir%/var/log/website', 'admin' => '%mate.root_dir%/var/log/admin', ]) ; ``` -------------------------------- ### Run mate CLI commands Source: https://github.com/symfony/ai/blob/main/src/mate/AGENTS.md Essential CLI commands for the mate tool. Includes initialization, extension discovery, skill management, cache clearing, debugging, and tool/resource operations. The tools:*, resources:read, debug:*, skills:list and skills:validate commands accept --format=json (also toon when helgesverre/toon is installed) for machine-readable output. ```bash bin/mate init # Initialize configuration bin/mate discover # Discover extensions (also installs extension skills) bin/mate skills:install # Install extension skills bin/mate skills:install --dry-run # Report what an install would change bin/mate skills:list # List skills with mode, state and status bin/mate skills:validate # Check generated folders and content against recorded state bin/mate skills:prune # Remove leftover generated mate-* folders bin/mate skills:override mate-system-information # Copy into mate/skills/ and own it bin/mate skills:reset mate-system-information # Hand it back to Mate bin/mate skills:disable mate-system-information # Hide it from coding agents bin/mate skills:enable mate-system-information # Show it again bin/mate clear-cache # Clear cache bin/mate debug:capabilities # Show all capabilities bin/mate debug:extensions # Show extension discovery status bin/mate tools:list # List tools bin/mate tools:inspect server-info # Inspect a tool with its schema bin/mate tools:call server-info # Execute a tool bin/mate tools:call symfony-profiler-list --limit=1 # ... with parameters as options bin/mate resources:read # Read a resource by URI ```