# AIIQ Orchestration Integration

This package now vendors the `q:\aiiq` orchestration runtime under `ai_orchestrator/` and exposes it through `ares_compression`.

## What Was Added

- The `ai_orchestrator/` package was copied into this project.
- `ares_compression.aiiq_integration` adds lazy helpers so the orchestrator can be created from this repo without importing it manually.
- The vendored AIIQ settings now support explicit embedding backend selection. Default startup is safe for offline use because embedding model downloads are disabled unless you opt in.

## Install

```bash
cd inventions/ares-context-compression-layer
pip install -e .[orchestration]
```

## FastAPI App

```bash
uvicorn ai_orchestrator.api.main:create_app --factory
```

That serves the vendored AIIQ API from this project.

## Python API

```python
from pathlib import Path

from ares_compression import (
    build_aiiq_app,
    build_aiiq_runtime,
    build_aiiq_task_bridge,
)

runtime = build_aiiq_runtime(embedding_backend="hash")
app = runtime.create_app(run_embedded_worker=False)

bridge = build_aiiq_task_bridge(embedding_backend="hash")
submitted = bridge.submit_task_sync(
    goal="Inspect this repo and prepare an implementation plan.",
    repo_path=Path(r"Q:\\ARES"),
)

print(submitted.task_id)
```

## Inline Worker Execution

If you want one process to submit and execute tasks without a separate worker service:

```python
from pathlib import Path
from ares_compression import build_aiiq_task_bridge

bridge = build_aiiq_task_bridge(embedding_backend="hash")
task = bridge.run_task_sync(
    goal="Implement the researched optimization in this repo.",
    repo_path=Path(r"Q:\\ARES"),
    timeout_seconds=900,
)

print(task.status, task.summary)
```

This runs the vendored AIIQ worker in-process. Actual code generation still depends on your configured model provider keys.

## Compression Layer Notes

- `ContextCompressor` now resolves `cuda` vs `cpu` automatically.
- `compress()` returns `CompressionResult.attention_mask` when an input mask is provided.
- The tensor compression layer still works on hidden states, not raw token ids.
