cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Databricks Free Edition Help
Engage in discussions about the Databricks Free Edition within the Databricks Community. Share insights, tips, and best practices for getting started, troubleshooting issues, and maximizing the value of your trial experience to explore Databricks' capabilities effectively.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to Connect Google Gemini Agent to Data Bricks Genie Space

VinodPitta
New Contributor II
 
1 ACCEPTED SOLUTION

Accepted Solutions

emma_s
Databricks Employee
Databricks Employee

H

Hi,

I'm not an expert in what Google Gemini Enterprise agent supports, but there are a couple of options with Genie.

The easiest one is if Google Gemini Enterprise agent supports it, using the Databricks Genie MCP to add your MCP. However, I'm not sure whether the Gemini Enterprise agent has this capability of adding MCPs. Docs for this are here. https://docs.databricks.com/aws/en/generative-ai/mcp/managed-mcp

If not, then you can use the Genie API, docs here https://docs.databricks.com/aws/en/genie/conversation-api?language=Use+an+existing+space

You would register this as a google cloud function and then import this into your Gemini Enterpise Agent.

 

Here is some sample code of what the cloud function would look like.

import os
import json
import functions_framework
from databricks.sdk import WorkspaceClient


@functions_framework.http
def query_genie(request):
    try:
        body = request.get_json(silent=True)
        if not body or "user_question" not in body:
            return (
                json.dumps({"error": "Missing 'user_question' in request body"}),
                400,
                {"Content-Type": "application/json"},
            )

        user_question = body["user_question"]

        w = WorkspaceClient(
            host=os.environ["DATABRICKS_HOST"],
            token=os.environ["DATABRICKS_TOKEN"],
        )
        space_id = os.environ["GENIE_SPACE_ID"]

        response = w.genie.start_conversation_and_wait(
            space_id=space_id,
            content=user_question,
        )

        # Genie returns attachments in order: [query, suggested_questions, text]
        # Prefer the text attachment (human-readable answer); fall back to query description.
        answer = ""
        query_fallback = ""
        for attachment in response.attachments or []:
            if hasattr(attachment, "text") and attachment.text:
                answer = attachment.text.content
                break
            if hasattr(attachment, "query") and attachment.query and not query_fallback:
                query_fallback = attachment.query.description or attachment.query.query
        if not answer:
            answer = query_fallback

        return (
            json.dumps(
                {
                    "answer": answer,
                    "conversation_id": response.conversation_id,
                }
            ),
            200,
            {"Content-Type": "application/json"},
        )

    except Exception as e:
        return (
            json.dumps({"error": str(e)}),
            500,
            {"Content-Type": "application/json"},
        )


For full disclosure the api currently only serves standard genie space responses not agent mode ones. You may also want to look at instead giving your business users access to Genie One. There is the ability in beta to connect this to google drive or office. Your users would then get Genie Agent mode properly.

I hope this helps.


Thanks,

Emma

View solution in original post

4 REPLIES 4

emma_s
Databricks Employee
Databricks Employee

Hi, not sure whether there should have been more context in this post. Do you want to let me know what you were trying to do?

 

Thanks,

Emma

VinodPitta
New Contributor II

How to connect Google Gemini Enterprise agent to Genie Space for natural language data querying in chatbots, applications, and AI agent frameworks. Today in Genie space , i can query for an invoice status and get more details conversation related to it , we want the same feature from Gemini Agent  i.e  When a user asks a question requiring database lookups (e.g., supplier details, invoice status, or invoice history ), you must use the Databricks Genie and provide the out come in Gemini Agent chat window.

emma_s
Databricks Employee
Databricks Employee

H

Hi,

I'm not an expert in what Google Gemini Enterprise agent supports, but there are a couple of options with Genie.

The easiest one is if Google Gemini Enterprise agent supports it, using the Databricks Genie MCP to add your MCP. However, I'm not sure whether the Gemini Enterprise agent has this capability of adding MCPs. Docs for this are here. https://docs.databricks.com/aws/en/generative-ai/mcp/managed-mcp

If not, then you can use the Genie API, docs here https://docs.databricks.com/aws/en/genie/conversation-api?language=Use+an+existing+space

You would register this as a google cloud function and then import this into your Gemini Enterpise Agent.

 

Here is some sample code of what the cloud function would look like.

import os
import json
import functions_framework
from databricks.sdk import WorkspaceClient


@functions_framework.http
def query_genie(request):
    try:
        body = request.get_json(silent=True)
        if not body or "user_question" not in body:
            return (
                json.dumps({"error": "Missing 'user_question' in request body"}),
                400,
                {"Content-Type": "application/json"},
            )

        user_question = body["user_question"]

        w = WorkspaceClient(
            host=os.environ["DATABRICKS_HOST"],
            token=os.environ["DATABRICKS_TOKEN"],
        )
        space_id = os.environ["GENIE_SPACE_ID"]

        response = w.genie.start_conversation_and_wait(
            space_id=space_id,
            content=user_question,
        )

        # Genie returns attachments in order: [query, suggested_questions, text]
        # Prefer the text attachment (human-readable answer); fall back to query description.
        answer = ""
        query_fallback = ""
        for attachment in response.attachments or []:
            if hasattr(attachment, "text") and attachment.text:
                answer = attachment.text.content
                break
            if hasattr(attachment, "query") and attachment.query and not query_fallback:
                query_fallback = attachment.query.description or attachment.query.query
        if not answer:
            answer = query_fallback

        return (
            json.dumps(
                {
                    "answer": answer,
                    "conversation_id": response.conversation_id,
                }
            ),
            200,
            {"Content-Type": "application/json"},
        )

    except Exception as e:
        return (
            json.dumps({"error": str(e)}),
            500,
            {"Content-Type": "application/json"},
        )


For full disclosure the api currently only serves standard genie space responses not agent mode ones. You may also want to look at instead giving your business users access to Genie One. There is the ability in beta to connect this to google drive or office. Your users would then get Genie Agent mode properly.

I hope this helps.


Thanks,

Emma

balajij8
Contributor III

You can follow below to enable the Gemini agent (to detect when users ask data-related questions (invoice status, supplier details etc)) and route those queries to the Genie Space, then return the results in the Gemini chat window.

Google Gemini Enterprise agent can call Databricks Genie Spaces via the Genie Conversation API.

  1. Create Tool/Function for Gemini Agent

    You can define a function calling tool in the Gemini agent that triggers when users ask data-related questions

  2. Implement Genie API Integration

    Create a backend service that connects Gemini to Genie.

  3. Integrate with Gemini Agent

    When Gemini calls the function, route to Genie.

  4. Configure Gemini Agent Instructions

    Add instructions to the Gemini agent to use genie function when users ask question about Invoice status etc

More details here