Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions examples/vertexai/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"google.golang.org/adk/cmd/launcher/full"
"google.golang.org/adk/model/gemini"
"google.golang.org/adk/server/restapi/services"
"google.golang.org/adk/session"
"google.golang.org/adk/session/vertexai"
"google.golang.org/adk/tool"
"google.golang.org/adk/tool/geminitool"
"google.golang.org/genai"
Expand All @@ -38,11 +38,28 @@ const (
func main() {
ctx := context.Background()

rootAgent, err := сreateAgent()
projectID := os.Getenv("CLOUD_PROJECT_ID")
if projectID == "" {
log.Fatalf("Env var CLOUD_PROJECT_ID is not set")
}
location := os.Getenv("CLOUD_LOCATION")
if location == "" {
log.Fatalf("Env var CLOUD_LOCATION is not set")
}
engineId := os.Getenv("VERTEX_ENGINE_ID")
if engineId == "" {
log.Fatalf("Env var VERTEX_ENGINE_ID is not set")
}

rootAgent, err := createAgent()
if err != nil {
log.Fatalf("Failed to create agent: %v", err)
}
srvs, err := session.VertexAIService(ctx, modelName)
srvs, err := vertexai.NewSessionService(ctx, vertexai.VertexAIServiceConfig{
Location: location,
ProjectID: projectID,
ReasoningEngine: engineId,
})
if err != nil {
log.Fatalf("Failed to create session service: %v", err)
}
Expand All @@ -59,7 +76,7 @@ func main() {
}
}

func сreateAgent() (agent.Agent, error) {
func createAgent() (agent.Agent, error) {
ctx := context.Background()

model, err := gemini.NewModel(ctx, modelName, &genai.ClientConfig{})
Expand Down
90 changes: 90 additions & 0 deletions examples/vertexai/vertexengine/create_engine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright 2025 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package main

import (
"context"
"fmt"
"log"
"os"

aiplatform "cloud.google.com/go/aiplatform/apiv1"
"cloud.google.com/go/aiplatform/apiv1/aiplatformpb"
"google.golang.org/api/option"
)

// main defines an example of how to initialize a vertex ai reasoning engine
func main() {
ctx := context.Background()
projectID := os.Getenv("CLOUD_PROJECT_ID")
if projectID == "" {
log.Fatalf("Env var CLOUD_PROJECT_ID is not set")
}
location := os.Getenv("CLOUD_LOCATION")
if location == "" {
log.Fatalf("Env var CLOUD_LOCATION is not set")
}

err := createReasoningEngine(ctx, projectID, location, "adk-go", "A reasoning engine created by an adk go sample")
if err != nil {
log.Fatalf("Failed to create reasoning engine: %v", err)
}
}

func createReasoningEngine(ctx context.Context, projectID, location, displayName, description string) error {
// Construct the parent resource name
parent := fmt.Sprintf("projects/%s/locations/%s", projectID, location)

// Construct the regional endpoint
endpoint := fmt.Sprintf("%s-aiplatform.googleapis.com:443", location)

// Create the client
client, err := aiplatform.NewReasoningEngineClient(ctx, option.WithEndpoint(endpoint))
if err != nil {
return fmt.Errorf("failed to create ReasoningEngineClient: %w", err)
}
defer func() {
if err := client.Close(); err != nil {
log.Printf("Warning: failed to close client: %v", err)
}
}()

// Define the ReasoningEngine object
reasoningEngine := &aiplatformpb.ReasoningEngine{
DisplayName: displayName,
Description: description,
}

// Create the request
req := &aiplatformpb.CreateReasoningEngineRequest{
Parent: parent,
ReasoningEngine: reasoningEngine,
}

// Call the CreateReasoningEngine method
op, err := client.CreateReasoningEngine(ctx, req)
if err != nil {
return fmt.Errorf("failed to call CreateReasoningEngine: %w", err)
}

// Wait for the long-running operation to complete
resp, err := op.Wait(ctx)
if err != nil {
return fmt.Errorf("failed to wait for operation: %w", err)
}

fmt.Printf("Successfully created ReasoningEngine: %s\n", resp.Name)
return nil
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module google.golang.org/adk
go 1.24.4

require (
cloud.google.com/go/aiplatform v1.105.0
cloud.google.com/go/storage v1.56.1
github.com/google/go-cmp v0.7.0
github.com/google/uuid v1.6.0
Expand All @@ -18,6 +19,7 @@ require (
github.com/google/jsonschema-go v0.3.0
github.com/modelcontextprotocol/go-sdk v0.7.0
google.golang.org/grpc v1.76.0
google.golang.org/protobuf v1.36.10
gorm.io/driver/sqlite v1.6.0
gorm.io/gorm v1.31.0
)
Expand Down Expand Up @@ -79,5 +81,4 @@ require (
golang.org/x/sys v0.37.0 // indirect
golang.org/x/text v0.30.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20251014184007-4626949a642f // indirect
google.golang.org/protobuf v1.36.10 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ cel.dev/expr v0.24.0 h1:56OvJKSH3hDGL0ml5uSxZmz3/3Pq4tJ+fb1unVLAFcY=
cel.dev/expr v0.24.0/go.mod h1:hLPLo1W4QUmuYdA72RBX06QTs6MXw941piREPl3Yfiw=
cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE=
cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU=
cloud.google.com/go/aiplatform v1.105.0 h1:Tbc2iEp7vbzgk6Vs4QexfNo8/nl+E+Na+FEreRZdhcM=
cloud.google.com/go/aiplatform v1.105.0/go.mod h1:4rwKOMdubQOND81AlO3EckcskvEFCYSzXKfn42GMm8k=
cloud.google.com/go/auth v0.17.0 h1:74yCm7hCj2rUyyAocqnFzsAYXgJhrG26XCFimrc/Kz4=
cloud.google.com/go/auth v0.17.0/go.mod h1:6wv/t5/6rOPAX4fJiRjKkJCvswLwdet7G8+UGXt7nCQ=
cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc=
Expand Down
5 changes: 0 additions & 5 deletions session/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ func InMemoryService() Service {
}
}

// VertexAIService returns VertextAiSessionService implementation.
func VertexAIService(ctx context.Context, model string) (Service, error) {
return newVertexAiSessionService(ctx, model)
}

// CreateRequest represents a request to create a session.
type CreateRequest struct {
AppName string
Expand Down
74 changes: 0 additions & 74 deletions session/vertexai.go

This file was deleted.

Loading