Intro
“terminal” or “shell”) is a text-based consumer interface used to view, handle, and work together with the pc by typing particular instructions. CLI AI Brokers are the most recent step within the evolution of developer instruments. They mix the facility of LLMs with direct entry to a pc’s terminal, information, and exterior instruments. Simply think about utilizing the neatest AI fashions instantly in your terminal, with no need an online interface.
The discharge of ChatGPT in 2022 modified how folks interacted with software program, as customers may write pure language as an alternative of typing instructions. In 2023, the tech world had a significant breakthrough with the device calling operate launched by OpenAI. As a substitute of solely producing textual content, fashions may additionally carry out actions by sending structured requests to purposes, getting an output, and persevering with reasoning. Lastly, in 2025, Tremendous CLI arrived, the primary AI Agent explicitly constructed for working in your CLI with no net interface. Anthropic’s Claude Code and OpenAI’s Codex CLI adopted proper after.
CLI Brokers succeeded as a result of they match naturally into current developer workflows. As a substitute of changing the terminal, they increase it with reasoning. The CLI has developed from a spot the place people executed instructions right into a collaborative workspace the place customers outline objectives, and AI carries out a lot of the execution.
Right now, there are three kinds of CLI Brokers:
- Cloud-native (i.e. Claude Code): the mannequin runs within the cloud whereas the CLI securely accesses native instruments.
- Open-source (i.e. Hermes): the orchestration framework is open-source and might use native or distant fashions.
- Absolutely-local (i.e. Ollama): each mannequin and orchestration run by yourself machine.
On this tutorial, I’m going to point out how one can construct a fully-local CLI Agent with Python and Ollama. I’ll current some helpful code and stroll by means of each line of code with feedback as a way to replicate this instance.
Setup
Let’s begin by organising Ollama (pip set up ollama==0.6.2), essentially the most well-known library to run open-source LLMs regionally. Initially, it is advisable obtain Ollama from the web site. Then, in your CLI, use the command to obtain the chosen LLM. I’m going with Alibaba’s Qwen because it’s each good and light-weight.

After the obtain is accomplished, you may transfer on to Python and begin writing code.
import ollama
llm = "qwen2.5"
This Agent should have the ability to execute shell instructions on the CLI, so we have to present it with the suitable Device. First, we outline the operate that really performs the motion, then it should be mapped to Ollama schemas for device calling. For the CLI instructions, we’re going to want the subprocess module, a built-in library used to run system instructions instantly out of your Python code.
import subprocess
# 1. Outline the precise device operate
def execute_shell_command(command: str) -> str:
"""Executes a terminal command and returns stdout or stderr."""
strive:
end result = subprocess.run(command, shell=True, capture_output=True, textual content=True, timeout=10)
return end result.stdout if end result.returncode == 0 else end result.stderr
besides Exception as e:
return str(e)
# 2. Map device names to Python capabilities
TOOL_MAP = {
'execute_shell_command': execute_shell_command
}
# 3. Present schema representations for Ollama
TOOLS_SCHEMA = [
{
'type': 'function',
'function': {
'name': 'execute_shell_command',
'description': 'Execute safe terminal shell commands on the local machine.',
'parameters': {
'type': 'object',
'properties': {
'command': {
'type': 'string',
'description': 'The exact bash or shell command to run.',
}
},
'required': ['command'],
},
},
}
]
Agent
Within the interplay with a LLM chatbot, there are 3 kinds of roles:
- “position”:“system” — used to go core directions to the mannequin on how the dialog ought to proceed
- “position”:“consumer”— used for consumer’s questions
- “position”:“assistant” — it’s the reply from the mannequin
After we give the very first instruction to the mannequin, we’ve to specify that it’s the system immediate.
messages = [
{"role": "system", "content": "You are a helpful local CLI assistant. You can inspect the system and run tasks using your tools."}
]
In an effort to hold the chat with the AI alive, I’ll use a loop that begins with the consumer’s enter, after which invokes the Agent to reply (which generally is a textual content from the LLM or the activation of a Device).
import sys
whereas True:
strive:
user_input = enter("🙂 >")
if user_input.decrease() in ['exit', 'quit']:
break
if not user_input.strip():
proceed
messages.append({"position": "consumer", "content material": user_input})
# Request completion from Ollama with enabled instruments
response = ollama.chat(
mannequin=llm,
messages=messages,
instruments=TOOLS_SCHEMA
)
### WE WILL ADD CODE HERE ###
besides KeyboardInterrupt:
print("nExiting.")
sys.exit(0)
If the mannequin desires to make use of the Device, the suitable operate must be executed with the enter parameters recommended by the LLM in its response object.
import json
# Course of potential device calls requested by the mannequin
whereas response.get('message', {}).get('tool_calls'):
messages.append(response['message'])
for tool_call in response['message']['tool_calls']:
tool_name = tool_call['function']['name']
arguments = tool_call['function']['arguments']
print(f"🔧 >[Executing Tool] {tool_name}({json.dumps(arguments)})")
if tool_name in TOOL_MAP:
# Execute device and seize output string
tool_result = TOOL_MAP[tool_name](**arguments)
# Present device final result again to the mannequin context
messages.append({
"position": "device",
"identify": tool_name,
"content material": tool_result
})
else:
print(f"⚠️ >Unknown device execution tried: {tool_name}")
# Re-submit historical past together with device logs for closing analysis
response = ollama.chat(
mannequin=llm,
messages=messages,
instruments=TOOLS_SCHEMA
)
Because the CLI is a fragile device, within the final traces of code, I requested the mannequin to double test the dialog historical past and motion parameters, proper earlier than the ultimate reply.
# Show closing textual content reply to consumer
res = response['message']['content']
print(f"👽 >{res}n")
messages.append({"position": "assistant", "content material": res})
Run
We will run and work together with the CLI Agent. I saved the code in a py file, so I shall run it from the terminal (python CLIagent.py).
The mannequin interprets your natural-language request into shell instructions. For instance, it may examine your system: “How a lot disk area I’ve left?” (df -h), or “What’s my OS model?” (sw_vers), or “How a lot reminiscence is getting used? What processes are consuming my CPU?” (prime, ps).

Please observe that something phrased ambiguously round deletion or cleanup (“clear up my Downloads folder“) may do some actual harm, so watch out.
Conclusion
This text has been a tutorial to exhibit how one can construct your personal fully-local CLI Agent. Now that the fundamentals are clear, one may add logic and Instruments (i.e. Excel, Python) to make a extra advanced AI, identical to Hermes and Claude Code.
I hope you loved it! Be at liberty to contact me for questions and suggestions, or simply to share your fascinating initiatives.
👉 Let’s Join 👈

(All photos are by the writer until in any other case famous)















