-
Notifications
You must be signed in to change notification settings - Fork 497
Description
Describe the bug
When creating an Agent with the instructions field and using the Gemini model (gemini-2.0-flash) via @openai/agents-extensions (which wraps @ai-sdk/google), the system prompt is serialized incorrectly. Instead of sending each part’s text as a string, the SDK wraps it in an array. The Gemini endpoint then rejects the request with:
APICallError [AI_APICallError]: Invalid JSON payload received. Unknown name "text" at 'system_instruction.parts[0]': Proto field is not repeating, cannot start list.
Debug information
-
Agents SDK version: v0.0.2
-
@openai/agents-extensions version: v0.0.2
-
@ai-sdk/google version: v1.2.19
-
Runtime environment:
- Node.js v22.12.0
- OS: Windows 10 Pro (build 2004)
Repro steps
-
Create a new folder and run:
npm init -y
-
Install these dependencies:
npm install @openai/agents @openai/agents-extensions @ai-sdk/google dotenv
-
Create a file named
main.ts(ormain.js) with the following content:import { Agent, run } from '@openai/agents'; import { google } from '@ai-sdk/google'; import { aisdk } from '@openai/agents-extensions'; import { setTracingDisabled } from '@openai/agents'; import dotenv from 'dotenv'; dotenv.config(); setTracingDisabled(true); // Initialize Gemini model via Vercel AI SDK const model = aisdk(google('gemini-2.0-flash')); // Pass an `instructions` string to the Agent constructor const agent = new Agent({ name: 'My Agent', instructions: 'You are a helpful assistant.', model, }); (async () => { const result = await run(agent, 'What is the capital of France?'); console.log(result.finalOutput); })();
-
Create a
.envfile and set your Gemini API key (e.g.GOOGLE_API_KEY=<your_key>). -
Run the script:
node main.ts
-
Observe the error:
APICallError [AI_APICallError]: Invalid JSON payload received. Unknown name "text" at 'system_instruction.parts[0]': Proto field is not repeating, cannot start list. at …/provider-utils/src/response-handler.ts:59:16 … requestBodyValues: contents: [{ role: 'user', parts: [{ text: 'What is the capital of France?' }] }] systemInstruction: { parts: [{ text: [ [Object] ] }] } … statusCode: 400
Expected behavior
The SDK should serialize the instructions string into a single-element parts array where parts[0].text is a plain string, for example:
"systemInstruction": {
"parts": [
{ "text": "You are a helpful assistant." }
]
}With this correct format, Gemini’s API would accept the request and return a valid response.