Skip to content

amammay/adk-go-mongo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

adk-go-mongo

Go Reference

A Go library that provides a MongoDB-backed implementation for adk-go's session and memory service.

Session Service Features

  • MongoDB storage for ADK sessions: app state, user state, and per-session state
  • Append and query session events with rich metadata
  • Provided indexes
  • API surface aligned with google.golang.org/adk/session

Memory Service Features

WIP

Installation

go get github.com/amammay/adk-go-mongo

Requirements

  • Go 1.25+
  • MongoDB 6+

Quick Start

Create a mongosession-backed session service using an existing *mongo.Database:

package main

import (
	"context"
	"log"

	"go.mongodb.org/mongo-driver/v2/mongo"
	"go.mongodb.org/mongo-driver/v2/mongo/options"

	"github.com/amammay/adk-go-mongo/mongosession"
	"google.golang.org/adk/session"
)

func main() {
	ctx := context.Background()
	client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
	if err != nil {
		log.Fatal(err)
	}

	db := client.Database("adk")

	// Create the session service
	svc, err := mongosession.NewSessionService(db)
	if err != nil {
		log.Fatal(err)
	}

	// Apply recommended indexes (safe to call at startup)
	if err := mongosession.ApplyIndexes(svc); err != nil {
		log.Fatal(err)
	}

	// Create a new session
	createRes, err := svc.Create(ctx, &session.CreateRequest{
		AppName: "my-app",
		UserID:  "user-123",
		State:   map[string]any{"app:topic": "football"},
	})
	if err != nil {
		log.Fatal(err)
	}

	s := createRes.Session
	log.Printf("created session: app=%s user=%s id=%s", s.AppName(), s.UserID(), s.ID())
}

License

See LICENSE file.

Security

If you discover a security issue, please open an issue or contact the maintainers privately.

About

MongoDB-backed session and memory services for ADK in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages