The Firebase plugin integrates Genkit with Firebase and Google Cloud. It provides:
See also the official docs for deploying Genkit with Firebase.
npm i --save @genkit-ai/firebase
Call enableFirebaseTelemetry() to export Genkit traces, metrics, and logs to Google Cloud / Firebase:
import { genkit } from 'genkit';
import { enableFirebaseTelemetry } from '@genkit-ai/firebase';
enableFirebaseTelemetry();
const ai = genkit({
plugins: [
// ...
],
});
See the monitoring documentation for details.
This plugin provides two StreamManager implementations for durable streaming:
FirestoreStreamManager: Persists stream state in Google Firestore.RtdbStreamManager: Persists stream state in the Firebase Realtime Database.You can use these with expressHandler or appRoute to make your flow streams durable.
To use a stream manager, import it from @genkit-ai/firebase/beta and provide it to your flow handler:
import { expressHandler } from '@genkit-ai/express';
import { FirestoreStreamManager } from '@genkit-ai/firebase/beta';
import express from 'express';
import { initializeApp } from 'firebase-admin/app';
import { getFirestore } from 'firebase-admin/firestore';
// ... define your flow: myFlow
const fApp = initializeApp();
const firestore = new FirestoreStreamManager({
firebaseApp: fApp,
db: getFirestore(fApp),
collection: 'streams',
});
const app = express();
app.use(express.json());
app.post('/myDurableFlow', expressHandler(myFlow, { streamManager: firestore }));
app.listen(8080);
Similarly, for the Realtime Database:
import { RtdbStreamManager } from '@genkit-ai/firebase/beta';
const rtdb = new RtdbStreamManager({
firebaseApp: fApp,
refPrefix: 'streams',
});
app.post('/myDurableRtdbFlow', expressHandler(myFlow, { streamManager: rtdb }));
FirestoreSessionStore is a Firestore-backed SessionStore for persisting agent session snapshots. It is a thin Firebase wrapper around the core implementation in @genkit-ai/google-cloud, adding a firebaseApp option for deriving the Firestore instance from a Firebase app. Unlike a naive single-document store, it persists each turn as an incremental JSON Patch diff anchored to periodic, sharded full-state checkpoints, so:
checkpointInterval rather than total session length, so it scales to arbitrarily long sessions (e.g. long-lived chatbots, coding agents).Import it from @genkit-ai/firebase/beta and pass it as the store when defining an agent:
import { genkit } from 'genkit/beta';
import { FirestoreSessionStore } from '@genkit-ai/firebase/beta';
import { initializeApp } from 'firebase-admin/app';
const fApp = initializeApp();
const ai = genkit({
plugins: [
// ...
],
});
const myAgent = ai.defineAgent({
name: 'myAgent',
model: 'googleai/gemini-2.5-flash',
system: 'You are a helpful assistant.',
store: new FirestoreSessionStore({ firebaseApp: fApp }),
});
FirestoreSessionStore accepts the following options:
firebaseApp: A Firebase app to derive the Firestore instance from.db: An explicit Firestore instance. Takes precedence over firebaseApp.collection: The collection where snapshot documents are stored. Defaults to "genkit-sessions". Two companion collections are derived from it: "<collection>-pointers" (one pointer document per session) and "<collection>-shards" (the sharded checkpoint state).checkpointInterval: Number of turns between full-state checkpoints. Defaults to 25. Lower it (e.g. 10) for small-state, read-heavy sessions; raise it (e.g. 50-100) for large per-turn state retained for a long time.shardSize: Maximum size in bytes of a single shard / diff document. Defaults to 512 KiB. Any diff exceeding this is promoted to a sharded checkpoint so no document approaches the 1 MiB limit.The sources for this package are in the main Genkit repo. Please file issues and pull requests against that repo.
Usage information and reference details can be found in Genkit documentation.
License: Apache 2.0