Metadata-Version: 2.5
Name: hani2
Version: 0.3.0
Summary: HANI2: a web interface for human-agent negotiation studies, with an AI Assistant and pluggable tools
Project-URL: Homepage, https://github.com/autoneg/hani2
Project-URL: Documentation, https://autoneg.github.io/hani2/
Project-URL: Repository, https://github.com/autoneg/hani2
Author-email: Yasser Mohammad <yasserfarouk@gmail.com>
License-Expression: AGPL-3.0-or-later
License-File: LICENSE
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.11
Requires-Dist: attrs>=23.0
Requires-Dist: fastapi>=0.110
Requires-Dist: httpx>=0.27
Requires-Dist: itsdangerous>=2.1
Requires-Dist: litellm>=1.0.0
Requires-Dist: negmas-llm>=0.4.3
Requires-Dist: negmas>=0.17.0
Requires-Dist: pandas>=2.0
Requires-Dist: plotly>=5.20
Requires-Dist: python-multipart>=0.0.9
Requires-Dist: pyyaml>=6.0
Requires-Dist: typer>=0.9
Requires-Dist: uvicorn[standard]>=0.27
Provides-Extra: dev
Requires-Dist: pytest-timeout; extra == 'dev'
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.6; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.25; extra == 'docs'
Provides-Extra: e2e
Requires-Dist: playwright>=1.49; extra == 'e2e'
Provides-Extra: han
Requires-Dist: han-agents>=0.0.2; extra == 'han'
Provides-Extra: harness
Requires-Dist: claude-agent-sdk>=0.2.184; extra == 'harness'
Description-Content-Type: text/markdown

# HANI2

HANI2 is a web interface for human–agent negotiation studies. People negotiate in the browser against automated agents built with [negmas](https://github.com/yasserfarouk/negmas), optionally helped by an AI Assistant, while HANI2 records every offer, message, click and questionnaire answer. It runs the human–agent negotiation and hybrid intelligence tracks of the [ANAC competition](https://anac.cs.brown.edu).

HANI2 is a Python package: a FastAPI backend plus a React frontend that ships pre-built inside the wheel.

**Documentation:** <https://autoneg.github.io/hani2/>

## Install and run

Requires Python 3.11 or newer (tested up to 3.15).

```bash
pip install hani2
hani2 setup      # creates ~/negmas/hani2/settings with defaults, users and sample scenarios
hani2            # http://localhost:5006
```

One port (default 5006) serves:

| URL | What |
| --- | --- |
| `/app` | The negotiation interface for logged-in users (`user` / `userpass`, `admin` / `adminpass`). |
| `/play` | The no-login playground. Prolific participants arrive at `/play?PROLIFIC_PID=...`. |
| `/admin` | The admin console. |
| `/api` | The REST and WebSocket API. |

The Assistant and LLM opponents need a language model. The defaults use a local [Ollama](https://ollama.com) model:

```bash
ollama pull qwen3:4b-instruct
```

Any provider supported by litellm works too; see [Language models](https://autoneg.github.io/hani2/guide/llms/).

## Features

- **Negotiation desk**: the opponent's offer on the table, a counter-offer editor, utility gauges with a no-deal marker, a conversation-style history, confirmation before accepting or ending, three layouts and a phone layout.
- **Tools**: preferences, plots, histograms, the offer trace, an offer picker and more, in panes participants can rearrange. Write new ones in Python.
- **Assistant**: an AI helper that chats, highlights and annotates the interface, rearranges tools, shows interactive panels and, with permission, makes offers. It can also find, use and add tools. Sixteen capabilities and three autonomy levels.
- **Autopilot**: the Assistant or any negotiator plays the human's seat.
- **WebMCP**: browser AI agents can read and (optionally) negotiate through the page's tools.
- **Opponents**: any negmas, Genius or negmas-llm negotiator, your own classes, and named groups.
- **Studies**: self-contained experiments, questionnaires, results CSV files and an event log with analytics.
- **Prolific**: practice rounds, counted rounds and completion links.
- **Admin console**: live sessions, results, analytics, users and all settings in the browser.
- **Accounts**: password, GitHub and Google OAuth, or no login; optional consent form.

## A custom opponent agent

The opponent is any negmas `SAONegotiator`. This one concedes over time and says why; text in the `data` of an offer shows in the participant's history.

```python
# my_opponent.py
from negmas.outcomes import ExtendedOutcome
from negmas.sao import ResponseType, SAONegotiator


class Haggler(SAONegotiator):
    """Asks for a lot at first, concedes linearly over time, and explains itself."""

    def target(self, state) -> float:
        lo, hi = self.ufun.minmax()
        floor = max(lo, float(self.ufun.reserved_value or lo))
        return hi - state.relative_time * (hi - floor) * 0.8  # never concede the last 20%

    def propose(self, state, dest=None):
        outcome = self.ufun.invert().one_in((self.target(state), self.ufun.max()), normalized=False)
        text = "This is my best offer." if state.relative_time < 0.5 else "I am meeting you halfway now."
        return ExtendedOutcome(outcome, data={"text": text})

    def respond(self, state, source=None):
        offer = state.current_offer
        if offer is not None and self.ufun(offer) >= self.target(state):
            return ResponseType.ACCEPT_OFFER
        return ResponseType.REJECT_OFFER
```

Start the server from the folder that holds `my_opponent.py`:

```bash
hani2 --opponents file:my_opponent.Haggler
```

Or list it in `opponents` in `env.json`, next to built-in agents and groups such as `:template` or `helpers.AgentK`. See [Opponents](https://autoneg.github.io/hani2/guide/opponents/).

## A custom Assistant

```python
# my_agent.py
from hani2.assistant.runtime import Assistant


class RulesAgent(Assistant):
    def handle_user_message(self, text: str) -> None:
        actions = self.session_state.get("actions")
        if not actions:
            self.post("Load a scenario and start a negotiation first.")
            return
        ctx = self.run_on_doc(actions["context"])
        if ctx["partner_offer"] is None:
            self.post("Your opponent has not made an offer yet.")
        elif ctx["partner_offer_utility"] < ctx["reserved_value"]:
            self.post("That offer is worse than walking away.")
        else:
            self.post("That offer beats your reserved value.")
```

Point `agent_class` in `~/negmas/hani2/settings/assistant_settings.json` at it and start the server from the folder that holds `my_agent.py`:

```json
{"agent_class": "my_agent:RulesAgent"}
```

```bash
PYTHONPATH=$PWD hani2 --page play
```

The [Assistant tutorial](https://autoneg.github.io/hani2/tutorials/assistant/) goes from this to LLM agents that highlight the interface and show their own panels.

## A custom tool

```python
# my_tools.py
from hani2.tools import Tool, ui


class OfferCounter(Tool):
    name = "Offer Counter"
    description = "How many offers each side made so far."
    icon = "hash"
    pane = "side"

    def view(self):
        trace = self.trace()
        me = self.session_state.get("human_id")
        mine = sum(1 for row in trace if row[3] == me)
        return [ui.stats(ui.stat("Your offers", mine), ui.stat("Opponent offers", len(trace) - mine))]
```

Register it in `~/negmas/hani2/settings/env.json`:

```json
{"tools": {"extra": ["my_tools:OfferCounter"]}}
```

See the [tools tutorial](https://autoneg.github.io/hani2/tutorials/tools/).

## Development

```bash
git clone https://github.com/autoneg/hani2
cd hani2
uv venv
uv pip install -e '.[dev]'
pytest

# the web app (writes the bundle to src/hani2/web)
cd frontend
npm install
npm run build
```

For frontend work, run `hani2 --no-browser --dev` and `npm run dev` in `frontend/` (port 5173, proxied to the backend). To build the documentation, install `.[docs]` and run `mkdocs serve`.

## License

AGPL-3.0-or-later. See [LICENSE](LICENSE).
