Skip to content

Invalid JSON payload: “text” at system_instruction.parts[0] when using Gemini model via @openai/agents-extensions #34

@Codewithsaffy

Description

@Codewithsaffy

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

  1. Create a new folder and run:

    npm init -y
  2. Install these dependencies:

    npm install @openai/agents @openai/agents-extensions @ai-sdk/google dotenv
  3. Create a file named main.ts (or main.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);
    })();
  4. Create a .env file and set your Gemini API key (e.g. GOOGLE_API_KEY=<your_key>).

  5. Run the script:

    node main.ts
  6. 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.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions