AgentSkillsCN

openai-agents-gemini

【做什么】基于 Gemini 作为后端 LLM,搭建 OpenAI Agents SDK 环境。 【何时】当用户希望通过 OpenAI 兼容的 API,使用 Google Gemini 模型运行 OpenAI Agents 时使用。

SKILL.md
--- frontmatter
name: openai-agents-gemini
description: |
  [What] Creates an OpenAI Agents SDK setup using Gemini as the backend LLM.
  [When] Use when users want to run OpenAI Agents with Google Gemini models via the OpenAI-compatible API.
allowed-tools: Write, Read

OpenAI Agents SDK (Gemini Backend)

Creates a functional OpenAI Agents SDK skill configured to use Google's Gemini models via the OpenAI-compatible API endpoint.

What This Skill Does

  • Configures AsyncOpenAI client to point to generativelanguage.googleapis.com.
  • Implements OpenAIChatCompletionsModel using the custom client.
  • Defines functional tools (@function_tool) for the agent.
  • Provides a runnable script (agent_gemini.py) using Runner.run_sync.
  • Sets up .env template for keys.

What This Skill Does NOT Do

  • Use real OpenAI models (GPT-4, etc.) unless reconfigured.
  • Handle OAuth for Google Cloud (uses API Key auth).
  • Deploy the agent to a server (runs locally).

Before Implementation

Gather context to ensure successful implementation:

SourceGather
CodebaseExisting .env file location, Python dependency management (poetry/pip).
ConversationUser's specific API key availability (GEMINI_API_KEY).
Skill Referencesreferences/gemini-config.md for client setup details.
User GuidelinesPreference for sync vs async runner.

Ensure all required context is gathered before implementing. Only ask user for THEIR specific requirements (domain expertise is in this skill).


Output Checklist

  • Runnable Python script agent_gemini.py created.
  • .env file (or template) created with GEMINI_API_KEY.
  • AsyncOpenAI client uses correct Google base_url.
  • Agent instantiated with model=llm_model wrapper.
  • Tools defined and attached to Agent.

Reference Files

FileWhen to Read
references/gemini-config.mdFor deeper understanding of the Gemini/OpenAI adapter pattern.
assets/agent_gemini.pyThe complete source code implementation.

Usage Instructions

  1. Install Dependencies:
    bash
    pip install openai-agents python-dotenv
    
  2. Setup Environment: Create .env:
    env
    GEMINI_API_KEY=your_google_ai_studio_key
    OPENAI_API_KEY=dummy_val_for_tracing
    
  3. Run Agent:
    bash
    python agent_gemini.py