Argument Parsing and Help Text
Required vs optional args, type validation, and auto-generated help.
Good CLI Design Starts with Good Arguments
A well-designed CLI agent argument interface means users can figure out how to use the tool from --help alone. Every argument should have a clear name, type, default value, and description.
Poorly named or undocumented arguments make tools frustrating to use and hard to maintain.
Required vs. Optional Arguments
Required arguments must be provided — the CLI exits with an error if they are missing. Optional arguments have a default= value and can be omitted. Deciding which is which shapes your tool's UX.
import argparse
parser = argparse.ArgumentParser(description='AI Agent CLI')
# Required: no default, must be provided
parser.add_argument(
'--query', '-q',
type=str,
required=True,
help='Question to send to the agent'
)
# Optional: has a default, can be omitted
parser.add_argument(
'--model', '-m',
type=str,
default='gpt-4o-mini',
help='Model name (default: gpt-4o-mini)'
)
parser.add_argument(
'--max-tokens',
type=int,
default=1000,
help='Maximum tokens in response (default: 1000)'
)
args = parser.parse_args(['--query', 'test'])
print(args.query, args.model, args.max_tokens)All lessons in this course
- Building Command-Line Agent Interfaces
- Interactive REPL-Style Agents
- Argument Parsing and Help Text
- Streaming Output in CLI Agents