@devries-cameron20 / composio Mirror · read-only
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

Mirrored from https://github.com/Camo67/composio.git

Synced Nov 21, 06:00 UTC

next
md 72 lines 2.55 KB
Rendered Raw
1 # @composio/google
2
3 Adapts Composio tools to Gemini function declarations for the Google GenAI SDK (`@google/genai`) and executes the function calls the model returns.
4
5 ## Installation
6
7 ```bash
8 npm install @composio/core @composio/google @google/genai
9 ```
10
11 Set `COMPOSIO_API_KEY` (create one at https://dashboard.composio.dev/settings) and `GOOGLE_API_KEY` (from https://aistudio.google.com/apikey) in your environment.
12
13 ## Quickstart
14
15 Create a session for your user, pass its tools to Gemini as function declarations, and run the loop: execute each function call with `composio.provider.executeToolCall`, feed the result back, and repeat until the model replies with text.
16
17 ```typescript
18 import { Composio } from '@composio/core';
19 import { GoogleProvider } from '@composio/google';
20 import { GoogleGenAI, type Part } from '@google/genai';
21
22 const composio = new Composio({
23 provider: new GoogleProvider(),
24 });
25 const ai = new GoogleGenAI({ apiKey: process.env.GOOGLE_API_KEY! });
26
27 // Create a session for your user
28 const session = await composio.create('user_123');
29 const tools = await session.tools();
30
31 const chat = ai.chats.create({
32 model: 'gemini-3-pro-preview',
33 config: {
34 tools: [{ functionDeclarations: tools }],
35 },
36 });
37
38 let response = await chat.sendMessage({
39 message:
40 "Send an email to john@example.com with the subject 'Hello' and body 'Hello from Composio!'",
41 });
42
43 // Agentic loop: keep executing tool calls until the model responds with text
44 while (response.functionCalls && response.functionCalls.length > 0) {
45 const parts: Part[] = [];
46 for (const fc of response.functionCalls) {
47 const result = await composio.provider.executeToolCall(session, {
48 name: fc.name || '',
49 args: (fc.args || {}) as Record<string, unknown>,
50 });
51 parts.push({
52 functionResponse: {
53 id: fc.id,
54 name: fc.name,
55 response: JSON.parse(result),
56 },
57 });
58 }
59 response = await chat.sendMessage({ message: parts });
60 }
61
62 console.log(response.text);
63 ```
64
65 ## Tool execution
66
67 Gemini function calling is non-agentic; the model returns function calls and you execute them. `GoogleProvider` exposes `executeToolCall(session, functionCall)`, which takes a `{ name, args }` pair, executes it through the session that produced the tools, and returns the tool result as a JSON string. For tools fetched with `tools.get()`, call `executeToolCall(userId, functionCall, options?, modifiers?)` instead. The constructor takes no options.
68
69 ## Links
70
71 - [Google provider docs](https://docs.composio.dev/docs/providers/google)
72 - [Composio documentation](https://docs.composio.dev)