A Practical Guide to Online and Local Deployment of AI Agents
This guide explains how to deploy AI agents in both online (cloud-based) and local (self-hosted) modes. It covers runtime environment preparation, installing and verifying a CLI agent, configuring API credentials, deploying a local model based on hardware capacity, switching between modes through layered configuration, and security and maintenance best practices.
1. Overview and Use Cases
An AI agent is a software system that can understand task goals, call tools, read and write files, and iterate until the work is done. Developers typically use these tools from the command line, letting the agent read a codebase, propose changes, and run tests.
There are two common deployment modes:
- Online mode: The agent connects to a cloud-hosted LLM service. It requires a network connection, offers stronger model capability, and is billed per usage.
- Local mode: The model runs on the developer’s own machine. Data never leaves the device, which suits scenarios with strict code confidentiality requirements. However, it is constrained by local compute, so model sizes tend to be smaller.
The core difference between the two modes is where the model comes from. The agent’s installation, configuration, and usage are essentially the same in both cases. A sensible approach is therefore to first stabilize the runtime environment and the agent tooling, then choose the model source as needed. This article follows that order.
2. Environment Preparation
2.1 Runtime Environment
Most CLI agents are built on a JavaScript runtime, which must be installed first. The Long-Term Support (LTS) version is recommended because its interfaces are stable and suitable for long-term use.
Installation steps:
- Go to the official website of the runtime and download the LTS installer.
- Complete the default installation following the setup wizard.
- Close any open terminal windows and reopen them so the system environment variables take effect.
2.2 Package Manager
The runtime usually ships with a package manager for installing and updating third-party CLI tools. It is installed together with the runtime and requires no separate configuration. Keeping it on a recent stable version helps reduce dependency resolution issues.
2.3 Version Control Tool
Agents frequently need to read repository history and compare changes. On desktop operating systems, a version control tool also provides a Unix-like command-line environment, making script execution easier. If it is not already installed, install it first.
2.4 Environment Verification
After installation, verify each component’s version. The table below lists the checks and criteria:
| Component | Check Command | Criteria |
|---|---|---|
| Runtime | <runtime> --version |
Major version meets the official minimum requirement |
| Package manager | <package-manager> --version |
Outputs a version number normally |
| Version control tool | git --version |
Outputs a version number normally |
If a command reports that the program cannot be found, the environment variables have likely not taken effect. Restart the terminal or sign out and back in.
3. Installing and Verifying the CLI Agent
3.1 Global Installation
Using the package manager’s global install flag makes the tool callable from any directory:
# Refer to the official documentation for the exact package name<package-manager> install -g <agent-tool-package>
A global install writes the executable into the system path. If you hit permission errors during installation, adjust the permissions of the package manager’s global directory rather than running the install command with administrator privileges.
3.2 Verifying the Installation
<agent-command> --version
A printed version number indicates a successful installation. If the version prints correctly but the tool fails at runtime, the problem is usually in the configuration and should be checked in the next step.
3.3 First Launch and Authentication
On first launch, the tool typically walks the user through selecting a model service and completing authentication. In online mode, you need to request an API key from the service provider. The provider could be Baidu AI Cloud or any other cloud vendor; the integration approach is essentially the same.
When configuring API keys:
- Store keys in environment variables or a system key management tool — never in source code, config files, or version control.
- Grant keys the minimum required permissions and rotate them regularly.
- If you suspect a key has leaked, revoke it immediately in the provider’s console and generate a new one.
4. Deploying a Local Model
Local mode involves three steps: installing a local inference service, downloading a model, and pointing the agent at the local service.
4.1 Installing a Local Inference Service
The local inference service loads model files and exposes inference capabilities through an API. Download the installer from the project’s official channel, then confirm the service starts correctly after installation.
4.2 Choosing a Model Based on Hardware
Model size directly determines VRAM or memory usage. Prioritize your hardware constraints first, then consider model capability. Reference recommendations for common setups:
| Hardware | Recommended Model Size | Use Case |
|---|---|---|
| Dedicated GPU with 8GB+ VRAM | Medium-sized code-focused model | Day-to-day code completion, refactoring, and Q&A |
| No dedicated GPU or low-spec machine | 3B-parameter code-focused model | Simple code generation with acceptable response speed |
| Functional testing only | Models at 1.5B parameters or below | Validating the workflow; not recommended for real development |
Larger models generally understand code better but run inference more slowly. Developers should trade off speed against quality based on their actual tasks.
4.3 Downloading and Testing the Model
Use the inference service’s pull command to download a model:
<inference-service> pull <model-name>
After the download completes, send a simple test request to confirm the model returns results. If the response is empty or times out, check whether the service is running in the background and whether sufficient VRAM is available.
4.4 Connecting the Agent to the Local Service
The agent needs to know the local service’s address and the model name. This is commonly specified via a configuration file or environment variables. Exact variable names depend on the tool’s documentation. Example:
# Example configuration; field names depend on the actual tool's documentationprovider: local # Options: online or locallocal:base_url: http://127.0.0.1:<local-service-port>model: <local-model-name>online:base_url: <online-service-url>api_key_env: ONLINE_API_KEY # Read the key from an environment variable
After saving the configuration, restart the agent and run a simple code Q&A to confirm requests are actually routed to the local service.
5. Designing Mode Switching Between Online and Local
In real teams, developers often switch between the two modes — for example, using the online model for stronger capability on public projects, and switching to the local model when working with sensitive code.
The key to enabling this is layered configuration:
- Shared configuration: Tool behavior, working directory, ignore rules, etc., used by both modes.
- Mode configuration: Only the model service address, model name, and authentication method.
- Project-level overrides: Allow individual projects to specify a default mode, avoiding manual switching every time.
With this design, switching modes requires changing only a single field while everything else stays the same, reducing the chance of errors.
6. Security and Operations Recommendations
Local deployment does not automatically equal security. The following practices should be applied in daily use:
- Data boundaries: Clearly define which code may be sent to online services, and write this into team guidelines.
- Dependency updates: Regularly update the runtime, package manager, and agent tool to receive security fixes promptly.
- Resource monitoring: Local inference consumes significant VRAM and memory. Watch the load to avoid impacting other development tasks.
- Log management: Logs must not contain API keys or complete sensitive code snippets.
7. Conclusion
Online and local deployment each have their strengths. The key steps are: stabilize the runtime and package manager first, then install and authenticate the agent, select a local model based on hardware, and finally implement mode switching through a unified configuration. Following the workflow in this article, developers can flexibly leverage models of different scales while keeping their data secure.
