AI Agent Deployment: A Practical Guide to Cloud-Hosted and Local Setups
This guide compares cloud-hosted and local AI Agent deployments, outlines the required dependencies, and walks through installing Aider, connecting to OpenAI-compatible cloud models or local Ollama models such as Qwen2.5-Coder, switching between cloud and local configurations, and verifying each setup. It also covers common troubleshooting points, including API key security, offline usage, slow local inference, and cases where the agent may still be pointing to a cloud endpoint.
1. How to Choose Between Cloud-Hosted and Local AI Agents?
An AI Agent is an intelligent program that can understand natural-language instructions, call tools, and complete multi-step tasks. When deploying an AI Agent, there are two common options: a cloud-hosted online version and a local private version.
- Cloud-hosted online version: The Agent connects to a cloud model service. It is suitable for fast setup, elastic compute, and environments without a local GPU.
- Local private version: The Agent connects to a local model inference service. Data stays on the local machine, making it suitable for compliance-sensitive scenarios, offline environments, and restricted internal networks.
How to Choose Between the Online Version and the Local Version
You can make a decision based on the following four dimensions:
- Compliance requirements: If the work involves sensitive code, customer data, or internal materials, prefer the local version.
- Network conditions: If external APIs cannot be accessed reliably, prefer the local version.
- Hardware conditions: If there is no discrete GPU or memory is limited, prefer the online version.
- Cost structure: For short-term validation, use the online version. For long-term, high-frequency use where suitable hardware is already available, consider the local version. Note that the local version is not necessarily lower cost; it should also account for hardware amortization, electricity, operations, and model upgrade costs.
2. What Dependencies Are Needed Before Deployment?
The following technology stack is used as a real, executable example:
- Script runtime: Python 3.11
- Package manager: pip
- Version control tool: Git
- Agent client: Aider
- Cloud model service: OpenAI-compatible API
- Local model service: Ollama
- Example local model: Qwen2.5-Coder
Dependency and Verification Table
| Dependency | Recommended version | Purpose | Verification command |
|---|---|---|---|
| Python | 3.11 or later | Run Aider | python3 --version |
| pip | Included with Python | Install Aider | python3 -m pip --version |
| Git | 2.40 or later | Code repository operations | git --version |
| Aider | Latest stable version | Agent client | aider --version |
| Ollama | Latest stable version | Local model inference service | ollama --version |
Recommended verification output looks similar to this:
python3 --version# Python 3.11.9python3 -m pip --version# pip 24.0 from ...git --version# git version 2.45.2
If aider --version reports that the command cannot be found after installation, this usually means the environment variables have not taken effect. Please reopen the terminal and check the Python and pip installation paths.
3. Install and Verify the Agent Client
After the dependencies are ready, install Aider with pip:
python3 -m pip install --upgrade pippython3 -m pip install aider-chat
After installation, verify it with:
aider --version
If the output looks like aider 0.xx.x, the client has been installed successfully. Aider is a command-line intelligent programming tool. You can use it inside a project directory to call models for code understanding, modification, and generation tasks.
4. How to Configure the Cloud-Hosted Online Version?
The cloud-hosted online version requires configuring the model service address and access credentials. Using an OpenAI-compatible API as an example:
export OPENAI_API_KEY="sk-your-real-key"
Then start the cloud model:
aider --model gpt-4o-mini
You can also verify whether the cloud credentials are available:
curl -s https://api.openai.com/v1/models \-H "Authorization: Bearer $OPENAI_API_KEY" | head -n 20
If a JSON model list is returned, the credentials and network connectivity are working normally. If an authentication error is returned, check whether the key has expired, whether quota is sufficient, and whether the environment variables have taken effect.
Note: An API key is sensitive information. Do not hardcode it in source code, and do not commit it to a Git repository. For production environments, use environment variables, a secrets management service, or encrypted variables in CI/CD.
5. How to Set Up the Local Private Version?
The local version requires running a model inference service on the machine first. This guide uses Ollama as the local inference service.
1. Start Ollama
After installing Ollama, start the service:
ollama serve
Verify whether the service has started:
ollama --versioncurl -s http://localhost:11434/api/tags
If a JSON model list is returned, Ollama is running normally.
2. Pull a Local Model
Using Qwen2.5-Coder as an example:
ollama pull qwen2.5-coder:7b
For lower-spec devices, you can pull a smaller model:
ollama pull qwen2.5-coder:1.5b
After pulling, you can view model details:
ollama show qwen2.5-coder:7b
3. Choose a Model Size Based on Hardware
Model parameter size affects VRAM, memory, and inference speed. When selecting a model, you should not only look at the “number of B”; you should also consider quantization precision and context length. Ollama usually uses quantized models by default, but usage can vary depending on the model and version.
| Hardware condition | Recommended model | Notes |
|---|---|---|
| Discrete GPU with about 8GB VRAM | qwen2.5-coder:7b |
Suitable for lightweight code completion and small to medium tasks; long context increases usage |
| 12GB to 16GB VRAM | qwen2.5-coder:7b or qwen2.5-coder:14b |
You can try a larger model, but monitor actual VRAM usage |
| CPU-only or low-spec device | qwen2.5-coder:1.5b |
The main goal is to get the workflow running; response quality is limited |
| Functional validation only | qwen2.5-coder:0.5b |
Suitable for validating the workflow; not recommended for real development |
General selection principle: first ensure the workflow can run end to end, then gradually upgrade the model based on available hardware headroom. If local inference is slow, first reduce the model size or shorten the context length.
6. How to Point the Agent to a Local Model
The key difference between the local version and the cloud version is the model service endpoint. Using Aider as an example, you can set an OpenAI-compatible endpoint to point to local Ollama:
export OPENAI_API_BASE="http://localhost:11434/v1"export OPENAI_API_KEY="ollama"
Then start the local model:
aider --model ollama/qwen2.5-coder:7b
After switching, you can verify the configuration:
echo "Current endpoint: $OPENAI_API_BASE"curl -s http://localhost:11434/v1/models
If the result contains qwen2.5-coder:7b, Aider is pointing to the local model. At this point, inference requests are sent to the local localhost, and data no longer leaves the machine.
Note that some Agent tools may use configuration files instead of environment variables. For example, Aider can read ~/.aider.conf.yml or a configuration file in the project directory. Therefore, clearing environment variables may not reset all configurations. Before switching, you can check:
grep -R "openai-api-base" ~/.aider.conf.yml .aider.conf.yml 2>/dev/null || true
7. How to Switch Between Online and Local and Restore Settings?
During real development, you often need to switch between “local development” and “cloud enhancement.” It is recommended to maintain two sets of configuration scripts.
online.env
export OPENAI_API_KEY="sk-your-real-key"unset OPENAI_API_BASE
local.env
export OPENAI_API_BASE="http://localhost:11434/v1"export OPENAI_API_KEY="ollama"
When using them, load the corresponding configuration:
source online.envaider --model gpt-4o-mini
Or:
source local.envaider --model ollama/qwen2.5-coder:7b
After switching, it is recommended to run a verification:
echo "Current endpoint: $OPENAI_API_BASE"
If the current endpoint is empty, this usually means you have switched back to the cloud. If it outputs http://localhost:11434/v1, the local service is currently being used.
8. Common Issues and Troubleshooting Suggestions
How to Choose Between the Online Version and the Local Version?
If data is sensitive, network access is restricted, or offline operation is required, choose the local version. If you need stronger model capabilities, faster startup, and do not have local hardware, choose the online version.
Can the Local Version Run Completely Offline?
Yes. The prerequisite is that the model has already been downloaded and the Agent’s model endpoint points to the local service. In offline environments, avoid calling external APIs and check configuration files and scripts for any remaining cloud addresses.
What Should You Do if an API Key Is Leaked?
Immediately revoke or rotate the key in the service platform, check whether code repositories and logs contain the key, and switch to environment variables or a secrets management service.
What Should You Do if Local Inference Is Too Slow?
Reduce the model size, for example by switching from qwen2.5-coder:7b to qwen2.5-coder:1.5b. You can also reduce the context length, disable unnecessary tool calls, or upgrade the hardware.
What If It Still Calls the Cloud Model After Switching?
Check three types of configuration: environment variables, Agent configuration files, and project-local configuration files. Different tools have different priorities, so you must confirm the currently effective endpoint item by item.
9. Conclusion
AI Agent deployment can be summarized as “client + model service.” The online version places the model in the cloud and emphasizes capability, convenience, and elasticity. The local version places the model on the local machine and emphasizes privacy, autonomy, and offline availability.
Using Python, Aider, Ollama, and Qwen2.5-Coder as examples, this guide covers the complete practical path from dependency preparation and client installation to cloud integration, local model setup, endpoint switching, and verification. As long as you understand the model endpoint, credential configuration, and post-switch verification methods, you can quickly deploy and switch AI Agents based on hardware, compliance, and cost requirements.
