Skip to main content

A provider-agnostic command-line agent and LLM framework.

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] Command
-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 / 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 code lang str override code generation language Option
-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 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

q_bot-2.0.0.dev3.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

q_bot-2.0.0.dev3-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file q_bot-2.0.0.dev3.tar.gz.

File metadata

  • Download URL: q_bot-2.0.0.dev3.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for q_bot-2.0.0.dev3.tar.gz
Algorithm Hash digest
SHA256 2ef743b555b90764f8734b5cfdf6122d46d093a8d9e4337e4a66aa60873e7b5d
MD5 fc14c45248c75ac322d629b835b7d396
BLAKE2b-256 bfe91021a321e1a870a4ed27b76c67250d55948d8df378d725015b0826114e32

See more details on using hashes here.

File details

Details for the file q_bot-2.0.0.dev3-py3-none-any.whl.

File metadata

  • Download URL: q_bot-2.0.0.dev3-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

Hashes for q_bot-2.0.0.dev3-py3-none-any.whl
Algorithm Hash digest
SHA256 7e10f4c8bc43868de974d4855da5b67b81525ede8b9e529fb5382a73ac71357b
MD5 f7a01058c28a9e65790510bc8883f636
BLAKE2b-256 767d8c6778371e8ec849629b46a0ff04519e8b2ee775d81434a7aa3e4f6b11b1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page