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, recordsdata, and exterior instruments. Simply think about utilizing the neatest AI fashions instantly in your terminal, while not having an online interface.
The discharge of ChatGPT in 2022 modified how folks interacted with software program, as customers might write pure language as an alternative of typing instructions. In 2023, the tech world had a serious breakthrough with the software calling perform launched by OpenAI. As a substitute of solely producing textual content, fashions might additionally carry out actions by sending structured requests to functions, getting an output, and persevering with reasoning. Lastly, in 2025, Tremendous CLI arrived, the primary AI Agent explicitly constructed for operating in your CLI with no internet 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 advanced 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 this moment, there are three forms 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 may use native or distant fashions.
- Totally-local (i.e. Ollama): each mannequin and orchestration run by yourself machine.
On this tutorial, I’m going to point out the right way to construct a fully-local CLI Agent with Python and Ollama. I’ll current some helpful code and stroll by each line of code with feedback with the intention to replicate this instance.
Setup
Let’s begin by establishing Ollama (pip set up ollama==0.6.2), probably the most well-known library to run open-source LLMs domestically. To start with, you might want to 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 sensible and lightweight.

After the obtain is accomplished, you’ll be able to 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 perform that really performs the motion, then it should be mapped to Ollama schemas for software 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 software perform
def execute_shell_command(command: str) -> str:
"""Executes a terminal command and returns stdout or stderr."""
strive:
outcome = subprocess.run(command, shell=True, capture_output=True, textual content=True, timeout=10)
return outcome.stdout if outcome.returncode == 0 else outcome.stderr
besides Exception as e:
return str(e)
# 2. Map software 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 forms 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
Once we give the very first instruction to the mannequin, we’ve got 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."}
]
So as 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 is usually 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 needs to make use of the Device, the suitable perform must be executed with the enter parameters instructed by the LLM in its response object.
import json
# Course of potential software 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 software and seize output string
tool_result = TOOL_MAP[tool_name](**arguments)
# Present software consequence again to the mannequin context
messages.append({
"position": "software",
"title": tool_name,
"content material": tool_result
})
else:
print(f"⚠️ >Unknown software execution tried: {tool_name}")
# Re-submit historical past together with software logs for ultimate analysis
response = ollama.chat(
mannequin=llm,
messages=messages,
instruments=TOOLS_SCHEMA
)
For the reason that CLI is a fragile software, 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 ultimate textual content reply to consumer
res = response['message']['content']
print(f"👽 >{res}n")
messages.append({"position": "assistant", "content material": res})
Run
We are able to 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 might examine your system: “How a lot disk house 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?” (high, ps).

Please word that something phrased ambiguously round deletion or cleanup (“clear up my Downloads folder“) might do some actual injury, so watch out.
Conclusion
This text has been a tutorial to show the right way to construct your personal fully-local CLI Agent. Now that the fundamentals are clear, one might 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 happy to contact me for questions and suggestions, or simply to share your fascinating initiatives.
👉 Let’s Join 👈

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





