adkopenai

package module
v0.0.0-...-56ccd9b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2026 License: BSD-3-Clause Imports: 11 Imported by: 0

README

ADK OpenAI Go

OpenAI Adapter for Google's Agent Development Kit (ADK) in Go.

This library allows you to use any OpenAI-compatible API with Google ADK agents.

Installation

go get github.com/huytd/adk-openai-go

Usage

Basic Usage
package main

import (
    "context"
    "log"

    adkopenai "github.com/huytd/adk-openai-go"
    "google.golang.org/adk/agent"
)

func main() {
    ctx := context.Background()

    // Create a new OpenAI model (uses OPENAI_API_KEY env var by default)
    model, err := adkopenai.NewModel(ctx, "gpt-5-mini", nil)
    if err != nil {
        log.Fatal(err)
    }

    // Use the model with ADK agents
    myAgent := agent.New(agent.Config{
        Name:  "my-agent",
        Model: model,
        // ... other config
    })

    _ = myAgent
}
Custom Configuration
cfg := &adkopenai.Config{
    APIKey:           "your-api-key",
    BaseURL:          "https://api.openai.com/v1",
}

model, err := adkopenai.NewModel(ctx, "gpt-5-mini", cfg)
OpenAI-Compatible APIs

This adapter works with any OpenAI-compatible API by setting the BaseURL:

Ollama:

cfg := &adkopenai.Config{
    BaseURL: "http://localhost:11434/v1",
}

model, err := adkopenai.NewModel(ctx, "<model-name>", cfg)

LM Studio:

cfg := &adkopenai.Config{
    BaseURL: "http://localhost:1234/v1",
}

model, err := adkopenai.NewModel(ctx, "<model-name>", cfg)

Other providers:

cfg := &adkopenai.Config{
    BaseURL: "<base-url>",
    APIKey:  "<api-key>",
}

model, err := adkopenai.NewModel(ctx, "gpt-5-mini", cfg)

Environment Variables

Variable Description
OPENAI_API_KEY OpenAI API key (used if Config.APIKey is not set)
OPENAI_API_BASE_URL Base URL for the OpenAI-compatible API

Example

See the examples directory for a complete working example that demonstrates:

  • Creating an OpenAI model adapter
  • Defining multiple function tools (weather, time)
  • Setting up session management
  • Running an agent with the ADK runner
  • Handling streaming events

Run the example:

cd examples/
OPENAI_API_KEY=your-api-key go run agent.go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewModel

func NewModel(modelName string, cfg *Config) model.LLM

NewModel creates a new OpenAI model adapter for ADK. If cfg is nil, it will use environment variables (OPENAI_API_KEY, OPENAI_API_BASE_URL).

Types

type Config

type Config struct {
	APIKey  string
	BaseURL string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL