# Class instantiation

Instantiate the Query Agent against an authenticated Weaviate Cloud client. Configuration can be set at construction time (collections, system prompt, and — in Python — a request timeout) and most options can also be overridden per call to `ask()` or `search()`.

## Basic instantiation

The Query Agent requires only a target [Weaviate Cloud instance](../manage-clusters/connect.md) to be initialised. First, set up a Weaviate client:

:::code-group{sync="languages"}
```python title="Python"
import os
import weaviate
from weaviate.agents.query import QueryAgent
from weaviate.classes.init import Auth
headers = {
```

```typescript title="JavaScript/TypeScript"
import weaviate from 'weaviate-client';
import { QueryAgent } from 'weaviate-agents';

const headers = {
```
:::

Then pass that client to the Query Agent, and all Weaviate calls via agents will be routed through it.

:::code-group{sync="languages"}
```python title="Python"
qa = QueryAgent(client=client)
```

```typescript title="JavaScript/TypeScript"
const qa = new QueryAgent(client);
```
:::

:::callout{intent="note" title="Async"}
In Python, to instantiate the async Query Agent (`AsyncQueryAgent`), you must also pass an async Weaviate Client via `weaviate.use_async_with_weaviate_cloud`. In JavaScript/TypeScript, the Query Agent is async by default.
:::

## Additional configuration

### Parameters

The `QueryAgent` constructor accepts the following arguments:

::::tabs{sync="languages"}
:::tab{title="Python"}
| Parameter       | Type                                      | Description                                                                                                                                                                                                       |
| --------------- | ----------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client`        | `WeaviateClient`                          | Required. The Weaviate client connected to a Weaviate Cloud cluster.                                                                                                                                              |
| `collections`   | `list[str \| QueryAgentCollectionConfig]` | Optional. The collections to query. Can be overridden per call to `ask()` or `search()`.                                                                                                                          |
| `system_prompt` | `str`                                     | Optional. Prompt to provide extra instructions to the agents, as well as define the tone, format, and style of the agent's final response. [See the page on the system prompt for more detail](system-prompt.md). |
| `timeout`       | `int \| None`                             | Optional. The maximum time to wait for a response, in seconds. Defaults to 60 seconds.                                                                                                                            |
:::

:::tab{title="JavaScript/TypeScript"}
The first argument is the Weaviate client. All other options are passed in a `QueryAgentOptions` object as the second argument.

| Parameter      | Type                                       | Description                                                                                                                                                                                                       |
| -------------- | ------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `client`       | `WeaviateClient`                           | Required. The Weaviate client connected to a Weaviate Cloud cluster.                                                                                                                                              |
| `collections`  | `(string \| QueryAgentCollectionConfig)[]` | Optional. The collections to query. Can be overridden per call to `ask()` or `search()`.                                                                                                                          |
| `systemPrompt` | `string`                                   | Optional. Prompt to provide extra instructions to the agents, as well as define the tone, format, and style of the agent's final response. [See the page on the system prompt for more detail](system-prompt.md). |

The TypeScript client does not currently expose a `timeout` option.
:::
::::

### Collections

You can define which collections are available either

- at the instantiation of the Query Agent base class,

:::code-group{sync="languages"}
```python title="Python"
qa = QueryAgent(
    client=client,
    collections=["FinancialContracts", "Weather"]
)
```

```typescript title="JavaScript/TypeScript"
const qaWithCollections = new QueryAgent(client, {
    collections: ['FinancialContracts', 'Weather'],
});
```
:::

- or at runtime of the Query Agent's methods, either Ask Mode or Search Mode.

:::code-group{sync="languages"}
```python title="Python"
qa = QueryAgent(client=client)

qa.ask(
    "What type of contracts have been signed and who were the authors?", 
    collections=["FinancialContracts", "Weather"]
)
```

```typescript title="JavaScript/TypeScript"
const qaWithoutCollections = new QueryAgent(client);

await qaWithoutCollections.ask(
    "What type of contracts have been signed and who were the authors?", {
    collections: ['FinancialContracts', 'Weather'],
});
```
:::

If you provide both, then the collections specified at runtime will override those specified in the base class. [See the page on collection configuration for more detail](advanced-collections.md).

## Questions and feedback

Have a question or feedback? Here's how to reach us.

::::card-grid
:::card{title="Community Forum" href="https://forum.weaviate.io/c/support" icon="messages-square"}
Ask questions and connect with other developers on our **Community forum**.
:::

:::card{title="Support" href="/guides/support-overview" icon="life-buoy"}
Weaviate Cloud user or customer? Find the right channel on the **Support page**.
:::
::::

## Related pages

- [Agents](./agents-index.md)
- [AI-assisted Weaviate code generation](./ai-assisted-vibe-coding-index.md)
- [APIs](./apis-index.md)
- [Authorization and authentication](./authorization-and-authentication-index.md)
- [Benchmarks](./benchmarks-index.md)
- [Best practices](./best-practices-index.md)
- [Client libraries](./clients-index.md)
- [Client Libraries / SDKs](./client-libraries-index.md)
- [Cloud](./cloud-index.md)
- [Cloud account management](./cloud-account-management-index.md)

# Agent Instructions

This portal answers questions programmatically. To receive a synthesized,
source-cited answer instead of crawling page by page, append the `?ask=`
query parameter to any page URL on this site:

    /guides/quickstart?ask=how+do+I+authenticate

Optional parameters:

- `&goal=<what-you-are-trying-to-do>` steers the answer toward your
  objective (e.g. `&goal=write+a+python+client`).
- `&version=<label>` scopes the answer to a mounted version when the
  portal publishes more than one.

The response is `text/markdown`: the answer followed by a `# Sources` list
of the portal pages it was grounded in. Status codes are the contract:

- `200` — the answer; `402` — the portal owner’s plan or answer credits are
  exhausted (surface this to your operator; do NOT retry); `429` — you are
  rate-limited; back off for the `Retry-After` seconds; `503` — the answer
  lane is temporarily unavailable; fall back to crawling the `.md` pages.

For the full corpus map read `llms.txt` at the site root; for the tool
surface (search + page fetch as MCP tools) see `/mcp`.
