AI Agent Deployment: A Practical Guide to Online and Local Setups
This guide explains how to deploy AI Agents in online or local mode, covering environment preparation, cloud inference setup, private inference services, switching and rollback scripts, troubleshooting, and security governance. It helps you choose the right deployment path based on data sensitivity, hardware, and cost, and turn your configuration into a maintainable, reproducible engineering workflow.
1. Why Choose Between Online and Local Deployment
An AI Agent is essentially a combination of large model inference, tool calling, and context management. The deployment model you choose determines data flow, response speed, cost structure, and control boundaries. Online mode relies on cloud inference services, offering strong model capabilities without local compute requirements. Local mode runs inference on your own hardware, keeping data inside your network, which suits scenarios with strict compliance requirements. The two are not mutually exclusive; mature teams often maintain both paths and switch dynamically based on task sensitivity.
2. Environment Preparation and Verification
Whichever path you choose, fix the base runtime first to avoid later issues such as “command not found” or version mismatches.
- Runtime: Install Node.js 18 or later; an LTS version is recommended. The package manager installs with the runtime; version 10.x or later is recommended.
- Version control: On Windows, install Git for Windows for a Unix-like command-line experience.
- Terminal: PowerShell 7 or later is recommended for better compatibility.
- After installation, reopen the terminal so environment variables take effect.
A minimal set of commands is enough to verify the setup:
node --version # expect v20.xnpm --version # expect 10.xgit --version # expect 2.x
If all three return normally, the base layer is ready. If any command fails, first check whether the installation path contains spaces or non-English characters, and whether PATH is overridden by another runtime.
3. Online Mode: Connecting to Cloud Inference Services
Online mode centers on three elements: credentials, endpoint, and model identifier. To install the agent CLI toolkit, use a global install through the package manager:
npm install -g @agent/cli-toolkitclaude-like-agent --version
The first launch enters a guided setup that asks for access credentials or a model provider selection. Inject credentials through environment variables rather than writing them into project files:
$env:AGENT_API_KEY = "your-credential"$env:AGENT_BASE_URL = "https://your-endpoint.example"
Online mode needs no local GPU and handles long context and complex reasoning stably. The trade-off is network round trips and per-call cost, and code snippets leave your machine. When working with core repositories, key files, or customer data, switch to local mode.
4. Local Mode: Building a Private Inference Service
Local mode needs an inference backend compatible with an OpenAI-style API; a common choice is a local model runtime. After installation, confirm the service is listening on a local port such as 11434 and pull at least one model.
Match model selection to hardware, following the principle “VRAM first, parameter count second, quantization as fallback”:
| Hardware | Recommended Size | Notes |
|---|---|---|
| Dedicated GPU with 8GB+ | 7B–14B quantized | Good quality for code completion and rewriting |
| CPU only / low spec | 3B quantized | Fast response, suitable for completion tasks |
| Very low spec / integration testing | 1.5B quantized | Only verifies the pipeline works |
Pull and verify:
# Pull a model (example name; replace with an available model)ollama pull coder-model:7b# Verify the inference service respondscurl http://127.0.0.1:11434/api/generate -d '{"model":"coder-model:7b","prompt":"hello","stream":false}'
A JSON response containing generated text means the local inference pipeline is working.
5. Switching and Rollback: Making Configuration a Reusable Asset
Switching is essentially changing environment variables and configuration files. Maintain one script per mode to avoid manual mistakes:
# switch-local.ps1$env:AGENT_PROVIDER = "local"$env:AGENT_BASE_URL = "http://127.0.0.1:11434/v1"$env:AGENT_MODEL = "coder-model:7b"# switch-online.ps1$env:AGENT_PROVIDER = "cloud"$env:AGENT_BASE_URL = "https://your-endpoint.example"$env:AGENT_MODEL = "general-purpose-large"Remove-Item Env:AGENT_API_KEY -ErrorAction SilentlyContinue
When rolling back to an online model, do three things: restore the cloud endpoint, restore the model identifier, and re-inject credentials. If you use configuration files instead of environment variables, back up before overwriting and keep a “factory default” copy for quick restoration.
6. Common Issues and Troubleshooting Order
- Command not recognized: PATH has not taken effect; reopen the terminal or check the installation directory.
- Local model call timeout: the service is not running or the port is occupied; check the listening status first.
- Noticeable drop in output quality: the model is too small or over-quantized; switch to a larger model.
- Still using the cloud after switching: environment variables take precedence over configuration files; clear residual variables.
- First launch stuck on the setup page: credential format is wrong or the endpoint is unreachable; run a minimal request from the command line to verify connectivity.
7. Security and Governance Recommendations
- Keep credentials only in environment variables or a secrets management service; never commit them or write them to logs.
- Local mode is not absolutely secure; still restrict the inference service to listening on the loopback address.
- Set an allowlist and sandbox directory for Agent tool calls to avoid accidental file deletion.
- Establish a “sensitivity tier” policy: public code goes online, core code stays local.
- If you need elastic compute, consider general capabilities such as container platforms, object storage, and log monitoring from Baidu AI Cloud to host the inference service for scaling and observability.
8. Summary
Online and local deployment is not an either-or choice but a switchable engineering system. Solidify environment verification, credential management, model selection, switching scripts, and rollback plans, and an AI Agent can evolve from “just running” into a maintainable, governable, and reproducible productivity tool.
