Install Core Package
composer require arnaudmoncondhuy/synapse-core
Run Doctor CLI for Auto-Configuration
php bin/console synapse:doctor --init
admin user (admin/admin)Conversation, Message)synapse_core.yaml configFirst Use Case: Programmatic Chat
use Synapse\Core\Chat\ChatService;
class MyController extends AbstractController {
public function __invoke(ChatService $chatService) {
$response = $chatService->ask(
message: "Summarize this report",
options: ['tone' => 'professional']
);
return $this->json($response['answer']);
}
}
php bin/console list synapse (for all available commands)config/packages/synapse_core.yamlsrc/Entity/Conversation.php and src/Entity/Message.phpPattern: Specialized AI Agents with Tools
// Define an agent in config
synapse_core:
agents:
report_analyst:
instructions: "Analyze financial reports with precision"
tools: ["spreadsheet_parser", "database_query"]
tone: "expert_analyst"
Usage:
$agent = $this->get('synapse_core.agent.report_analyst');
$analysis = $agent->execute("Analyze Q3 2023 revenue trends");
Pattern: Token Budgeting
// Check budget before expensive operation
$budget = $chatService->getBudget('user_123');
if ($budget->remainingTokens < 1000) {
throw new \RuntimeException("Token budget exhausted");
}
// Execute with cost tracking
$response = $chatService->ask(
message: "Generate 500-word blog post",
options: ['cost_aware' => true]
);
Pattern: Real-Time UI Feedback
{# templates/chat/streaming.html.twig #}
<div id="chat-stream">
{{ include('@Synapse/chat/streaming_component.html.twig', {
endpoint: path('synapse_chat_stream'),
conversationId: conversation.id
}) }}
</div>
Pattern: Vector Store Integration
# config/packages/synapse_core.yaml
synapse_core:
vector_store:
class: App\Service\CustomVectorStore
options:
embedding_model: "text-embedding-ada-002"
Pattern: Monitoring Endpoints
// In your controller
public function dashboard(AnalyticsService $analytics) {
$stats = $analytics->getUsageStats();
return $this->render('admin/dashboard.html.twig', ['stats' => $stats]);
}
Entity Mismatch
Class App\Entity\Conversation does not existphp bin/console synapse:doctor --init to generate entities or manually create them:
php bin/console make:entity Conversation
php bin/console make:entity Message
Token Cost Overruns
synapse_core.yaml:
synapse_core:
quotas:
default:
daily_limit: 10000
cost_per_token: 0.000005
Streaming Component Issues
{{ form_start(form, {'attr': {'data-csrf': app.request.csrfToken}}) }}
Synapse Doctor
php bin/console synapse:doctor --check
Cost Logging Enable debug mode to see token usage:
synapse_core:
accounting:
debug: true
Agent Debugging
$agent->setDebug(true);
$result = $agent->execute("Test query");
// View debug output in Symfony profiler
Custom LLM Providers
Implement Synapse\Core\LLM\ProviderInterface:
class CustomProvider implements ProviderInterface {
public function generate(string $prompt, array $options): string {
// Your custom logic
}
}
Register in config:
synapse_core:
providers:
custom:
class: App\Service\CustomProvider
Event Listeners Extend conversation processing:
// src/EventListener/CustomChatListener.php
class CustomChatListener implements ChatEventSubscriber {
public static function getSubscribedEvents() {
return [
ChatEvents::PRE_ASK => 'onPreAsk',
];
}
public function onPreAsk(ChatEvent $event) {
// Modify request before processing
}
}
Custom Vector Stores
Implement Synapse\Core\VectorStore\StoreInterface for custom embeddings:
class CustomVectorStore implements StoreInterface {
public function addEmbedding(string $id, array $vector) { /* ... */ }
public function query(string $query, int $limit) { /* ... */ }
}
Multilingual Support
symfony/translation bundlesynapse_core.yaml:
synapse_core:
i18n:
enabled: true
default_locale: en
Auto-Titling
synapse-chat bundlesynapse_chat:
auto_titling: true
Security Notes
synapse_chat:
routes:
ask:
csrf_protection: false
How can I help you explore Laravel packages today?