Customizing the system prompt
You can provide a custom system prompt to guide the Query Agent's behavior, by passing it as part of the instantiation.
from weaviate.agents.query import QueryAgent
from weaviate.agents.classes import QueryAgentCollectionConfig
# Define a custom system prompt to guide the agent's behavior
system_prompt = """
You are a helpful assistant that can answer questions about the products and users in the database.
When you write your response use standard markdown formatting for lists, tables, and other structures.
Emphasize key insights and provide actionable recommendations when relevant.
"""
qa = QueryAgent(
client=client,
collections=[
QueryAgentCollectionConfig(
name="ECommerce",
target_vector=["name_description_brand_vector"],
)
],
system_prompt=system_prompt,
)
Then any run using the Query Agent will use this new set of instructions.
A custom system prompt is supported in both Ask Mode and Search Mode.
How is it used?
The system prompt is used in two places:
- During the query/aggregation writing - the system prompt is passed in addition to a general set of instructions to guide the construction of any queries.
- During the writing of the final answer - the system prompt overrides a general prompt.
Therefore it is most useful to use the system prompt in one of two ways:
- Instructions specific for your data, so that the query writing agent has additional information to write queries more effectively.
- A guide for style and tone in writing the final answer, such as specific formatting instructions.
Questions and feedback
If you have any questions or feedback, let us know in the user forum.
