From 253257401f9bfff32efd6fbdb7e3e89148fdb295 Mon Sep 17 00:00:00 2001 From: OpenWaygate <27287694+OpenWaygate@users.noreply.github.com> Date: Fri, 13 Feb 2026 22:51:01 +0800 Subject: [PATCH] :recycle: Pass args directly for future --- cmd/agent/BUILD.bazel | 6 +--- cmd/agent/agent.go | 33 +++++++++-------- cmd/agent/commandline-syntax.md | 39 ++++++++++++++++++++ cmd/agent/console.go | 31 ---------------- cmd/agent/web.go | 63 --------------------------------- 5 files changed, 56 insertions(+), 116 deletions(-) create mode 100644 cmd/agent/commandline-syntax.md delete mode 100644 cmd/agent/console.go delete mode 100644 cmd/agent/web.go diff --git a/cmd/agent/BUILD.bazel b/cmd/agent/BUILD.bazel index 7cb5360..0ec7a9f 100644 --- a/cmd/agent/BUILD.bazel +++ b/cmd/agent/BUILD.bazel @@ -2,11 +2,7 @@ load("@rules_go//go:def.bzl", "go_library") go_library( name = "agent", - srcs = [ - "agent.go", - "console.go", - "web.go", - ], + srcs = ["agent.go"], embedsrcs = ["INSTRUCTION.md"], importpath = "github.com/eat-pray-ai/yutu/cmd/agent", visibility = ["//visibility:public"], diff --git a/cmd/agent/agent.go b/cmd/agent/agent.go index e10dab6..1eeef24 100644 --- a/cmd/agent/agent.go +++ b/cmd/agent/agent.go @@ -6,9 +6,11 @@ package agent import ( "context" _ "embed" + "fmt" + "io" "log/slog" "os" - "time" + "strings" rootCmd "github.com/eat-pray-ai/yutu/cmd" "github.com/modelcontextprotocol/go-sdk/mcp" @@ -32,16 +34,7 @@ var ( //go:embed INSTRUCTION.md instruction string - streamingMode string - idleTimeout time.Duration - port int - readTimeout time.Duration - writeTimeout time.Duration - sublaunchers []string - sseWriteTimeout time.Duration - webuiAddress string - a2aAgentURL string - apiServerAddress string + launcherArgs string ) var agentCmd = &cobra.Command{ @@ -55,15 +48,23 @@ var agentCmd = &cobra.Command{ } }, Run: func(cmd *cobra.Command, args []string) { - _ = cmd.Help() + if launcherArgs == "" { + _ = cmd.Help() + return + } + launch(cmd.Context(), cmd.OutOrStdout(), strings.Fields(launcherArgs)) }, } func init() { rootCmd.RootCmd.AddCommand(agentCmd) + agentCmd.Flags().StringVarP( + &launcherArgs, "args", "a", "", + "launcher arguments as a single string, e.g. 'console -streaming_mode sse'", + ) } -func launch(ctx context.Context, args []string) { +func launch(ctx context.Context, writer io.Writer, args []string) { m, err := gemini.NewModel( ctx, os.Getenv("YUTU_AGENT_MODEL"), &genai.ClientConfig{ APIKey: os.Getenv("YUTU_LLM_API_KEY"), @@ -109,10 +110,8 @@ func launch(ctx context.Context, args []string) { } l := full.NewLauncher() if err := l.Execute(ctx, config, args); err != nil { - slog.ErrorContext( - ctx, "failed to launch agent", - "launch", l.CommandLineSyntax(), "error", err, - ) + slog.ErrorContext(ctx, "failed to launch agent", "error", err) + _, _ = fmt.Fprintln(writer, l.CommandLineSyntax()) os.Exit(1) } } diff --git a/cmd/agent/commandline-syntax.md b/cmd/agent/commandline-syntax.md new file mode 100644 index 0000000..5cebc0b --- /dev/null +++ b/cmd/agent/commandline-syntax.md @@ -0,0 +1,39 @@ +```shell +Arguments: Specify one of the following: + * console - runs an agent in console mode. + * web - starts web server with additional sub-servers specified by sublaunchers +Details: + console + -streaming_mode string + defines streaming mode (none|sse) (default "sse") + + web + -idle-timeout duration + Server idle timeout (i.e. '10s', '2m' - see time.ParseDuration for details) - for waiting for the next request (only when keep-alive is enabled) (default 1m0s) + -port int + Localhost port for the server (default 8080) + -read-timeout duration + Server read timeout (i.e. '10s', '2m' - see time.ParseDuration for details) - for reading the whole request including body (default 15s) + -shutdown-timeout duration + Server shutdown timeout (i.e. '10s', '2m' - see time.ParseDuration for details) - for waiting for active requests to finish during shutdown (default 15s) + -write-timeout duration + Server write timeout (i.e. '10s', '2m' - see time.ParseDuration for details) - for writing the response after reading the headers & body (default 15s) + You may specify sublaunchers: + * api - starts ADK REST API server, accepting origins specified by webui_address (CORS) + * a2a - starts A2A server which handles jsonrpc requests on /a2a/invoke path + * webui - starts ADK Web UI server which provides UI for interacting with ADK REST API + Sublaunchers syntax: + api + -sse-write-timeout duration + SSE server write timeout (i.e. '10s', '2m' - see time.ParseDuration for details) - for writing the SSE response after reading the headers & body (default 2m0s) + -webui_address string + ADK WebUI address as seen from the user browser. It's used to allow CORS requests. Please specify only hostname and (optionally) port. (default "localhost:8080") + + a2a + -a2a_agent_url string + A2A host URL as advertised in the public agent card. It is used by A2A clients as a connection endpoint. (default "http://localhost:8080") + + webui + -api_server_address string + ADK REST API server address as seen from the user browser. Please specify the whole URL, i.e. 'http://localhost:8080/api'. (default "http://localhost:8080/api") +``` diff --git a/cmd/agent/console.go b/cmd/agent/console.go deleted file mode 100644 index dd43f8d..0000000 --- a/cmd/agent/console.go +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2026 eat-pray-ai & OpenWaygate -// SPDX-License-Identifier: Apache-2.0 - -package agent - -import ( - "github.com/spf13/cobra" -) - -const ( - consoleShort = "Start agent in console mode" - consoleLong = "Start agent in console mode" -) - -var consoleCmd = &cobra.Command{ - Use: "console", - Short: consoleShort, - Long: consoleLong, - Run: func(cmd *cobra.Command, args []string) { - launcherArgs := []string{"console"} - if streamingMode != "" { - launcherArgs = append(launcherArgs, "-streaming_mode", streamingMode) - } - launch(cmd.Context(), launcherArgs) - }, -} - -func init() { - agentCmd.AddCommand(consoleCmd) - consoleCmd.Flags().StringVarP(&streamingMode, "streamingMode", "m", "sse", "defines streaming mode: none|sse") -} diff --git a/cmd/agent/web.go b/cmd/agent/web.go deleted file mode 100644 index 14f65b3..0000000 --- a/cmd/agent/web.go +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2026 eat-pray-ai & OpenWaygate -// SPDX-License-Identifier: Apache-2.0 - -package agent - -import ( - "slices" - "strconv" - "time" - - "github.com/spf13/cobra" -) - -var webCmd = &cobra.Command{ - Use: "web", - Short: "Start agent in web mode", - Long: "start agent in web mode with additional sub-servers specified by sublaunchers", - Run: func(cmd *cobra.Command, args []string) { - launcherArgs := []string{"web"} - - launcherArgs = append(launcherArgs, "-idle-timeout", idleTimeout.String()) - launcherArgs = append(launcherArgs, "-port", strconv.Itoa(port)) - launcherArgs = append(launcherArgs, "-read-timeout", readTimeout.String()) - launcherArgs = append(launcherArgs, "-write-timeout", writeTimeout.String()) - - if slices.Contains(sublaunchers, "api") { - launcherArgs = append( - launcherArgs, "api", - "-sse-write-timeout", sseWriteTimeout.String(), - "-webui_address", webuiAddress, - ) - } - if slices.Contains(sublaunchers, "a2a") { - launcherArgs = append(launcherArgs, "a2a", "-a2a_agent_url", a2aAgentURL) - } - if slices.Contains(sublaunchers, "webui") { - launcherArgs = append(launcherArgs, "webui", "-api_server_address", apiServerAddress) - } - - launch(cmd.Context(), launcherArgs) - }, -} - -func init() { - agentCmd.AddCommand(webCmd) - - // web flags - webCmd.Flags().DurationVarP(&idleTimeout, "idleTimeout", "i", time.Minute, "Server idle timeout") - webCmd.Flags().IntVarP(&port, "port", "p", 8080, "Localhost port for the server") - webCmd.Flags().DurationVarP(&readTimeout, "readTimeout", "r", 15*time.Second, "Server read timeout") - webCmd.Flags().DurationVarP(&writeTimeout, "writeTimeout", "w", 15*time.Second, "Server write timeout") - webCmd.Flags().StringSliceVarP(&sublaunchers, "sublaunchers", "l", []string{"api"}, "One or more sublaunchers: api, a2a, and webui") - - // api flags - webCmd.Flags().DurationVarP(&sseWriteTimeout, "sseWriteTimeout", "s", 2*time.Minute, "SSE server write timeout") - webCmd.Flags().StringVarP(&webuiAddress, "webuiAddress", "W", "localhost:8080", "ADK WebUI address") - - // a2a flags - webCmd.Flags().StringVarP(&a2aAgentURL, "a2aAgentUrl", "u", "http://localhost:8080", "A2A host URL") - - // webui flags - webCmd.Flags().StringVarP(&apiServerAddress, "apiServerAddress", "U", "http://localhost:8080/api", "ADK REST API server address") -}