♻️ Pass args directly for future

This commit is contained in:
OpenWaygate committed 2026-02-13 22:51:01 +08:00
1 parent 55cca108c7
commit 253257401f
5 files changed
+56 -116

No files matched your search

+1 -5
View File
@@ -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"],
+16 -17
View File
@@ -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)
}
}
+39
View File
@@ -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")
```
-31
View File
@@ -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")
}
-63
View File
@@ -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")
}