Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
9 changes: 8 additions & 1 deletion cmd/launcher/web/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,15 @@ func (a *apiLauncher) UserMessage(webURL string, printer func(v ...any)) {

// SetupSubrouters adds the API router to the parent router.
func (a *apiLauncher) SetupSubrouters(router *mux.Router, config *launcher.Config) error {
// Create the ADK REST API config
adkrestConfig := &adkrest.Config{
AgentLoader: config.AgentLoader,
SessionService: config.SessionService,
ArtifactService: config.ArtifactService,
SSEWriteTimeout: a.config.sseWriteTimeout,
}
// Create the ADK REST API handler
apiHandler := adkrest.NewHandler(config, a.config.sseWriteTimeout)
apiHandler := adkrest.NewHandler(adkrestConfig)

// Wrap it with CORS middleware
corsHandler := corsWithArgs(a.config.frontendAddress)(apiHandler)
Expand Down
10 changes: 5 additions & 5 deletions examples/rest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (

"google.golang.org/adk/agent"
"google.golang.org/adk/agent/llmagent"
"google.golang.org/adk/cmd/launcher"
"google.golang.org/adk/model/gemini"
"google.golang.org/adk/server/adkrest"
"google.golang.org/adk/session"
Expand Down Expand Up @@ -60,13 +59,14 @@ func main() {
}

// Configure the ADK REST API
config := &launcher.Config{
AgentLoader: agent.NewSingleLoader(a),
SessionService: session.InMemoryService(),
config := &adkrest.Config{
AgentLoader: agent.NewSingleLoader(a),
SessionService: session.InMemoryService(),
SSEWriteTimeout: 120 * time.Second,
}

// Create the REST API handler - this returns a standard http.Handler
apiHandler := adkrest.NewHandler(config, 120*time.Second)
apiHandler := adkrest.NewHandler(config)

// Create a standard net/http ServeMux
mux := http.NewServeMux()
Expand Down
31 changes: 31 additions & 0 deletions server/adkrest/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 adkrest

import (
"time"

"google.golang.org/adk/agent"
"google.golang.org/adk/artifact"
"google.golang.org/adk/session"
)

// Config defines the services and loaders required by the adkrest package.
type Config struct {
SessionService session.Service
ArtifactService artifact.Service
AgentLoader agent.Loader
SSEWriteTimeout time.Duration
}
6 changes: 2 additions & 4 deletions server/adkrest/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,18 @@ package adkrest

import (
"net/http"
"time"

"github.com/gorilla/mux"
sdktrace "go.opentelemetry.io/otel/sdk/trace"

"google.golang.org/adk/cmd/launcher"
"google.golang.org/adk/internal/telemetry"
"google.golang.org/adk/server/adkrest/controllers"
"google.golang.org/adk/server/adkrest/internal/routers"
"google.golang.org/adk/server/adkrest/internal/services"
)

// NewHandler creates and returns an http.Handler for the ADK REST API.
func NewHandler(config *launcher.Config, sseWriteTimeout time.Duration) http.Handler {
func NewHandler(config *Config) http.Handler {
adkExporter := services.NewAPIServerSpanExporter()
telemetry.AddSpanProcessor(sdktrace.NewSimpleSpanProcessor(adkExporter))

Expand All @@ -38,7 +36,7 @@ func NewHandler(config *launcher.Config, sseWriteTimeout time.Duration) http.Han
// where the ADK REST API will be served.
setupRouter(router,
routers.NewSessionsAPIRouter(controllers.NewSessionsAPIController(config.SessionService)),
routers.NewRuntimeAPIRouter(controllers.NewRuntimeAPIController(config.SessionService, config.AgentLoader, config.ArtifactService, sseWriteTimeout)),
routers.NewRuntimeAPIRouter(controllers.NewRuntimeAPIController(config.SessionService, config.AgentLoader, config.ArtifactService, config.SSEWriteTimeout)),
routers.NewAppsAPIRouter(controllers.NewAppsAPIController(config.AgentLoader)),
routers.NewDebugAPIRouter(controllers.NewDebugAPIController(config.SessionService, config.AgentLoader, adkExporter)),
routers.NewArtifactsAPIRouter(controllers.NewArtifactsAPIController(config.ArtifactService)),
Expand Down