A terminal LLM Q&A tool with multi-model support, role memory, and MCP tool integration.
Compared to traditional AI Agent frameworks, ask.py focuses on a lightweight, fast, and terminal-friendly design:
- Extremely Lightweight: No complex Agent framework required, low resource usage, fast response
- Terminal-First: Get answers with
ask "question", streaming output, seamlessly integrated into terminal workflows - Focused on Core Scenarios: Perfect for quick queries, code analysis, and error diagnosis in daily development
Enjoy a lightweight AI Q&A experience without starting heavy Agent frameworks.
- 🚀 Quick terminal Q&A - just
ask "question" - ⚡ Streaming output - real-time response display (enabled by default)
- 🔧 Multi-model configuration - supports any OpenAI-compatible API
- 🎭 Role system with custom System Prompts
- 🧠 Three-tier memory system (short/medium/long-term) with auto compression
- 🔌 MCP (Model Context Protocol) tool support
- 📁 File content analysis - supports
-fparameter to read files - 📊 Error log analysis - supports reading from stdin
- 🌍 Context awareness - auto-injects working directory, environment variables, etc.
# Using pipx (recommended)
pipx install ask-py-cli
# Or using uv tool
uv tool install ask-py-cliAfter installation, you can use it directly. Default configuration is auto-created on first run:
# Ask a question (using default public model)
ask "What is Python?"
⚠️ Important Notes:
- The default
public(glm-4-flash)model is for quick experience only, with IP-based rate limiting (dynamically adjusted)- For long-term use, configure your own API key to avoid rate limit restrictions
- Supports any OpenAI-compatible API: OpenAI, Azure OpenAI, DeepSeek, GLM, Ollama, etc.
ask model add openai \
-b https://api.openai.com/v1 \
-k $OPENAI_API_KEY \
-m gpt-4 \
--set-default# Ask a question
ask "What is quantum computing?"
# Use tool mode (time queries, shell commands, etc.)
ask -t "What time is it?"
ask -t "List files in /tmp"
ask -t "Organize video filenames in ~/Downloads"
# Create a role (with memory)
ask role add coder -s "You are a senior programmer" --set-default
ask "Write a quicksort"
ask "Convert it to iterative version" # Automatically remembers contextask [OPTIONS] "question"
Options:
-m, --model TEXT Specify model name
-s, --system TEXT Set temporary system prompt
-r, --role TEXT Use specified role
-t, --tools Enable MCP tools
--mcp NAME Specify MCP server (can be used multiple times)
--no-stream Disable streaming output (show complete result at once)
-f, --file TEXT Read file content and analyze
--stdin Read additional input from stdin (for error analysis, etc.)# Quick questions (streaming output, real-time display)
ask "What is Python's generator?"
ask "Explain RESTful API design principles"# Analyze single file
ask -f main.py "Explain this file's functionality"
ask "Optimize this code's performance" -f utils.py
# Analyze configuration files
ask -f docker-compose.yml "Check if configuration is correct"
ask -f package.json "Explain dependencies"# Analyze error logs
cat error.log | ask "Analyze this error" --stdin
python script.py 2>&1 | ask "Explain this error" --stdin
# Analyze application logs
tail -n 100 app.log | ask "Find performance bottlenecks" --stdin
journalctl -u myapp -n 50 | ask "Analyze service issues" --stdin# Use shell role for system management
ask role add shell -s "You are a system administrator assistant. When users ask about system-related questions (such as file operations, process management, system information queries, etc.), prioritize using shell commands to solve them rather than implementing with other programming languages." --set-default
ask "Find the directory with largest disk usage"
ask "List all listening ports" # Automatically remembers context
# System problem diagnosis
ask -r shell "Clean files older than 7 days in /tmp"
ask -r shell "Check system load and find the cause"# Use MCP tools
ask -t "What time is it?" # Query time
ask --mcp shell "List Python files in current directory"
# Combine usage
ask -f requirements.txt "Check dependency conflicts" --no-stream | tee analysis.txtask model add NAME -b API_BASE -k API_KEY [-m MODEL] [--set-default]
ask model list
ask model default NAME
ask model remove NAMEask role add NAME -s "prompt" [-m MODEL] [--set-default]
ask role list
ask role show NAME
ask role edit NAME -s "new prompt"
ask role default [NAME] # Set/clear default role
ask role remove NAME
ask role memory NAME # View memory
ask role clear-memory NAME --confirmConfigurations are stored in ~/.config/ask/:
~/.config/ask/
├── config.yaml # Model configuration
├── roles.yaml # Role configuration
├── mcp.json # MCP server configuration
└── memory/ # Memory storage
Default configuration is auto-created on first run:
default: public
lang: en # Language: en, zh-cn, zh-tw, ja (auto-detects from $LANG by default)
models:
public:
api_base: https://ask.appsvc.net/v1
api_key: <auto-generated key>
model: glm-4-flash
temperature: 0.7
⚠️ Important Notes:
- The
public(glm-4-flash)model is for quick experience only, with IP-based rate limiting (dynamically adjusted)- For long-term use, add your own model configuration with your own API key
- You can add multiple models and switch default model with
ask model default <name>
After adding your own models:
default: openai
default_role: shell
lang: en
models:
public:
api_base: https://ask.appsvc.net/v1
api_key: <auto-generated key>
model: glm-4-flash
temperature: 0.7
openai:
api_base: https://api.openai.com/v1
api_key: sk-xxx
model: gpt-4
temperature: 0.7Supported languages:
en- Englishzh-cn- Simplified Chinesezh-tw- Traditional Chineseja- Japanese
Language detection priority:
langsetting in config file- Environment variable
$LANG - Defaults to English
Streaming output is enabled by default, displaying responses in real-time:
ask "Explain quantum computing principles" # Real-time display, no need to wait for complete response
ask "Detailed explanation" --no-stream # Disable streaming, show complete result at onceAutomatically injects current environment information for more contextual responses:
- Current working directory
- Operating system and Python version
- Important environment variables (PATH, HOME, USER, SHELL, LANG, etc.)
No manual configuration needed, the system automatically identifies and adds to context.
Directly analyze code files, configuration files, etc.:
ask -f main.py "Explain this file"
ask "Optimize this code" -f utils.py
ask -f config.yaml "Check if configuration is correct"Read error information from standard input for analysis:
# Analyze error logs
cat error.log | ask "Analyze this error" --stdin
# Analyze recent logs
tail -n 100 app.log | ask "Find the cause of the problem" --stdin
# Analyze command output
python script.py 2>&1 | ask "Explain this error" --stdinRoles support three-tier hierarchical memory with automatic conversation history management:
| Tier | Description | Strategy |
|---|---|---|
| Short-term | Recent complete conversations | Keep 10 rounds |
| Medium-term | Earlier conversation summaries | LLM compressed |
| Long-term | Overall refined summary | Multiple summaries merged |
MCP (Model Context Protocol) enables LLM to call external tools.
⚠️ Note: Tool mode requires spawning external processes, which is slower. Use-tonly when needed.
Auto-created on first run at ~/.config/ask/mcp.json, automatically detects uvx or pipx:
{
"mcpServers": {
"time": {
"command": "uvx",
"args": ["mcp-server-time"]
},
"shell": {
"command": "uvx",
"args": ["mcp-shell-server"],
"env": {
"ALLOW_COMMANDS": "ls,cat,head,tail,find,grep,wc,pwd,echo,mkdir,cp,mv,touch,date,whoami,hostname,ps,du"
}
}
},
"enabled": ["time"]
}time: Query current time (enabled by default)shell: Execute system commands (restricted byALLOW_COMMANDS, not enabled by default)- Auto-detection: prefers
uvx, falls back topipx
⚠️ Note: Theshellserver is not enabled by default due to execution accuracy issues. To use it, specify manually with--mcp shell, or edit the config file to add"shell"toenabled.
{
"mcpServers": {
"time": { "command": "uvx", "args": ["mcp-server-time"] },
"filesystem": { "command": "npx", "args": ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"] },
"fetch": { "command": "uvx", "args": ["mcp-server-fetch"] }
},
"enabled": ["time", "filesystem"]
}MCP tools are invoked dynamically via
uvxornpx. Requires uv or Node.js.
ask mcp list # List servers
ask mcp tools shell # View shell tool details
ask -t "What time is it?" # Use default enabled tools (time)
ask -t "List files in /tmp" # Need to manually enable shell server
ask --mcp shell "List files in current directory" # Manually specify shell server
⚠️ Note: Theshellserver is not enabled by default due to execution accuracy issues. To use it, specify manually with--mcp shell, or edit the config file to enable it.
# ~/.config/ask/roles.yaml
shell:
system_prompt: "You are a system administrator assistant. When users ask about system-related questions (such as file operations, process management, system information queries, etc.), prioritize using shell commands to solve them rather than implementing with other programming languages."
mcp: ["shell"] # Enable shell server to execute commandsAny OpenAI-compatible API: OpenAI, Azure OpenAI, DeepSeek, GLM, Ollama, vLLM, LM Studio, etc.
# Clone and install
git clone https://github.com/tiancheng91/ask.py
cd ask.py
uv sync
# Run
uv run ask "question"
# Test
uv run pytest test_ask.py -v
# Build and publish
uv build
uv publishpipx install git+https://github.com/tiancheng91/ask.py
# Or
uv tool install git+https://github.com/tiancheng91/ask.py
# Or from PyPI
pipx install ask-py-cliMIT