Skip to content

Migrate from 0.5 to 0.9

Genkit 0.9 introduces a number of breaking changes alongside feature enhancements that improve overall functionality. If you have been developing applications with Genkit 0.5, you will need to update your application code when you upgrade to the latest version. This guide outlines the most significant changes and offers steps to migrate your existing applications smoothly.

The following steps will help you migrate from Genkit 0.5 to Genkit 0.9 quickly. Read more information about these changes in the detailed Changelog below.

  • Uninstall the old CLI

    Terminal window
    npm uninstall -g genkit && npm uninstall genkit
  • Install the new CLI globally

    Terminal window
    npm install -g genkit-cli
  • Remove individual Genkit core packages

    Terminal window
    npm uninstall @genkit-ai/ai @genkit-ai/core @genkit-ai/dotprompt @genkit-ai/flow
  • Install the new consolidated genkit package

    Terminal window
    npm install genkit
  • Upgrade all plugin versions (example below)

    npm upgrade @genkit-ai/firebase
  • Remove imports for individual Genkit core packages

    import { … } from '@genkit-ai/ai';
    import { … } from '@genkit-ai/core';
    import { … } from '@genkit-ai/flow';
  • Remove zod imports

    import * as z from 'zod';
  • Import genkit and zod from genkit

    import { z, genkit } from 'genkit';

Configuration for Genkit is now done per instance. Telemetry and logging is configured globally and separately from the Genkit instance.

  • Replace configureGenkit with ai = genkit({...}) blocks. Keep only the plugin configuration.

    import { genkit } from 'genkit';
    const ai = genkit({ plugins: [...]});
  • Configure telemetry using enableFirebaseTelemetry or enableGoogleCloudTelemetry

    For Firebase:

    import { enableFirebaseTelemetry } from '@genkit-ai/firebase';
    enableFirebaseTelemetry({...});

    For Google Cloud:

    import { enableGoogleCloudTelemetry } from '@genkit-ai/google-cloud';
    enableGoogleCloudTelemetry({...});
  • Set your logging level independently

    import { logger } from 'genkit/logging';
    logger.setLogLevel('debug');

See the Monitoring and Logging documentation for more details on how to configure telemetry and logging.

See the Get Started documentation for more details on how to configure a Genkit instance.

Migrate Genkit actions to be called from the genkit instance

Section titled “Migrate Genkit actions to be called from the genkit instance”

Actions (flows, tools, retrievers, indexers, etc.) are defined per instance. Read the Changelog for all of the features you will need to change, but here is an example of some common ones.

import { genkit } from 'genkit';
import { onFlow } from '@genkit-ai/firebase/functions';
const ai = genkit({ plugins: [...]});
// Flows and tools are defined on the specific genkit instance
// and are directly callable.
const sampleFlow = ai.defineFlow(...);
const sampleTool = ai.defineTool(...);
async function callMyFlow() {
// Previously, text output could accessed via .text()
// Now it is either .output() or .text
return await sampleFlow().output();
}
// onFlow now takes the Genkit instance as first argument
// This registers the flow as a callable firebase function
onFlow(ai, ...);
const flows = [ sampleFlow, ... ];
// Start the flow server to make the registered flows callable over HTTP
ai.startFlowServer({flows});
Terminal window
# run the DevUI and your js code
genkit start -- <command to run node>
# run a defined flow
genkit flow:run <flowName>

The command-line interface (CLI) has undergone significant updates in Genkit 0.9. The command to start Genkit has changed, and the CLI has been separated into its own standalone package, which you now need to install separately.

To install the CLI:

Terminal window
npm install -g genkit-cli

Some changes have been made to the genkit start command:

Starts your Genkit application code + Dev UI together:

Terminal window
genkit start -- [start command]
genkit start -- tsx src/index.ts
genkit start -- go run main.go

Watch mode is supported as well:

Terminal window
genkit start -- tsx --watch src/index.ts

Starts ONLY your application code in Genkit dev mode:

Terminal window
genkit start --noui -- <start command>
genkit start --noui -- tsx src/index.ts

Starts the Dev UI ONLY:

Terminal window
genkit start

Previously, the genkit start command would start the Dev UI and your application code together. If you have any CI/CD pipelines relying on this command, you may need to update the pipeline.

The Dev UI will interact directly with the flow server to figure out which flows are registered and allow you to invoke them directly with sample inputs.

Previously, the Genkit libraries were separated into several modules, which you needed to install and import individually. These modules have now been consolidated into a single import. In addition, the Zod module is now re-exported by Genkit.

Old:

Terminal window
npm install @genkit-ai/core @genkit-ai/ai @genkit-ai/flow @genkit-ai/dotprompt

New:

Terminal window
npm install genkit

Old:

import { … } from '@genkit-ai/ai';
import { … } from '@genkit-ai/core';
import { … } from '@genkit-ai/flow';
import * as z from 'zod';

New:

import { genkit, z } from 'genkit';

Genkit plugins still must be installed and imported individually.

Previously, initializing Genkit was done once globally by calling the configureGenkit function. Genkit resources (flows, tools, prompts, etc.) would all automatically be wired with this global configuration.

Genkit 0.9 introduces Genkit instances, each of which encapsulates a configuration. See the following examples:

Old:

import { configureGenkit } from '@genkit-ai/core';
configureGenkit({
telemetry: {
instrumentation: ...,
logger: ...
}
});

New:

import { genkit } from 'genkit';
import { logger } from 'genkit/logging';
import { enableFirebaseTelemetry } from '@genkit-ai/firebase';
logger.setLogLevel('debug');
enableFirebaseTelemetry({...});
const ai = genkit({ ... });

Let’s break it down:

  • configureGenkit() has been replaced with genkit(), and it returns a configured Genkit instance rather than setting up configurations globally.
  • The Genkit initialization function is now in the genkit package.
  • Logging and telemetry are still configured globally using their own explicit methods. These configurations apply uniformly across all Genkit instances.

4. Defining flows and starting the flow server explicitly

Section titled “4. Defining flows and starting the flow server explicitly”

Now that you have a configured Genkit instance, you will need to define your flows. All core developer-facing API methods like defineFlow, defineTool, and onFlow are now invoked through this instance.

This is distinct from the previous way, where flows and tools were registered globally.

Old:

import { defineFlow, defineTool, onFlow } from '@genkit-ai/core';
defineFlow(...);
defineTool(...);
onFlow(...);

New:

// Define tools and flows
const sampleFlow = ai.defineFlow(...);
const sampleTool = ai.defineTool(...);
// onFlow now takes the Genkit instance as first argument
// This registers the flow as a callable firebase function
onFlow(ai, ...);
const flows = [ sampleFlow, ... ];
// Start the flow server to make the registered flows callable over HTTP
ai.startFlowServer({flows});

As of now, all flows that you want to make available need to be explicitly registered in the flows array above.

5. Tools and Prompts must be statically defined

Section titled “5. Tools and Prompts must be statically defined”

In earlier versions of Genkit, you could dynamically define tools and prompts at runtime, directly from within a flow.

In Genkit 0.9, this behavior is no longer allowed. Instead, you need to define all actions and flows outside of the flow’s execution (i.e. statically).

This change enforces a stricter separation of action definitions from execution.

If any of your code is defined dynamically, they need to be refactored. Otherwise, an error will be thrown at runtime when the flow is executed.

❌ DON’T:

const flow = defineFlow({...}, async (input) => {
const tool = defineTool({...});
await tool(...);
});

✅ DO:

const tool = ai.defineTool({...});
const flow = ai.defineFlow({...}, async (input) => {
await tool(...);
});

In Genkit 0.9, we have simplified the syntax for defining a streaming flow and invoking it.

First, defineFlow and defineStreamingFlow have been separated. If you have a flow that is meant to be streamed, you will have to update your code to define it via defineStreamingFlow.

Second, instead of calling separate stream() and response() functions, both stream and response are now values returned directly from the flow. This change simplifies flow streaming.

Old:

import { defineFlow, streamFlow } from '@genkit-ai/flow';
const myStreamingFlow = defineFlow(...);
const { stream, output } = await streamFlow(myStreamingFlow, ...);
for await (const chunk of stream()) {
console.log(chunk);
}
console.log(await output());

New:

const myStreamingFlow = ai.defineStreamingFlow(...);
const { stream, response } = await myStreamingFlow(...);
for await (const chunk of stream) {
console.log(chunk);
}
console.log(await response);

7. GenerateResponse class methods replaced with getter properties

Section titled “7. GenerateResponse class methods replaced with getter properties”

Previously, you used to access the structured output or text of the response using class methods, like output() or text().

In Genkit 0.9, those methods have been replaced by getter properties. This simplifies working with responses.

Old:

const response = await generate({ prompt: 'hi' });
console.log(response.text());

New:

const response = await ai.generate('hi');
console.log(response.text);

The same applies to output:

Old:

console.log(response.output());

New:

console.log(response.output);

Genkit 0.9 simplifies response handling by removing the candidates attribute. Previously, responses could contain multiple candidates, which you needed to handle explicitly. Now, only the first candidate is returned directly in a flat response.

Any code that accesses the candidates directly will not work anymore.

Old:

const response = await generate({
messages: [ { role: 'user', content: ...} ]
});
console.log(response.candidates); // previously you could access candidates directly

New:

const response = await ai.generate({
messages: [ { role: 'user', content: ...} ]
});
console.log(response.message); // single candidate is returned directly in a flat response

For multi-turn conversations, the old toHistory() method has been replaced by messages, further simplifying how conversation history is handled.

Old:

const history = response.toHistory();

New:

const response = await ai.generate({
messages: [ { role: 'user', content: ...} ]
});
const history = response.messages;

In Genkit 0.9, the Chat API has been redesigned for easier session management and interaction. Here’s how you can leverage it for both synchronous and streaming chat experiences:

import { genkit } from 'genkit';
import { gemini15Flash, googleAI } from '@genkit-ai/googleai';
const ai = genkit({
plugins: [googleAI()],
model: gemini15Flash,
});
const session = ai.createSession({ store: firestoreSessionStore() });
const chat = await session.chat({ system: 'talk like a pirate' });
let response = await chat.send('hi, my name is Pavel');
console.log(response.text()); // "hi Pavel, I'm llm"
// continue the conversation
response = await chat.send("what's my name");
console.log(response.text()); // "Pavel"
// can stream
const { response, stream } = await chat.sendStream('bye');
for await (const chunk of stream) {
console.log(chunk.text());
}
console.log((await response).text());
// can load session from the store
const prevSession = await ai.loadSession(session.id, { store });
const prevChat = await prevSession.chat();
await prevChat.send('bye');