Skip to main content

A terminal-based agent for interacting with Qwen3-Coder models

Project description

Qwen3-Coder Terminal Agent

A powerful terminal interface for interacting with the Qwen3-Coder model, featuring secure API key management, hybrid token counting, and intelligent rate limiting.

Features

  • Hybrid Token Counting: Combines local estimation with API validation for accurate token counting
  • Secure API Key Management: Environment-based configuration with secure storage
  • Adaptive Rate Limiting: Intelligent handling of rate limits with predictive throttling
  • Context Management: Dynamic windowing for large conversations
  • Terminal UX: Clean interface with real-time token usage
  • Session Persistence: Save and load conversation history

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/qwen3-coder-terminal.git
    cd qwen3-coder-terminal
    
  2. Create and activate a virtual environment (recommended):

    python -m venv venv
    # On Windows:
    venv\Scripts\activate
    # On macOS/Linux:
    source venv/bin/activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Create a .env file with your API configuration:

    QWEN_API_KEY=your_api_key_here
    QWEN_API_BASE=https://api.qwen.com/v1  # Default value, update if different
    MAX_CONTEXT_TOKENS=4000  # Adjust based on your model's context window
    

Usage

Start the terminal interface:

python -m qwen3_coder.cli

Available Commands

Chat Commands

  • Just type your message and press Enter to chat with Qwen3-Coder
  • Multi-line input is supported (press Shift+Enter for new lines, Enter to send)

System Commands

  • /help or ? - Show help message with available commands
  • /exit or /q - Exit the application
  • /clear - Clear the current conversation
  • /tokens or /t - Show token usage statistics

Session Management

  • /save [name] or /s [name] - Save current conversation
  • /load <id> or /l <id> - Load a saved session
  • /sessions or /ls - List all saved sessions

Configuration

The following environment variables can be set in the .env file:

  • QWEN_API_KEY: Your Qwen API key (required)
  • QWEN_API_BASE: Base URL for the Qwen API (default: https://api.qwen.com/v1)
  • MAX_CONTEXT_TOKENS: Maximum number of tokens to keep in context (default: 4000)

Examples

Starting a new conversation

qwen3> Hello! How can I help you today?

Saving a session

qwen3> /save my_first_session
Session saved as: my_first_session

Loading a session

qwen3> /load my_first_session
Session loaded: my_first_session

Development

Running Tests

pytest tests/

Code Style

This project uses black for code formatting and flake8 for linting.

black .
flake8

License

MIT License - see the LICENSE file for details.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

  • /save [name] - Save current session
  • /load <name> - Load a saved session
  • /model [name] - Get or set the current model
  • /debug - Toggle debug mode
  • /new - Start a new session
  • /system <msg> - Add a system message
  • /settings - Show current settings
  • /exit or /quit - Exit the program

Configuration

Edit the .env file to customize settings:

# API Configuration
QWEN_API_KEY=your_api_key_here
API_BASE_URL=https://api.qwen.ai/v1/chat/completions

# Rate Limiting
MAX_RETRIES=3
INITIAL_RETRY_DELAY=1
MAX_RETRY_DELAY=10

# Token Management
MAX_TOKENS=4096
MAX_CONTEXT_TOKENS=32000
WARNING_THRESHOLD=0.8

Security

  • API keys are never logged or stored in plaintext
  • Environment variables are used for configuration
  • Secure credential storage options available via keyring
  • All API calls use HTTPS

Development

  1. Install development dependencies:

    pip install -r requirements-dev.txt
    
  2. Run tests:

    pytest
    
  3. Format code:

    black .
    isort .
    

License

MIT

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Acknowledgements

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

qwen3_coder_agent-0.1.0.tar.gz (44.3 kB view details)

Uploaded Source

Built Distribution

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

qwen3_coder_agent-0.1.0-py3-none-any.whl (34.4 kB view details)

Uploaded Python 3

File details

Details for the file qwen3_coder_agent-0.1.0.tar.gz.

File metadata

  • Download URL: qwen3_coder_agent-0.1.0.tar.gz
  • Upload date:
  • Size: 44.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for qwen3_coder_agent-0.1.0.tar.gz
Algorithm Hash digest
SHA256 29878a8c268275892ae0af554a35f7217d64c7e820c94ca89b7403dd7fbf8f27
MD5 e165f09ffbbcce38cf8c1e832f4b88c9
BLAKE2b-256 fc584aebb223c8ee79bf649f87c894fd71a1bebd4599550e632ce192c48f246c

See more details on using hashes here.

File details

Details for the file qwen3_coder_agent-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for qwen3_coder_agent-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ecac2761d805b2cacb70e15ba711b65ce5f83c20c8a38da7dee226755e4f897
MD5 94e1be62eab0233b274d85b76089360f
BLAKE2b-256 85ba175ce80b2b6d4fe92ce92ba2022f5b173ae01c71832d3c9edf2d533ffe56

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