Skip to main content
Go to documentation:
⌘U
Weaviate Database

Develop AI applications using Weaviate's APIs and tools

Deploy

Deploy, configure, and maintain Weaviate Database

Query Agent

Run agentic search over your Weaviate Cloud collections

Weaviate Cloud

Manage and scale Weaviate in the cloud

Engram

Persistent memory for LLM agents and applications

Additional resources

Integrations
Contributor guide
Events & Workshops
Weaviate Academy

Need help?

Weaviate LogoAsk AI Assistant⌘K
Community Forum

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 to be initialised. First, set up a Weaviate client:

import os
import weaviate
from weaviate.agents.query import QueryAgent
from weaviate.classes.init import Auth
headers = {
# Provide your required API key(s), e.g. Cohere, OpenAI, etc. for the configured vectorizer(s)
"X-INFERENCE-PROVIDER-API-KEY": os.environ.get("YOUR_INFERENCE_PROVIDER_KEY", ""),
}

client = weaviate.connect_to_weaviate_cloud(
cluster_url=os.environ.get("WEAVIATE_URL"),
auth_credentials=Auth.api_key(os.environ.get("WEAVIATE_API_KEY")),
headers=headers,
)

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

qa = QueryAgent(client=client)
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:

ParameterTypeDescription
clientWeaviateClientRequired. The Weaviate client connected to a Weaviate Cloud cluster.
collectionslist[str | QueryAgentCollectionConfig]Optional. The collections to query. Can be overridden per call to ask() or search().
system_promptstrOptional. 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.
timeoutint | NoneOptional. The maximum time to wait for a response, in seconds. Defaults to 60 seconds.

Collections

You can define which collections are available either

  • at the instantiation of the Query Agent base class,
    qa = QueryAgent(
    client=client,
    collections=["FinancialContracts", "Weather"]
    )
  • or at runtime of the Query Agent's methods, either Ask Mode or Search Mode.
    qa = QueryAgent(client=client)

    qa.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.

Questions and feedback

If you have any questions or feedback, let us know in the user forum.