Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
/**
* Google GenAI Example
*
* This example demonstrates how to use Composio SDK with Google's GenAI (Gemini).
*
* Prerequisites:
* 1. Set up your COMPOSIO_API_KEY in the .env file
* 2. Set up your GEMINI_API_KEY in the .env file
* 3. Run the example: pnpm start
*/
import { Composio } from '@composio/core';
import { GoogleGenAI } from '@google/genai';
import { GoogleProvider } from '@composio/google';
import 'dotenv/config';
const ai = new GoogleGenAI({
apiKey: process.env.GEMINI_API_KEY,
});
const composio = new Composio({
apiKey: process.env.COMPOSIO_API_KEY,
provider: new GoogleProvider(),
});
/**
* Main function to run the example
*/
async function main() {
try {
console.log('π Starting Google GenAI Example...');
const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
console.log(`β
Found ${tools.length} tools`);
const task = "Fetch the details of the user 'pg'";
console.log(`π Task: ${task}`);
const response = await ai.models.generateContent({
model: 'gemini-2.0-flash-001',
contents: task,
config: {
tools: [{ functionDeclarations: tools }],
},
});
console.log('β
Response received from Gemini');
if (response.functionCalls) {
console.log(`π Calling tool ${response.functionCalls[0].name}`);
const functionCall = {
name: response.functionCalls[0].name || '',
args: response.functionCalls[0].args || {},
};
const result = await composio.provider.executeToolCall('default', functionCall);
console.log('π Result:');
console.log(JSON.parse(result).data);
} else {
console.log('π No function calls in the response');
console.log(response.text);
}
} catch (error) {
console.error('β Error running example:', error);
process.exitCode = 1;
}
}
// Run the example
main().catch(error => {
console.error(error);
process.exitCode = 1;
});