Skip to content

Conversation

@apascal07
Copy link
Collaborator

@apascal07 apascal07 commented Jan 8, 2026

This PR adds experimental session management APIs for Genkit Go, enabling stateful execution environments that persist across requests.

Summary

  • New session package (core/x/session) - Core session management with typed state
  • Firestore session store (plugins/firebase/x) - Persistent sessions backed by Firestore

Core Session API

import "github.com/firebase/genkit/go/core/x/session"

// Define your state type
type MyState struct {
    Count int `json:"count"`
}

// Create a new session
sess, err := session.New(ctx,
    session.WithID[MyState]("my-session"),
    session.WithStore(store),
    session.WithInitialState(MyState{Count: 0}),
)

// Load an existing session
sess, err := session.Load(ctx, store, sessionID)

// Access and update state
state := sess.State()
sess.UpdateState(ctx, newState)

// Attach to context (for tools to access)
ctx = session.NewContext(ctx, sess)

// Retrieve from context (in tools)
sess := session.FromContext[MyState](ctx)

Session Stores

In-Memory Store (for development/testing):

store := session.NewInMemoryStore[MyState]()

Firestore Store (for production):

import firebasex "github.com/firebase/genkit/go/plugins/firebase/x"

store, err := firebasex.NewFirestoreSessionStore[MyState](ctx, g,
    firebasex.WithCollection("genkit-sessions"),
    firebasex.WithTTL(1 * time.Hour),
)

Using Sessions with Tools

Tools can access and modify session state via context:

myTool := genkit.DefineTool(g, "myTool", "description",
    func(ctx *ai.ToolContext, input MyInput) (MyOutput, error) {
        sess := session.FromContext[MyState](ctx.Context)
        state := sess.State()
        // ... modify state ...
        sess.UpdateState(ctx.Context, state)
        return output, nil
    },
)

Checklist (if applicable):

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @apascal07, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust session management system for Genkit in Go. It provides a core, generic API for creating and managing stateful sessions, along with a flexible Store interface for persistence. A concrete FirestoreSessionStore implementation is included, allowing sessions to be durably stored in Google Cloud Firestore with configurable TTL. This change also streamlines Firestore-related configurations by introducing reusable options, improving consistency and reducing boilerplate for future Firestore integrations.

Highlights

  • Core Session Management API: Introduced a new go/core/x/session package providing a generic Session[S] type for managing stateful execution environments, allowing strongly-typed state that can be persisted.
  • Pluggable Persistence: Defined a Store[S] interface for abstracting session data persistence, with an InMemoryStore implementation provided for local or testing purposes, and a NotFoundError type for missing sessions.
  • Firestore Integration for Durable Sessions: Added a FirestoreSessionStore[S] within go/plugins/firebase/x to enable durable session persistence using Google Cloud Firestore, including support for configurable Time-To-Live (TTL) for session documents.
  • Reusable Firestore Options: Refactored common Firestore configuration options (collection name, TTL) into a new firestoreOptions struct and WithCollection, WithTTL functions, making them generic and reusable across various Firestore-backed services within the Firebase plugin (e.g., FirestoreSessionStore and FirestoreStreamManager).
  • Context Integration: Provided NewContext and FromContext utilities for seamlessly attaching and retrieving sessions from a Go context.Context, facilitating session propagation across function calls.
  • Comprehensive Testing: Included extensive unit tests for the core session package and integration tests for the FirestoreSessionStore to ensure reliability and correct functionality.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive session management feature, including a core API, an in-memory store, and a Firestore-backed persistent store. The overall design is solid, leveraging Go generics and the options pattern effectively. The accompanying tests are thorough. My review focuses on a couple of critical correctness issues: one related to ensuring deep copies for thread safety in the core Session object, and another concerning the correct handling of CreatedAt timestamps in the FirestoreSessionStore. I've also suggested improvements to the tests to better cover these edge cases.

@github-actions github-actions bot added the docs Improvements or additions to documentation label Jan 9, 2026
@apascal07 apascal07 requested a review from pavelgj January 9, 2026 19:14
@apascal07 apascal07 marked this pull request as ready for review January 9, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation go

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant