Setup
Copy
Ask AI
npm i ai @google/genai @nangohq/node
This example uses the Node SDK, a lightweight wrapper over Nango’s REST API. The same flow works in any language by using the API reference.
- A Nango account with a Hubspot integration configured and the
whoamiaction enabled. - A Google Gemini account.
Usage
Example of a basic tool that calls an external API (Hubspot):Copy
Ask AI
import { GoogleGenAI, FunctionCallingConfigMode, Type } from "@google/genai";
import { Nango } from "@nangohq/node";
export async function runGoogleAgent() {
if (!process.env.GOOGLE_API_KEY) {
console.log("Missing environment variable: GOOGLE_API_KEY.");
}
const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! });
const nango = new Nango({ secretKey: process.env.NANGO_SECRET_KEY! });
const userId = "user1", integrationId = "hubspot";
// Step 1: Ensure the user is authorized
console.log("🔒 Checking API authorization...");
let connectionId = (await nango.listConnections({ integrationId, userId })).connections[0]?.connection_id;
// Step 2: If the user is not authorized, redirect to the auth flow.
if (!connectionId) {
const session = await nango.createConnectSession({
allowed_integrations: [integrationId],
end_user: { id: userId },
});
console.log(`Please authorize the app by visiting this URL: ${session.data.connect_link}`);
const connection = await nango.waitForConnection(integrationId, userId);
connectionId = connection!.connection_id;
}
// Step 3: Send a prompt to your model with tool definitions
console.log("🤖 Agent running...");
const response = await ai.models.generateContent({
model: "gemini-2.5-flash",
contents: "Using the who_am_i tool, provide the current user info.",
config: {
toolConfig: {
functionCallingConfig: {
mode: FunctionCallingConfigMode.ANY,
allowedFunctionNames: ["who_am_i"],
},
},
tools: [
{
functionDeclarations: [
{
name: "who_am_i",
description: "Get the current user info.",
parameters: {
type: Type.OBJECT,
properties: {},
required: [],
},
},
],
},
],
},
});
const functionCall = response.functionCalls?.[0];
if (functionCall?.name === "who_am_i") {
// Step 4: Execute the requested tool with Nango.
const userInfo = await nango.triggerAction(integrationId, connectionId, "whoami");
console.log("✅ Agent retrieved your Hubspot user info:", userInfo);
} else {
console.log(response.text);
}
}
You can let agents or models introspect available tools and their specifications by calling this endpoint. Your model can then automatically decide which tool to call.