hostedagent

package
v2.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package hostedagent adapts local API-backed models to the ADK agent interface.

The package centers on New, which wraps a google.golang.org/adk/v2/model.LLM into an ADK agent. Helper constructors such as NewOpenAIModel and NewAIStudioModel build model implementations for common hosted providers.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) (adkagent.Agent, error)

New wraps a hosted model as an ADK agent.

Example
package main

import (
	"context"
	"fmt"
	"iter"

	"google.golang.org/adk/v2/model"
)

type exampleModel struct{}

func (exampleModel) Name() string {
	return "example-model"
}

func (exampleModel) GenerateContent(context.Context, *model.LLMRequest, bool) iter.Seq2[*model.LLMResponse, error] {
	return func(func(*model.LLMResponse, error) bool) {}
}

func main() {
	agent, err := New(Config{
		Name:        "assistant",
		Description: "Hosted assistant",
		Model:       exampleModel{},
	})
	if err != nil {
		fmt.Println(err)
		return
	}

	fmt.Println(agent.Name())
	fmt.Println(agent.Description())
}
Output:
assistant
Hosted assistant

func NewAIStudioModel

func NewAIStudioModel(ctx context.Context, apiKey, modelName string) (model.LLM, error)

NewAIStudioModel creates an ADK-compatible Gemini model backed by Google AI Studio.

func ValidateAIStudioModel added in v2.3.0

func ValidateAIStudioModel(modelName string) error

ValidateAIStudioModel checks the required model parameter without creating a client. Credentials continue to use the client SDK's environment defaults.

func ValidateOpenAIModelOptions added in v2.3.0

func ValidateOpenAIModelOptions(apiKey, modelName string, opts OpenAIModelOptions) error

ValidateOpenAIModelOptions checks construction parameters without starting a provider, opening MCP connections, or issuing model requests.

Types

type Config

type Config struct {
	// Name is the ADK agent display name.
	Name string
	// Description is the ADK agent description.
	Description string
	// Instruction is appended after GlobalInstruction for each model request.
	Instruction string
	// GlobalInstruction is prepended before Instruction for each model request.
	GlobalInstruction string
	// Model handles underlying content generation.
	Model model.LLM
	// Tools contains ADK-native tools available to the hosted agent.
	Tools []tool.Tool
	// Toolsets contains ADK-native toolsets available to the hosted agent.
	Toolsets []tool.Toolset
}

Config describes an ADK agent backed by a hosted model implementation.

type OpenAIModel

type OpenAIModel struct {
	// contains filtered or unexported fields
}

OpenAIModel adapts the OpenAI chat completions API to the ADK model interface.

func NewOpenAIModel

func NewOpenAIModel(apiKey, modelName string) (*OpenAIModel, error)

NewOpenAIModel creates an ADK-compatible model backed by the OpenAI API.

func NewOpenAIModelWithOptions added in v2.2.0

func NewOpenAIModelWithOptions(apiKey, modelName string, opts OpenAIModelOptions) (*OpenAIModel, error)

NewOpenAIModelWithOptions creates a model with explicit request options.

func NewOpenAIModelWithTimeout added in v2.2.0

func NewOpenAIModelWithTimeout(apiKey, modelName string, timeout time.Duration) (*OpenAIModel, error)

NewOpenAIModelWithTimeout creates a model with a configured HTTP request timeout.

func (*OpenAIModel) GenerateContent

func (m *OpenAIModel) GenerateContent(ctx context.Context, req *model.LLMRequest, _ bool) iter.Seq2[*model.LLMResponse, error]

GenerateContent sends a single non-streaming request to the OpenAI API.

func (*OpenAIModel) Name

func (m *OpenAIModel) Name() string

Name returns the configured OpenAI model identifier.

type OpenAIModelOptions added in v2.2.0

type OpenAIModelOptions struct {
	// Timeout defaults to 30 seconds when zero.
	Timeout time.Duration
	// ReasoningEffort is omitted when empty. Only "none" is supported.
	ReasoningEffort string
}

OpenAIModelOptions controls optional OpenAI-compatible request behavior.

Jump to

Keyboard shortcuts

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