Documentation
Gemini generateContent
Use Milkey inline tools with the official Google Gen AI SDK and a bounded function-calling loop.
Overview
Gemini `generateContent` is an inline-only surface in the SDK and is designed to work with the official Google Gen AI SDK function-calling model.
This path is best when you want provider-native Gemini inline tooling and can own the bounded loop in your application.
Recommended
Recommended default: inline
Supported modes
inline, auto
Helpers
- milkey.gemini.config(...)
- milkey.gemini.extractFunctionCalls(...)
- milkey.gemini.parts(...)
- milkey.gemini.followUpContents(...)
Examples
Full GitHub example
Use the complete provider example in the SDK repo when you want the full runnable file with imports, env handling, and a realistic integration shape. Open the GitHub example.
examples/gemini-official-sdk.ts
import { GoogleGenAI } from "@google/genai"import { milkey } from "@milkeyskills/sdk" const ai = new GoogleGenAI({ apiKey: process.env.GEMINI_API_KEY!,}) const milkeyClient = milkey.createClient({ baseUrl: process.env.MILKEY_BASE_URL!, apiKey: process.env.MILKEY_API_KEY!,}) let contents = [ { role: "user", parts: [ { text: "Find the best Milkey skill for PostgreSQL query optimization.", }, ], },] for (let turn = 1; turn <= 4; turn += 1) { const response = await ai.models.generateContent({ model: process.env.GEMINI_MODEL ?? "gemini-2.5-flash", contents, config: milkey.gemini.config({ client: milkeyClient, allowedTools: ["resolve-skill"], }), }) const calls = milkey.gemini.extractFunctionCalls(response) if (calls.length === 0) break const toolResponse = await milkey.gemini.parts(calls, milkeyClient) contents = milkey.gemini.followUpContents(contents, response, toolResponse)}Edge cases and production notes
- Use `allowedTools` aggressively in Gemini loops when you want narrower behavior and lower tool noise.
- The Gemini helper family is intentionally split so you can keep the rest of your request shape provider-native.
Watch for these edges
- Hosted mode is not supported on `generateContent`.
- Your loop must handle the case where Gemini returns no function calls and finish cleanly.