Skip to content

huytd/adk-openai-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

OpenAI-compatible API adapter for Google ADK Golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages