Agent Executor (AX) is Google's open agentic orchestration runtime
Go
Remove the browse agent (#66)
Jaana Dogan4f2344af2c84
diff --git a/go.mod b/go.modindex 2784d6a..3b2604c 100644--- a/go.mod+++ b/go.mod@@ -3,7 +3,6 @@ module github.com/google/gargo 1.24.0require (- github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.0github.com/charmbracelet/huh v0.8.0github.com/charmbracelet/lipgloss v1.1.1-0.20250404203927-76690c660834github.com/google/uuid v1.6.0@@ -12,14 +11,12 @@ require (google.golang.org/grpc v1.78.0google.golang.org/protobuf v1.36.11gopkg.in/yaml.v3 v3.0.1- mvdan.cc/xurls/v2 v2.6.0)require (cloud.google.com/go v0.116.0 // indirectcloud.google.com/go/auth v0.9.3 // indirectcloud.google.com/go/compute/metadata v0.9.0 // indirect- github.com/JohannesKaufmann/dom v0.2.0 // indirectgithub.com/atotto/clipboard v0.1.4 // indirectgithub.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirectgithub.com/catppuccin/go v0.3.0 // indirectdiff --git a/go.sum b/go.sumindex b9fba2d..8d26566 100644--- a/go.sum+++ b/go.sum@@ -6,10 +6,6 @@ cloud.google.com/go/auth v0.9.3/go.mod h1:7z6VY+7h3KUdRov5F1i8NDP5ZzWKYmEPO842Bgcloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs=cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=-github.com/JohannesKaufmann/dom v0.2.0 h1:1bragmEb19K8lHAqgFgqCpiPCFEZMTXzOIEjuxkUfLQ=-github.com/JohannesKaufmann/dom v0.2.0/go.mod h1:57iSUl5RKric4bUkgos4zu6Xt5LMHUnw3TF1l5CbGZo=-github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.0 h1:mklaPbT4f/EiDr1Q+zPrEt9lgKAkVrIBtWf33d9GpVA=-github.com/JohannesKaufmann/html-to-markdown/v2 v2.5.0/go.mod h1:D56Cl9r8M5i3UwAchE+LlLc5hPN3kJtdZNVJn06lSHU=github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ=github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE=github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=@@ -132,7 +128,6 @@ github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfgithub.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc=github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk=github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=@@ -141,10 +136,6 @@ github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fgithub.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=-github.com/sebdah/goldie/v2 v2.8.0 h1:dZb9wR8q5++oplmEiJT+U/5KyotVD+HNGCAc5gNr8rc=-github.com/sebdah/goldie/v2 v2.8.0/go.mod h1:oZ9fp0+se1eapSRjfYbsV/0Hqhbuu3bJVvKI/NNtssI=-github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw=-github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=@@ -158,8 +149,6 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoOgithub.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no=github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=-github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=-github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=@@ -254,5 +243,3 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=-mvdan.cc/xurls/v2 v2.6.0 h1:3NTZpeTxYVWNSokW3MKeyVkz/j7uYXYiMtXRUfmjbgI=-mvdan.cc/xurls/v2 v2.6.0/go.mod h1:bCvEZ1XvdA6wDnxY7jPPjEmigDtvtvPXAD/Exa9IMSk=diff --git a/internal/controller/controller.go b/internal/controller/controller.goindex 31b7992..f8c4318 100644--- a/internal/controller/controller.go+++ b/internal/controller/controller.go@@ -24,7 +24,6 @@ import ("github.com/google/gar/agent""github.com/google/gar/internal/config""github.com/google/gar/internal/eventlog"- "github.com/google/gar/internal/localagent/browser""github.com/google/gar/proto")@@ -73,9 +72,6 @@ func New(ctx context.Context, config Config) (*Controller, error) {if err != nil {return nil, fmt.Errorf("failed to create registry: %w", err)}- if err := registerDefaultLocalAgents(registry); err != nil {- return nil, fmt.Errorf("failed to register default local agents: %w", err)- }// Determine plan function// If no planner builder is provided, use the default Gemini planner.@@ -109,15 +105,6 @@ func New(ctx context.Context, config Config) (*Controller, error) {}, nil}-func registerDefaultLocalAgents(r *Registry) error {- return r.RegisterLocal(config.LocalAgentConfig{- ID: "browser",- Name: "Browser Agent",- Description: "An agent that can fetch a URL. The agent returns the content of the page as markdown. Only use this agent if user specifically provides a URL to fetch.",- Agent: browser.NewAgent(),- })-}-// TriggerSession triggers a new agentic loop session or resumes an existing one.// If sessionID is empty, a UUID will be generated.// If the session already exists, it will be resumed with optional new inputs.diff --git a/internal/controller/gemini.go b/internal/controller/gemini.goindex 2e2cc6e..a70622f 100644--- a/internal/controller/gemini.go+++ b/internal/controller/gemini.go@@ -329,7 +329,7 @@ func (p *geminiPlannerAgent) Process(ctx context.Context, sessionID string, incoif err != nil {return fmt.Errorf("failed to convert function response to structpb: %w", err)}-+return handler(&proto.ProcessResponse{Contents: []*proto.Content{{Role: "assistant", // Note: The history uses assistant for nowdiff --git a/internal/localagent/browser/agent.go b/internal/localagent/browser/agent.godeleted file mode 100644index 3c8ea0d..0000000--- a/internal/localagent/browser/agent.go+++ /dev/null@@ -1,151 +0,0 @@-// Copyright 2026 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 browser provides an agent that fetches and converts web content to text.-package browser--import (- "context"- "fmt"- "net/url"- "strings"-- "github.com/google/gar/agent"- "github.com/google/gar/proto"- "github.com/google/uuid"- "mvdan.cc/xurls/v2"-)--// BrowserAgent takes a URL and retrieves its web contents.-// It fetches HTML pages and converts them to plain text format.-type BrowserAgent struct {- fetcher *webFetcher-}--// NewAgent creates a new browser agent with default HTTP client settings.-func NewAgent() *BrowserAgent {- return &BrowserAgent{- fetcher: newWebFetcher(nil),- }-}--var _ agent.Agent = (*BrowserAgent)(nil)--// Process handles incoming requests containing URLs to fetch.-// It extracts the URL from the request, fetches the page content,-// and streams the result back through the handler.-func (a *BrowserAgent) Process(ctx context.Context, sessionID string, incoming *proto.ProcessRequest, handler agent.OutputHandler) error {- text := readUserText(incoming)- if text == "" {- return a.emit(handler, "Please provide a URL to fetch")- }-- q, err := parseNaturalText(text)- if err != nil {- return a.emit(handler, "Invalid URL: "+err.Error())- }-- page, err := a.fetcher.Fetch(ctx, q)- if err != nil {- return a.emit(handler, "Failed to fetch: "+err.Error())- }-- body := page.Body- if body == "" {- body = "(empty body)"- }- return a.emit(handler,- fmt.Sprintf("Fetched: %s\nStatus: %d\nContent-Type: %s\n\n%s", page.URL, page.StatusCode, page.ContentType, body))-}--// HealthCheck verifies the agent is operational.-func (a *BrowserAgent) HealthCheck(ctx context.Context) error {- return nil-}--// Close cleans up any resources held by the agent.-func (a *BrowserAgent) Close() error {- return nil-}--// emit is a helper that sends a text response through the output handler.-// It generates a new UUID for each response checkpoint.-func (a *BrowserAgent) emit(handler agent.OutputHandler, text string) error {- return handler(&proto.ProcessResponse{- CheckpointId: uuid.New().String(),- Contents: []*proto.Content{- {- Role: "assistant",- Content: &proto.Content_Text{Text: &proto.TextContent{Text: text}},- },- },- })-}--// readUserText extracts the most recent text content from the request.-// It searches backwards through the contents to find the latest user message.-func readUserText(incoming *proto.ProcessRequest) string {- for i := len(incoming.Contents) - 1; i >= 0; i-- {- if c := incoming.Contents[i]; c != nil {- if t := c.GetText(); t != nil {- if txt := strings.TrimSpace(t.Text); txt != "" {- return txt- }- }- }- }- return ""-}--// parseNaturalText parses input into a URL-only browser query.-func parseNaturalText(input string) (Query, error) {- relaxedRegex := xurls.Relaxed()- relaxedURLs := relaxedRegex.FindAllString(input, -1)- if len(relaxedURLs) > 0 {- url := relaxedURLs[len(relaxedURLs)-1]- if !strings.HasPrefix(url, "http") {- url = "https://" + url- }- return Query{URL: url}, nil- }-- input = strings.TrimSpace(input)- if input == "" {- return Query{}, fmt.Errorf("empty request")- }- u, err := parseURL(input)- if err != nil {- return Query{}, err- }- return Query{URL: u}, nil-}--// parseURL validates and normalizes a URL string.-// It adds https:// scheme if missing and validates the URL format.-func parseURL(s string) (string, error) {- if !strings.Contains(s, "://") {- s = "https://" + s- }- u, err := url.ParseRequestURI(s)- if err != nil {- return "", fmt.Errorf("invalid URL")- }- if u.Scheme != "http" && u.Scheme != "https" {- return "", fmt.Errorf("scheme must be http or https")- }- if u.Host == "" {- return "", fmt.Errorf("missing host")- }- return u.String(), nil-}diff --git a/internal/localagent/browser/agent_test.go b/internal/localagent/browser/agent_test.godeleted file mode 100644index 1cf8344..0000000--- a/internal/localagent/browser/agent_test.go+++ /dev/null@@ -1,84 +0,0 @@-// Copyright 2026 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 browser--import (- "context"- "io"- "net/http"- "strings"- "testing"-- "github.com/google/gar/proto"-)--func testFetcher(t *testing.T) *webFetcher {- t.Helper()- client := newMockClient(func(r *http.Request) (*http.Response, error) {- return &http.Response{- StatusCode: http.StatusOK,- Body: io.NopCloser(strings.NewReader("<html><body>Sample content</body></html>")),- Header: http.Header{"Content-Type": []string{"text/html"}},- }, nil- })- return newWebFetcher(client)-}--func newTestAgent(t *testing.T) *BrowserAgent {- t.Helper()- return &BrowserAgent{- fetcher: testFetcher(t),- }-}--func TestBrowserAgentProcess(t *testing.T) {- a := newTestAgent(t)-- var chunks []string- err := a.Process(context.Background(), "s1", &proto.ProcessRequest{- CheckpointId: "cp1",- Contents: []*proto.Content{- {- Role: "user",- Content: &proto.Content_Text{Text: &proto.TextContent{Text: "Check out this URL: example.test/page"}},- },- },- }, func(out *proto.ProcessResponse) error {- if out.CheckpointId == "" {- t.Fatalf("checkpoint ID should not be empty")- }- if len(out.Contents) == 0 || out.Contents[0].GetText() == nil {- t.Fatalf("missing text content")- }- chunks = append(chunks, out.Contents[0].GetText().Text)- return nil- })- if err != nil {- t.Fatalf("Process() error = %v", err)- }- if len(chunks) != 1 {- t.Fatalf("expected 1 chunk, got %d", len(chunks))- }- last := chunks[0]- if !strings.Contains(last, "Fetched: https://example.test/page") {- t.Fatalf("missing fetched URL: %s", last)- }- if !strings.Contains(last, "Sample content") {- t.Fatalf("missing page body: %s", last)- }- if strings.Contains(last, "<body>") || strings.Contains(last, "<html>") {- t.Fatalf("expected html stripped: %s", last)- }-}diff --git a/internal/localagent/browser/fetcher.go b/internal/localagent/browser/fetcher.godeleted file mode 100644index 7ed3d4a..0000000--- a/internal/localagent/browser/fetcher.go+++ /dev/null@@ -1,86 +0,0 @@-// Copyright 2026 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 browser--import (- "context"- "io"- "net/http"- "strings"- "time"-- htmltomarkdown "github.com/JohannesKaufmann/html-to-markdown/v2"-)--// Query represents a validated URL to fetch.-type Query struct {- URL string-}--// PageContent contains the fetched page data including headers and converted text body.-type PageContent struct {- URL string // The final URL after any redirects- StatusCode int // HTTP status code- ContentType string // Content-Type header value- Body string // HTML converted to plain text-}--// maxFetchBytes limits how much data can be downloaded from a single page.-const maxFetchBytes = 256 * 1024--// webFetcher retrieves and converts web pages to text.-type webFetcher struct {- client *http.Client-}--// newWebFetcher creates a new web fetcher with the given HTTP client.-// If client is nil, a default client with 15-second timeout is used.-func newWebFetcher(client *http.Client) *webFetcher {- if client == nil {- return &webFetcher{client: &http.Client{Timeout: 15 * time.Second}}- }- return &webFetcher{client: client}-}--// Fetch retrieves the page at the given URL and converts HTML to plain text.-// It respects the context for cancellation and enforces a maxFetchBytes limit.-func (f *webFetcher) Fetch(ctx context.Context, q Query) (PageContent, error) {- req, err := http.NewRequestWithContext(ctx, http.MethodGet, q.URL, nil)- if err != nil {- return PageContent{}, err- }- resp, err := f.client.Do(req)- if err != nil {- return PageContent{}, err- }- defer resp.Body.Close()-- bodyBytes, err := io.ReadAll(io.LimitReader(resp.Body, maxFetchBytes))- if err != nil {- return PageContent{}, err- }-- markdown, err := htmltomarkdown.ConvertString(string(bodyBytes))- if err != nil {- return PageContent{}, err- }-- return PageContent{- URL: q.URL,- StatusCode: resp.StatusCode,- ContentType: resp.Header.Get("Content-Type"),- Body: strings.TrimSpace(markdown),- }, nil-}diff --git a/internal/localagent/browser/fetcher_test.go b/internal/localagent/browser/fetcher_test.godeleted file mode 100644index 674ceb5..0000000--- a/internal/localagent/browser/fetcher_test.go+++ /dev/null@@ -1,61 +0,0 @@-// Copyright 2026 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 browser--import (- "context"- "io"- "net/http"- "strings"- "testing"-)--type roundTripFunc func(*http.Request) (*http.Response, error)--func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) {- return f(req)-}--func newMockClient(fn roundTripFunc) *http.Client {- return &http.Client{Transport: fn}-}--func TestWebFetcherFetch(t *testing.T) {- client := newMockClient(func(r *http.Request) (*http.Response, error) {- if got, want := r.URL.String(), "https://example.test/path"; got != want {- t.Fatalf("url mismatch: got %q want %q", got, want)- }- return &http.Response{- StatusCode: http.StatusOK,- Body: io.NopCloser(strings.NewReader("<html><body>Hello world</body></html>")),- Header: http.Header{"Content-Type": []string{"text/html; charset=utf-8"}},- }, nil- })-- f := newWebFetcher(client)- page, err := f.Fetch(context.Background(), Query{URL: "https://example.test/path"})- if err != nil {- t.Fatalf("Fetch() error = %v", err)- }- if got, want := page.StatusCode, http.StatusOK; got != want {- t.Fatalf("status mismatch: got %d want %d", got, want)- }- if !strings.Contains(page.Body, "Hello world") {- t.Fatalf("body mismatch: %q", page.Body)- }- if strings.Contains(page.Body, "<") {- t.Fatalf("expected text-only body, got %q", page.Body)- }-}