CLI vs Web: ADK Go Execution Modes Comparison and Selection
Table of Contents
CLI vs Web: ADK Go Execution Modes Comparison and Selection
ADK Go supports two execution modes: CLI interaction and Web interface. Both can run Agents, but suit different scenarios. This article helps you understand which to use when.
Execution Modes Overview
| Mode | Command | Applicable Scenario | Pros | Cons |
|---|---|---|---|---|
| CLI | go run agent.go | Debugging, automation scripts, production services | Lightweight, no dependencies, suitable for background | No interface |
| Web | go run agent.go web api webui | User testing, demos | Has interface, intuitive | Needs port open, not pure background |
CLI Mode
How to Start
source .env
go run agent.go
How It Works
User input → ADK Go CLI → Agent → Model → Tool → Return result → CLI output
In CLI mode, ADK Go’s launcher reads input from command line, processes it, outputs to stdout. This is a synchronous request-response loop.
Applicable Scenarios
Debugging and development phase
# Quick test new Tool
go run agent.go
> 查询北京天气
北京今天晴,气温 15-22°C
> 查询上海天气
上海今天多云,气温 18-26°C
Automation scripts
Can redirect CLI output to file:
echo "查询北京天气" | go run agent.go > output.txt
Production environment services
With nohup or systemd, create a long-running background service:
nohup go run agent.go > agent.log 2>&1 &
Web Mode
How to Start
go run agent.go web api webui
This command starts two services:
- API service:
localhost:8080, provides REST API - Web UI:
localhost:8080/webui, provides browser interface
How It Works
User browser → Web UI → API service → Agent → Model → Tool → Return → Web UI → User browser
Web mode is HTTP-based, provides stateful capability—can start a session, multi-turn conversations don’t need to re-enter context each time.
Applicable Scenarios
Demos and user testing
Send Web URL to colleagues or users, let them chat with Agent directly in browser, no installation needed.
Multi-turn conversation scenarios
CLI each time runs independently, historical messages don’t automatically carry to next round. Web mode keeps session context by default:
# Round 1
> 你好,我是助手
# Round 2 (Agent remembers last round)
> 我的名字叫什么?
(Agent remembers earlier "我是助手")
Session persistence scenarios
Web mode can store sessions to database or filesystem, resume after disconnection.
Switching Between Modes
ADK Go’s launcher determines mode based on os.Args[1:]:
l := full.NewLauncher()
l.Execute(ctx, config, os.Args[1:])
Common Command Parameters
| Parameter | Mode | Description |
|---|---|---|
| (none) | CLI | Default, starts interactive CLI |
web | Web API | API only, no UI |
web api webui | Web Full | API + Web UI |
stream | Streaming | Enables streaming output |
Switching via Code
More flexible way: switch based on environment variables:
func main() {
mode := os.Getenv("ADK_MODE")
switch mode {
case "web":
runWeb()
default:
runCLI()
}
}
Then at runtime:
ADK_MODE=web go run agent.go
Selection Guide
| Scenario | Recommended Mode | Reason |
|---|---|---|
| Local debugging | CLI | Fast, simple, logs visible directly |
| Automation scripts | CLI | Stateless, suitable for pipeline processing |
| Background services | CLI + systemd | Stable, manageable |
| User demos | Web | Has interface, zero barrier |
| Multi-turn conversation | Web | Keeps context by default |
| Session persistence | Web | Supports session storage |
Notes
ADK Web is for development only
Official docs emphasize: ADK Web is development-only, don’t use in production. Production should use Agent Runtime deployment (covered in Module 7).
Port conflicts
Port 8080 may be occupied. Specify another port:
go run agent.go web api webui --port 9090
Network access restrictions
Web mode listens to localhost by default. If needing access from other machines:
go run agent.go web api webui --host 0.0.0.0
Next Steps
Both execution modes clear. Next, learn about API Key acquisition and management, plus selection strategies between different models.
← Hello World Agent | API Key & Model Selection →
Follow “Mengshou Programming” on WeChat for more Go ADK hands-on tutorials, weekly updates on Go / AI programming 实战干货.
