CLI tools

User writes a prompt

in natural language rather than a command

Agent decides to use

Choose the tool and understand the usage

Context enhancement

Precise information or action goes into the generation

Introduction

CLI tools for AI turn the command line into a direct interface between large language models (LLMs) and your local environment. Rather than relying solely on the probabilistic nature of LLMs, a more reliable approach is to invoke deterministic CLI tools to compute exact results and feed those outputs back into the model for summarization. For example, even the most capable LLMs can make arithmetic mistakes; giving the model a calculator tool guarantees accurate computation.

CLI tools also protect sensitive operations that require credentials, such as payment processing or database administration. Exposing passwords or API keys directly in a prompt is risky, as that context could be logged or exposed. By embedding secrets inside local programs or environment variables, the AI can trigger the authorized action without ever seeing the underlying credentials.

To be usable by an AI agent, these tools must be accessible in the local environment, either placed on the system PATH (such as /usr/local/bin) or located directly inside the agent's working directory. Finally, each tool should be self-documenting (for example, via a clear --help manual) so the AI agent can inspect its usage, understand its arguments, and invoke it accurately.

Interaction model

Note that even though the CLI tools are availiable, it is the AI's decisions whether to use the tools or not.

Scaffold code

argparse module is able to parse the arguments from CLI with self-explaination feature.

cli_tool_template.py
python
import argparse

def main():
    parser = argparse.ArgumentParser(
        description="What this tool is for or does.",
    )
    parser.add_argument(
        "var",  # positional argument
        help="A variable without dashes. It is required by default.",
    )
    parser.add_argument(
        "-v", "--variable",  # option that takes a value
        help="The help text for this option",
    )
    parser.add_argument(
        "-t", "--tariable",  # option with more customizes
        default=0,  # default value
        required=False,  # True or False
        help="The help text for this option",
    )
    args = parser.parse_args()
    
    # ... your logic here ...

if __name__ == "__main__":
    main()

For more details, please read the argparse documentation on Python website.

Code example

Type a prompt in natural language and then inspect the internal process.

temp_convert.py
python
#!/usr/bin/env python3
"""Convert a temperature between Celsius and Fahrenheit."""

import argparse

def main():
    parser = argparse.ArgumentParser(
        description="Convert a temperature between Celsius and Fahrenheit.",
        epilog="example: python temp_convert.py 100 --to fahrenheit",
    )
    parser.add_argument("value", type=float, help="The temperature to convert")
    parser.add_argument(
        "--to",
        choices=["celsius", "fahrenheit"],
        required=True,
        help="Unit to convert into",
    )
    args = parser.parse_args()

    if args.to == "fahrenheit":
        result = args.value * 9 / 5 + 32
    else:
        result = (args.value - 32) * 5 / 9

    print(f"{result:.1f}")

if __name__ == "__main__":
    main()
You prompt in natural language
User
Convert 100F to C
What is 0 degrees Celsius in Fahrenheit?
Convert 37.5 C to F
The model reads the manual of the tool to know how to use it
Model
The model writes the command
Model
The command is run locally
Tool
The generated answer comes back to you
Model