Metadata-Version: 2.5
Name: langchain-getabrain
Version: 0.1.0
Summary: LangChain tools for GetABrain: ask verified humans a question from an agent.
Project-URL: Homepage, https://www.getabrain.ai
Project-URL: Documentation, https://github.com/Guitarmaniac24/langchain-getabrain#readme
Project-URL: Source, https://github.com/Guitarmaniac24/langchain-getabrain
Project-URL: API docs, https://www.getabrain.ai/docs
Author-email: GetABrain <hello@getabrain.ai>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,getabrain,human-in-the-loop,langchain,tools
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.11
Requires-Dist: getabrain>=0.2.1
Requires-Dist: langchain-core<2.0,>=1.0
Description-Content-Type: text/markdown

# langchain-getabrain

LangChain tools for [GetABrain](https://www.getabrain.ai), an API that lets an agent ask
verified people in the US a question and get structured answers back.

Two tools:

| Tool | Name the model sees | What it does |
|---|---|---|
| `GetABrainAskTool` | `getabrain_ask_human` | Sends a question, waits up to `max_wait_seconds` for answers, returns them. If nobody has answered yet it returns `status: "pending"` and a `query_id`. |
| `GetABrainGetAnswersTool` | `getabrain_get_answers` | Reads the answers to an earlier question by `query_id`. Free and read-only. |

People take minutes to hours to answer, so a `pending` result is normal. The question stays
open and the second tool picks up the answers later.

## Install

```bash
pip install -U langchain-getabrain
```

## Credentials

Create an account and API key at https://www.getabrain.ai/requestor/signup (or see the
[quick start](https://www.getabrain.ai/docs/quickstart)), then:

```bash
export GETABRAIN_API_KEY="gab_k_..."
export GETABRAIN_API_SECRET="gab_s_..."
```

**Cost:** with a live key, every answer is paid from your GetABrain balance. With a
**test-mode key** (`POST /api/v1/requestor/keys {"mode": "test"}`), answers are simulated by
an AI stand-in, never reach people, and come back marked `"simulated": true` with a notice.
Build and test with a test-mode key first.

## Use it directly

```python
from langchain_getabrain import GetABrainAskTool, GetABrainGetAnswersTool

ask = GetABrainAskTool(max_wait_seconds=60)
print(ask.invoke({
    "question": "Which name is easier to remember?",
    "query_type": "multiple_choice",
    "options": ["Quillo", "Brightdesk"],
    "num_responses": 3,
}))
```

The result is a JSON string:

```json
{"query_id": "...", "status": "answered", "answers_received": 3, "answers_requested": 3,
 "answers": [{"selected_ids": ["2"], "selected_options": ["Brightdesk"]}, "..."],
 "test_mode": false}
```

## Use it in an agent

```python
from langchain.agents import create_agent
from langchain_getabrain import GetABrainAskTool, GetABrainGetAnswersTool

agent = create_agent(
    model="anthropic:claude-sonnet-4-5",
    tools=[GetABrainAskTool(), GetABrainGetAnswersTool()],
    system_prompt="When a decision needs human judgment, ask a person with getabrain_ask_human.",
)
agent.invoke({"messages": [{"role": "user", "content": "Is our headline 'Ship faster' clear to a normal person?"}]})
```

## Arguments the model fills

| Argument | Type | Notes |
|---|---|---|
| `question` | str | Required. |
| `query_type` | `yes_no` \| `multiple_choice` \| `rating_scale` \| `text` | Default `yes_no`. `rating_scale` is 1 to 5. |
| `options` | list[str] | Required for `multiple_choice` (2 or more). |
| `context` | str | Optional background shown to the person. |
| `num_responses` | int | How many different people answer. Default 1. |

## Settings you set in code

| Setting | Default | Notes |
|---|---|---|
| `max_wait_seconds` | 60 | How long one call waits before returning `pending`. |
| `poll_interval_seconds` | 5 | Time between status checks. |
| `max_responses` | 5 | Upper limit on `num_responses` per call, a spend guard. |
| `speed` | `None` | `relaxed` / `standard` / `fast` / `rush`: higher pays people more per answer. |
| `api_key`, `api_secret`, `base_url` | env vars | `GETABRAIN_API_KEY`, `GETABRAIN_API_SECRET`, `GETABRAIN_BASE_URL`. |
| `client` | `None` | Pass a ready `getabrain.GetABrain` client instead. |

Other query types (image comparison, ranking, A/B tests, video and audio review) are available
through the [`getabrain` Python SDK](https://pypi.org/project/getabrain/) and the
[API docs](https://www.getabrain.ai/docs/api).

## Development

```bash
uv sync --group test
uv run pytest
```

Unit tests mock HTTP and make no network calls.

## License

MIT
