Skip to main content

A production-grade Python runtime for Antigravity CLI

Project description

agy-connect banner

agy-connect

Python Version License PyPI

A Python library that lets you use Antigravity CLI from Python with a clean API for chat, streaming, and session management.

Why agy-connect?

Instead of managing subprocesses, stdin/stdout, session recovery, streaming, and conversation state yourself, agy-connect provides a clean Python API so you can focus on building applications.

The biggest advantage: You get programmatic access to state-of-the-art LLMs entirely for free through your local Antigravity CLI, without paying for API keys!

Supported Models

Since agy-connect securely piggybacks off your local CLI, it supports all native Antigravity models:

  • Gemini 3.5 Flash (Low, Medium, High)
  • Gemini 3.1 Pro (Low, High)
  • Claude Sonnet 4.6 (Thinking)
  • Claude Opus 4.6 (Thinking)
  • GPT-OSS 120B (Medium)

Note: agy-connect uses whichever model is currently selected in your CLI. To change the model, simply open your terminal, run agy, type /model to select your desired LLM, and then restart your Python application.

Key Features

  • Zero API Key Requirement: Use premium models natively without API costs.
  • Native Context Memory: Preserves perfect conversation memory across requests.
  • Real-time Streaming: Fetch tokens instantly using async generators (chat.stream()).
  • Session Management: Built-in SessionManager utilizes LRU caching to manage hundreds of simultaneous chats efficiently.
  • Robust Process Management: Handles batch processing intelligently with auto-recovery.
  • Dual API Support: Complete support for both highly scalable asyncio applications and simple synchronous scripts.

What can you build?

  • ✓ Terminal chatbots
  • ✓ FastAPI / Flask backends
  • ✓ Discord / Slack bots
  • ✓ Desktop assistants
  • ✓ Automation agents
  • ✓ CLI applications

Installation

To install agy-connect, use pip:

pip install agy-connect

Prerequisites: You must have the Antigravity CLI installed on your system.

Verify Installation

After installation, you can easily verify that everything works:

python -c "from agy_connect import Chat; print(Chat().status())"

If agy is installed and authenticated correctly, you should see a status such as READY.

Supported Platforms

  • Windows
  • Linux
  • macOS

Requires Python 3.9+


Usage & Quick Start

1. Synchronous Chatbot (Simple Scripts)

The Chat class provides an easy-to-use, blocking interface perfect for automation scripts.

from agy_connect import Chat

def main():
    chat = Chat()
    print("User: Hello!")
    
    # Send a prompt and wait for the complete response
    response = chat.send("Hello!")
    print(f"Agy: {response}")
    
    # Context memory is naturally maintained!
    response2 = chat.send("What did I just say?")
    print(f"Agy: {response2}")
    
if __name__ == "__main__":
    main()

2. Streaming Responses

If you want to render text back to a user in real-time (like ChatGPT):

import sys
from agy_connect import Chat

chat = Chat()

print("Agy: ", end="")
for chunk in chat.stream("Write a short poem about code."):
    sys.stdout.write(chunk)
    sys.stdout.flush()
print()

3. Asynchronous APIs (FastAPI / Web Servers)

For high-performance non-blocking code, use the SessionManager.

import asyncio
from agy_connect import SessionManager, Config

async def run_server():
    # Configure session limits and timeouts
    config = Config(max_sessions=10, idle_timeout=300)
    manager = SessionManager(config)
    
    # Request a specific session (Memory is tied to "user_123")
    session = await manager.get("user_123")
    
    # Stream asynchronously
    async for chunk in session.stream("Explain asyncio."):
        print(chunk, end="", flush=True)
        
    # Cleanup memory
    await manager.shutdown()

asyncio.run(run_server())

4. Handling Exceptions

from agy_connect import Chat
from agy_connect.exceptions import AgyNotInstalled

try:
    chat = Chat()
except AgyNotInstalled:
    print("Please install Antigravity CLI.")

API Reference

The Chat and Session objects expose the following methods:

Method Description
send(prompt: str) Sends a prompt synchronously and returns the complete string response.
stream(prompt: str) Generator that yields response tokens in real-time as they arrive.
save(filename: Optional[str]) Saves history to JSON. Defaults to sessions/<session_id>.json and auto-creates the directory.
load(filename: str) Reloads a previous conversation history from a JSON file.
reset() Wipes the current session's memory/history completely.
history() Returns the raw list of messages (dictionaries) in the current session.
health() Returns real-time health metrics (PID, uptime, state, last errors).
status() Returns the current string state of the adapter (e.g. READY, BUSY).
restart() Forces a reboot of the underlying state machine and adapter.
close() / shutdown() Gracefully cleans up all resources and background tasks.

Architecture & Design

agy-connect Architecture

agy-connect uses an event-driven, state-machine architecture under the hood to ensure predictable process execution.

The Problem it Solves

The current implementation is designed around Antigravity CLI's non-interactive execution behavior, which makes long-lived stdin/stdout sessions impractical. As a result, agy-connect uses isolated batch-mode sessions while preserving conversation context in Python.

The Solution (Batch-Mode Strategy)

agy-connect embraces batch-mode processing using isolated workspaces.

  1. When a prompt is sent, agy-connect explicitly prepends the entire Python-side tracked history to ensure context isn't lost.
  2. It spawns a fresh, ephemeral agy process, immediately flushes stdin, and sends an EOF.
  3. It attaches an async reader to stdout to yield the tokens back to your application as agy generates them, then terminates the ephemeral process cleanly.

State Machine

Every adapter tracks its state strictly using agy_connect.constants: STOPPED -> STARTING -> READY -> STREAMING -> READY


Configuration

You can customize the library's behavior entirely by injecting a Config object:

from agy_connect import Chat, Config

config = Config(
    executable_path="/custom/path/to/agy", # Override auto-discovery
    idle_timeout=60,                       # Clean up session memory after 60s
    stream_chunk_size=512,                 # Byte sizes yielded during streams
    debug_mode=True                        # Enable verbose logger traces
)

chat = Chat(config)

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

This project is MIT licensed.

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

agy_connect-0.1.3.tar.gz (22.9 kB view details)

Uploaded Source

Built Distribution

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

agy_connect-0.1.3-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file agy_connect-0.1.3.tar.gz.

File metadata

  • Download URL: agy_connect-0.1.3.tar.gz
  • Upload date:
  • Size: 22.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for agy_connect-0.1.3.tar.gz
Algorithm Hash digest
SHA256 a920307320397135ac603e021072d7b3bbe71aba2e52d4813d349fcb57ad6a70
MD5 d0d1e8a366b5a072410902322a118197
BLAKE2b-256 8413a50832f71bc8ae3b43531e9fe9b765d2ceb240bdb13f054d0b9d56659f07

See more details on using hashes here.

File details

Details for the file agy_connect-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: agy_connect-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 23.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for agy_connect-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 bbe31354a0580b20d78fdc7925b3a68be1b1aced8a120da1c2887ce4399e877f
MD5 ca200a34defb4a39c4b09a00bac2b31f
BLAKE2b-256 2922d076fcb7992f8eab0bec68e0474fb263ab2359ce788675fb7334de4ccfa9

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