Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Fix google genai provider
haxzie committed
May 28, 2025 at 13:24 UTC
f07f5d1c1ff8dec118ce917934cc8f77b2c3d9a7
5 files changed
+40
-46
examples/google/.env.example
+1
-3
@@ -1,6 +1,4 @@
1
# Composio API Key - Get it from https://app.composio.dev
2
COMPOSIO_API_KEY=
3
-GEMINI_API_KEY=your_composio_api_key_here
4
-
3
# Google GenAI (Gemini) API Key - Get it from https://ai.google.dev/
6
-GEMINI_API_KEY=your_gemini_api_key_here
4
+GEMINI_API_KEY=your_composio_api_key_here
\ No newline at end of file
examples/google/package.json
+7
-1
@@ -9,7 +9,13 @@
9
"dev": "bun --watch src/index.ts",
10
"test": "echo \"Error: no test specified\" && exit 1"
11
},
12
- "keywords": ["composio", "example", "google", "genai", "gemini"],
12
+ "keywords": [
13
+ "composio",
14
+ "example",
15
+ "google",
16
+ "genai",
17
+ "gemini"
18
+ ],
19
"author": "",
20
"license": "ISC",
21
"packageManager": "pnpm@10.8.0",
examples/google/src/index.ts
+12
-19
@@ -18,10 +18,9 @@ const ai = new GoogleGenAI({
18
apiKey: process.env.GEMINI_API_KEY,
19
});
20
21
-const provider = new GoogleProvider();
21
const composio = new Composio({
22
apiKey: process.env.COMPOSIO_API_KEY,
24
- provider,
23
+ provider: new GoogleProvider(),
24
});
25
26
/**
@@ -30,43 +29,37 @@ const composio = new Composio({
29
async function main() {
30
try {
31
console.log('🚀 Starting Google GenAI Example...');
33
-
32
+
33
const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER');
35
-
34
+
35
console.log(`✅ Found ${tools.length} tools`);
37
-
38
- const task = "Fetch the details of the user 'haxzie'";
36
+
37
+ const task = "Fetch the details of the user 'pg'";
38
console.log(`📝 Task: ${task}`);
40
-
41
- const wrappedTools = provider.wrapTools(tools as any);
42
-
39
+
40
const response = await ai.models.generateContent({
41
model: 'gemini-2.0-flash-001',
42
contents: task,
43
config: {
47
- tools: [{ functionDeclarations: wrappedTools as any }],
44
+ tools: [{ functionDeclarations: tools }],
45
},
46
});
50
-
47
+
48
console.log('✅ Response received from Gemini');
52
-
49
+
50
if (response.functionCalls) {
54
- console.log(`✅ Calling tool ${response.functionCalls[0].name}`);
51
+ console.log(`🔄 Calling tool ${response.functionCalls[0].name}`);
52
const functionCall = {
53
name: response.functionCalls[0].name || '',
57
- args: response.functionCalls[0].args || {}
54
+ args: response.functionCalls[0].args || {},
55
};
59
- const result = await provider.executeToolCall(
60
- 'default',
61
- functionCall
62
- );
56
+ const result = await composio.provider.executeToolCall('default', functionCall);
57
console.log('📊 Result:');
58
console.log(JSON.parse(result).data);
59
} else {
60
console.log('📝 No function calls in the response');
61
console.log(response.text);
62
}
69
-
63
} catch (error) {
64
console.error('❌ Error running example:', error);
65
}
packages/providers/google/package.json
+7
-1
@@ -24,7 +24,13 @@
24
"build": "tsup",
25
"test": "vitest run"
26
},
27
- "keywords": ["composio", "provider", "google", "genai", "gemini"],
27
+ "keywords": [
28
+ "composio",
29
+ "provider",
30
+ "google",
31
+ "genai",
32
+ "gemini"
33
+ ],
34
"author": "",
35
"license": "ISC",
36
"packageManager": "pnpm@10.8.0",
packages/providers/google/src/index.ts
+13
-22
@@ -7,28 +7,20 @@
7
* @packageDocumentation
8
* @module providers/google
9
*/
10
-import {
11
- BaseNonAgenticProvider,
12
- Tool,
10
+import {
11
+ BaseNonAgenticProvider,
12
+ Tool,
13
ToolExecuteParams,
14
ExecuteToolModifiers,
15
- ExecuteToolFnOptions
15
+ ExecuteToolFnOptions,
16
} from '@composio/core';
17
+import { FunctionDeclaration, Schema } from '@google/genai';
18
19
/**
20
* Interface for Google GenAI function declaration
21
* Based on the FunctionDeclaration type from @google/genai
22
*/
22
-export interface GoogleGenAIFunctionDeclaration {
23
- name?: string;
24
- description?: string;
25
- parameters?: {
26
- type: 'object';
27
- description?: string;
28
- properties: Record<string, unknown>;
29
- required?: string[];
30
- };
31
-}
23
+export type GoogleTool = FunctionDeclaration;
24
25
/**
26
* Interface for Google GenAI function call
@@ -42,13 +34,13 @@ export interface GoogleGenAIFunctionCall {
34
/**
35
* Type for a collection of Google GenAI function declarations
36
*/
45
-export type GoogleGenAIToolCollection = GoogleGenAIFunctionDeclaration[];
37
+export type GoogleGenAIToolCollection = GoogleTool[];
38
39
/**
40
* Google GenAI Provider for Composio SDK
41
* Implements the BaseNonAgenticProvider to wrap Composio tools for use with Google's GenAI API
42
*/
51
-export class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollection, GoogleGenAIFunctionDeclaration> {
43
+export class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollection, GoogleTool> {
44
readonly name = 'google';
45
46
/**
@@ -56,16 +48,15 @@ export class GoogleProvider extends BaseNonAgenticProvider<GoogleGenAIToolCollec
48
* @param tool - The Composio tool to wrap.
49
* @returns The wrapped tool in Google GenAI format.
50
*/
59
- wrapTool(tool: Tool): GoogleGenAIFunctionDeclaration {
51
+ wrapTool(tool: Tool): GoogleTool {
52
return {
53
name: tool.slug,
54
description: tool.description || '',
63
- parameters: {
55
+ parameters: (tool.inputParameters ?? {
56
type: 'object',
65
- description: tool.description || '',
66
- properties: (tool.inputParameters?.properties || {}) as Record<string, unknown>,
67
- required: Array.isArray(tool.inputParameters?.required) ? tool.inputParameters.required : [],
68
- },
57
+ properties: {},
58
+ required: [],
59
+ }) as unknown as Schema,
60
};
61
}
62