Symfony bridge for PapiAI -- integrate AI agents into your Symfony application with full dependency injection, configuration, and service wiring.
composer require papi-ai/symfonyIf you are not using Symfony Flex, register the bundle manually in config/bundles.php:
return [
// ...
PapiAI\Symfony\PapiBundle::class => ['all' => true],
];Create config/packages/papi.yaml:
papi:
default_provider: openai
providers:
openai:
driver: PapiAI\OpenAI\OpenAIProvider
api_key: '%env(OPENAI_API_KEY)%'
model: gpt-4o
anthropic:
driver: PapiAI\Anthropic\AnthropicProvider
api_key: '%env(ANTHROPIC_API_KEY)%'
model: claude-sonnet-4-20250514
middleware:
- app.middleware.logging
- app.middleware.rate_limit
conversation:
store: file
path: '%kernel.project_dir%/var/papi/conversations'use PapiAI\Core\Contracts\ProviderInterface;
class ChatController
{
public function __construct(
private ProviderInterface $provider,
) {}
public function chat(string $message): string
{
$response = $this->provider->chat([
['role' => 'user', 'content' => $message],
]);
return $response->getText();
}
}use PapiAI\Core\Contracts\ConversationStoreInterface;
use PapiAI\Core\Conversation;
class ConversationService
{
public function __construct(
private ConversationStoreInterface $store,
) {}
public function saveConversation(string $id, Conversation $conversation): void
{
$this->store->save($id, $conversation);
}
public function loadConversation(string $id): ?Conversation
{
return $this->store->load($id);
}
}Install Doctrine DBAL and configure the store:
composer require doctrine/dbalpapi:
conversation:
store: doctrineCreate the conversations table in your database:
CREATE TABLE papi_conversations (
id VARCHAR(255) PRIMARY KEY,
data JSON NOT NULL,
created_at DATETIME NOT NULL,
updated_at DATETIME NOT NULL
);Install Symfony Messenger:
composer require symfony/messengeruse PapiAI\Core\Contracts\QueueInterface;
use PapiAI\Core\AgentJob;
class AgentService
{
public function __construct(
private QueueInterface $queue,
) {}
public function dispatchJob(string $agentClass, string $prompt): string
{
$job = new AgentJob(
agentClass: $agentClass,
prompt: $prompt,
);
return $this->queue->dispatch($job);
}
}MIT License. See LICENSE for details.