An LLM agent from the comfort of your command line
Project description
Overview
q is a provider-agnostic command-line agent and LLM framework.
I originally built this as a personal CLI tool before Claude Code existed. I still find it more useful for quick shell interactions and running multi-model experiments.
Installation
Install using any pip-compatible package manager (e.g. pip, pipx, uv, etc.):
pipx install q-bot
Requires Python 3.12+.
CLI Usage
q uses a simple paradigm where each character from a-z is mapped to a single flag representing a command or option. This enables concise combinations of flags to achieve complex behavior.
Flag Reference
| Flag | Name | Arg | Description | Type |
|---|---|---|---|---|
-a |
agent | [reserved for future use] | Command | |
-b |
batch | [reserved for future use] | ||
-c |
code | str | generate code | Command |
-d |
directory | - / str | add a directory to context | Option |
-e |
explain | - / str | explain code or text | Command |
-f |
file | str | read input from file | Option |
-g |
||||
-h |
help | - / str | help message / help agent | Command |
-i |
image | str | generate/edit an image | Command |
-j |
json | - | output as JSON | Option |
-k |
api key | str | override API key | Option |
-l |
||||
-m |
model | str | override model/provider | Option |
-n |
new session | - | clear the session history | Option |
-o |
output | str | output file | Option |
-p |
||||
-q |
||||
-r |
rag | - / str | [reserved for future use] | Command |
-s |
shell | - / str | generate a shell command | Command |
-t |
text | str | generate text | Command |
-u |
user command | str | [reserved for future use] | Command |
-v |
verbose | - | debug logging | Option |
-w |
web search | str | search the web | Command |
-x |
execute | - | execute a shell command | Option |
-y |
||||
-z |
undo | - / int | undo exchanges (default 1) | Option |
Sessions
Each terminal or script that runs q maintains an isolated session that persists conversation history across calls. Use -n to clear the session history for a new conversation or one-shot prompt. Sessions are automatically deleted when the parent shell process exits.
Library Usage
The q library is built on two principles:
Clients are single-capability. Each client does one thing (e.g. text generation, image generation, web search, etc.) and has a static return type. No mode switching or tool selection logic is necessary.
Agents are provider- and capability-agnostic. Every agent accepts any client and inherits its return type, regardless of what the underlying client does or which provider it calls.
Clients
A client wraps a provider's API for one capability.
Clients extend Client[T] and are instantiated with an API key, model name, and optionally provider- and model-specific argument overrides. All clients expose the same generate method which returns a value of type T:
Client[T](api_key: str, model: str, **model_args)
Client[T].generate(messages: list[Message]) -> T
A number of built-in clients with sensible defaults are provided for the following providers and capabilities:
| Client | T | Description | openai |
anthropic |
|---|---|---|---|---|
TextClient |
str |
text generation | ✓ | ✓ |
WebClient |
str |
web-grounded text generation | ✓ | ✗ |
ImageClient |
bytes |
image generation | ✓ | ✗ |
Dynamic Loading
Client classes are typically imported from their provider module:
from q.providers.openai import ImageClient
client = ImageClient(api_key, model, **model_args)
They can also be dynamically loaded at runtime by specifying a provider and capability using the load_client_class utility:
from q.providers import load_client_class
client_class = load_client_class('openai', 'ImageClient')
client = client_class(api_key, model, **model_args)
Agents
An agent manages conversation state and delegates generation to a client.
ChatAgent[T] maintains a message history and prepends an optional system prompt:
ChatAgent[T](client: Client[T], system: str | None = None)
ChatAgent[T].prompt(text: str) -> T
BatchAgent[T] processes multiple inputs concurrently using a shared system prompt, with no conversation history:
BatchAgent[T](client: Client[T], system: str | None = None)
BatchAgent[T].batch_prompt(text_list: list[str], n_threads: int = 8) -> list[T]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file q_bot-2.0.0.dev2.tar.gz.
File metadata
- Download URL: q_bot-2.0.0.dev2.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03a6260fc9c2e3a88904b79ef4861e6d73787cb8822f7b844189725ebf57c527
|
|
| MD5 |
d150b2267b527631d2b7b4d9130b9035
|
|
| BLAKE2b-256 |
95a74d61eecee2531397345cb625d4ae73e8d379fa14941c44c4fbf7e380f93c
|
File details
Details for the file q_bot-2.0.0.dev2-py3-none-any.whl.
File metadata
- Download URL: q_bot-2.0.0.dev2-py3-none-any.whl
- Upload date:
- Size: 18.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34b2d2deeed2436157396ca2884a6afca78848f997fe9b8d3dc0a3f2965a0523
|
|
| MD5 |
52ccd349fcaf48d8ad5fb12f5b31a414
|
|
| BLAKE2b-256 |
676803a702be5338159e82c4e3756a4f1e9ed0d1f1e0249e79373ef0e96b23c4
|