Metadata-Version: 2.5
Name: autom-haystack
Version: 0.1.0
Summary: Haystack integration for Autom: live Google, Bing, Brave, DuckDuckGo and Yahoo results for RAG pipelines and agents.
Project-URL: Homepage, https://www.autom.dev
Project-URL: Documentation, https://github.com/automdev/autom-haystack#readme
Project-URL: Repository, https://github.com/automdev/autom-haystack
Project-URL: Issues, https://github.com/automdev/autom-haystack/issues
Author-email: Autom <contact@autom.dev>
License-Expression: MIT
License-File: LICENSE
Keywords: agents,autom,haystack,rag,serp,web-search
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: haystack-ai>=2.9
Requires-Dist: httpx<1,>=0.27
Provides-Extra: test
Requires-Dist: pytest-asyncio>=0.24; extra == 'test'
Requires-Dist: pytest>=8.3; extra == 'test'
Requires-Dist: ruff<1,>=0.8; extra == 'test'
Description-Content-Type: text/markdown

# autom-haystack

[Haystack](https://haystack.deepset.ai) integration for [Autom](https://www.autom.dev), a SERP API that returns live search engine results as JSON.

`AutomWebSearch` searches the web with Google (the default), Bing, Brave, DuckDuckGo or Yahoo. It returns the results as Haystack `Document`s, ready for a RAG pipeline or an agent.

## Installation

```bash
pip install autom-haystack
```

Get an API key at [app.autom.dev](https://app.autom.dev) and set it in the environment:

```bash
export AUTOM_API_KEY="your-api-key"
```

## Usage

```python
from haystack_integrations.components.websearch.autom import AutomWebSearch

search = AutomWebSearch(top_k=5)
result = search.run(query="What is Haystack?")

for doc in result["documents"]:
    print(doc.meta["title"], doc.meta["link"])
    print(doc.content)
```

`run` returns two outputs:
- `documents`: one `Document` per organic result. The content is the snippet, and the metadata holds `title`, `link` and `position`, plus `date` and `source` when Autom returns them.
- `links`: the result URLs.

| Parameter | Default | Description |
| --- | --- | --- |
| `api_key` | `Secret.from_env_var("AUTOM_API_KEY")` | Autom API key |
| `top_k` | `10` | Maximum number of results; `None` keeps the whole page |
| `engine` | `google` | `google`, `bing`, `brave`, `duckduckgo` or `yahoo` |
| `allowed_domains` | | Only search these domains, added to the query as `site:` filters |
| `search_params` | | Extra parameters for Autom, such as `{"gl": "us", "hl": "en"}` or `{"tbs": "qdr:w"}` (past week) for Google |
| `timeout` | `60` | Seconds to wait for Autom |

A failed request raises `AutomError`, a Haystack `ComponentError` with the HTTP status. The API key never appears in the message. Autom reports a rate limit as HTTP 401 with "Rate limit exceeded", and the error says so. `run_async` is available too.

### In a RAG pipeline

```python
from haystack import Pipeline
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.websearch.autom import AutomWebSearch

template = [
    ChatMessage.from_user(
        "Answer the question from these search results.\n"
        "{% for doc in documents %}- {{ doc.content }} ({{ doc.meta.link }})\n{% endfor %}\n"
        "Question: {{ question }}"
    )
]

pipeline = Pipeline()
pipeline.add_component("search", AutomWebSearch(top_k=5))
pipeline.add_component("prompt", ChatPromptBuilder(template=template, required_variables=["documents", "question"]))
pipeline.add_component("llm", OpenAIChatGenerator(model="gpt-4.1-mini"))
pipeline.connect("search.documents", "prompt.documents")
pipeline.connect("prompt.prompt", "llm.messages")

question = "What is new in Python 3.13?"
result = pipeline.run({"search": {"query": question}, "prompt": {"question": question}})
print(result["llm"]["replies"][0].text)
```

## Development

```bash
pip install -e ".[test]"
pytest -m "not integration"   # offline
AUTOM_API_KEY=... pytest       # with the live test
```

## License

MIT
