Skip to content

AI Integration

Doggy deeply integrates AI capabilities through the Symfony AI Bundle, supporting multiple model providers with a unified interface.

Overview

The AI system lives in src/Service/AI/:

src/Service/AI/
├── AiManager.php                    # AI manager (unified interface)
├── AgentManager.php                 # Agent manager (Facade)
├── Agent/
│   ├── CodingAgent.php              # Coding assistant
│   ├── NaturalLanguageQueryAgent.php # Natural language query
│   ├── VisionAgent.php              # Vision recognition
│   └── PasswordPolicyAgent.php      # Password policy agent
└── Provider/
    └── AbstractOpenAiProvider.php   # OpenAI API abstraction

Model Providers

AiManager supports two providers, switched via the AI_PROVIDER env var:

ProviderPlatform ServiceConfig
Alibaba Cloudai.platform.generic.aliyunALIYUN_MODEL_ID
LM Studioai.platform.generic.lmstudioLM_STUDIO_MODEL_ID
yaml
# config/packages/ai.yaml
ai:
  providers:
    alibaba:
      type: alibaba_bailian
      api_key: '%env(ALIBABA_AI_KEY)%'

Configuration

bash
# .env
AI_PROVIDER=aliyun
ALIYUN_MODEL_ID=qwq-32b
ALIYUN_FAST_MODEL_ID=qwen-plus
LM_STUDIO_MODEL_ID=deepseek/deepseek-r1-0528-qwen3-8b

Calling AI

php
use App\Service\AI\AiManager;

class SomeService
{
    public function __construct(private AiManager $aiManager) {}

    public function ask(): string
    {
        return $this->aiManager->chat([
            ['role' => 'system', 'content' => 'You are a helpful assistant.'],
            ['role' => 'user', 'content' => 'Hello!'],
        ], [
            'temperature' => 0.7,
            'model' => 'qwen-plus',  // Optional model override
        ]);
    }
}

AiManager automatically handles:

  • Provider selection (based on AI_PROVIDER)
  • Streaming responses (supports reasoning models like qwq-32b)
  • Model configuration merging

Fast Model Switching

NaturalLanguageQueryAgent supports a fast model for NL queries to avoid slow reasoning model responses:

php
if ($this->provider === 'aliyun' && $this->aliyunFastModelId) {
    $options['model'] = $this->aliyunFastModelId;
}

Open Source under MIT | Copyright © 2026 Doggy