Skip to content

Genkit JS and CLI 1.39.0-rc.0

Pre-release
Pre-release

Choose a tag to compare

@pavelgj pavelgj released this 24 Jun 19:49
· 2 commits to main since this release

⚠️ Breaking changes (beta)

  • The beta Chat API has been removed and replaced by the new Agents API (#5248, #5251). The Chat class, ai.chat(...), and session.chat(...) are gone. Migrate to ai.defineAgent(...) and agent.chat() (see Agents below). All removed surface was beta.

This release introduces Agents, a first-class, multi-turn agent API for Genkit JS. Agents bundle a model/prompt, conversational state, tool loops, interrupts, persistence, streaming, and abort/resume into a single ergonomic, transport-agnostic surface that runs identically in-process on the server and over HTTP from the browser.

Highlights

defineAgent — the new Agents API (#5251)

Define a multi-turn agent in a single call, with three levels of control:

// Zero-config
const agent = ai.defineAgent({
  name: 'assistant',
  model: 'googleai/gemini-flash-latest',
  system: 'You are a helpful assistant.',
  tools: [searchTool],
});

// Reuse a registered .prompt (typed promptInput)
const agent = ai.definePromptAgent({ promptName: 'assistant', promptInput: { role: 'pirate' } });

// Full control via a custom turn handler
const agent = ai.defineCustomAgent({ name: 'custom' }, async (runner, input) => { /* ... */ });

Key capabilities:

  • Stateful, multi-turn chatschat() threads state, messages, snapshotId, and sessionId for you (send & stream).
  • Typed custom state with Zod validation (stateSchema).
  • Pluggable persistence via SessionStore (in-memory + file stores included); server-managed sessions resumable by sessionId.
  • Streaming with live custom-state patches over the wire (JSON Patch).
  • Interrupts & resume (restart / respond) for human-in-the-loop tools.
  • Abort, detach (background turns) + heartbeats, and graceful failure that preserves the last-good state.
  • clientTransform to redact/reshape state and stream chunks before they leave the server.
  • Same API server or browserremoteAgent(...) returns the same AgentAPI shape over HTTP.

Agents middleware: delegation & artifacts (#5252)

New @genkit-ai/middleware middlewares for building multi-agent, artifact-producing workflows:

  • agents() — turns an agent into an orchestrator that delegates to other registered agents. Injects a dedicated delegate_to_<agent> tool per sub-agent, auto-discovers descriptions, returns sub-agent interrupts/failures as tool results, and adds guard rails (maxDelegations, historyLength).
  • artifacts() — gives the model read_artifact / write_artifact tools backed by session state, with an <artifacts> listing injected each turn. Pair with agents({ artifactStrategy: 'session' }) so an orchestrator can read artifacts produced by its sub-agents.

useChat adapter for Agents — @genkit-ai/vercel-ai (#5426)

A new plugin providing a Vercel AI SDK ChatTransport that wires useChat directly to Genkit Agents, so you can build rich React chat UIs (Next.js, Vite) with zero custom plumbing:

  • GenkitChatTransport — drop-in ChatTransport, compatible with AI Elements.
  • Server-managed sessions keyed by the useChat id (no client-side snapshot bookkeeping).
  • First-class interrupts mapped onto the AI SDK's native HITL primitives (respond + restart).
  • Mapping utilities to convert between Vercel UIMessage and Genkit MessageData.
  • Ships a full sample app at js/testapps/vercel-ai-elements.

Firestore session store (#5586)

FirestoreSessionStore for persisting agent sessions, in @genkit-ai/google-cloud with a thin @genkit-ai/firebase wrapper. It persists each turn as an incremental JSON Patch diff anchored to periodic, sharded full-state checkpoints, so no document approaches Firestore's 1 MiB limit, per-turn reads/writes stay bounded regardless of session length, and reconstruction is strongly consistent without secondary indexes. Tunable via collection, checkpointInterval, and shardSize.

Supporting changes

  • Initialization data for flows & actions (#5247) — flows/actions can declare an initSchema and receive validated init data (separate from input) over HTTP. Plumbed through genkit/beta/client (runFlow/streamFlow) and the express, fastify, fetch, and next handlers.
  • Bidi actions and flows (#4288) — foundational support for bidirectional (streaming both ways) actions and flows.

Full Changelog: v1.38.0...v1.39.0-rc.0