Advanced Query Features
Learn how to leverage multi-turn and structured outputs
Multi-turn conversations
Based on your use case, you may want to leverage our multi-turn capabilities. With multi-turn, agents can use prior conversation history when responding to new queries. This means agents will automatically use information in prior turns to resolve ambiguities in the query, fetch the appropriate retrievals, and generate the final answer.
w/ Multi-turn | w/o Multi-turn | |
---|---|---|
Step 1 | Query: What is the merger price | Query: What is the merger price |
Response: Rationale: This is explicitly stated in Section 2.1(a) of the contract, which defines the “Per Share Merger Consideration” as $11.50 per share in cash, without interest Caveats: This price applies to all shares except for: (1) shares owned by Parent, Merger Sub, or their wholly owned subsidiaries (referred to as “Cancelled Shares”), (2) shares held in treasury by the Company, and (3) shares held by dissenting shareholders (referred to as “Dissenting Shares”) | Response: Rationale: This is explicitly stated in Section 2.1(a) of the contract, which defines the “Per Share Merger Consideration” as $11.50 per share in cash, without interest Caveats: This price applies to all shares except for: (1) shares owned by Parent, Merger Sub, or their wholly owned subsidiaries (referred to as “Cancelled Shares”), (2) shares held in treasury by the Company, and (3) shares held by dissenting shareholders (referred to as “Dissenting Shares”) | |
Turn 2 | Query: And when can this change? | Query: And when can this change? |
Response: Rationale: This is specified in Section 2.5 of the contract, which states that if the number of Shares or securities convertible into Shares changes due to certain corporate actions, “the Per Share Merger Consideration shall be equitably adjusted to provide to Parent and the holders of Shares the same economic effect as contemplated by this Agreement prior to such event. Caveats: The adjustment is specifically limited to maintaining the same economic effect as originally contemplated, and the contract does not provide for adjustments due to other factors such as market conditions or changes in the company’s financial performance. | Response: Rationale: This is based on Section 6.1(e) which outlines the specific conditions under which a Change of Recommendation can occur. It requires a 4-day notice period (the “Notice Period”) and must be in response to either an Intervening Event or a Superior Proposal. The Board must also determine that failing to make the change would be inconsistent with their fiduciary duties. Caveats: The change must follow specific procedural requirements including delivery of a written notice (Company Notice) with material details, and the Board must consult with financial advisors and outside legal counsel. |
Enabling multi-turn behavior
Enabling multi-turn is an agent-level setting. If multi-turn is enabled, at query-time you can pass a conversation_id
, which will:
- Append the new query to the given conversation
- Generate the response in a conversation-aware manner
If you do not pass a conversation_id
, Contextual will assume you are beginning a new conversation with the query in the request as the initial message.
If multi-turn is disabled at the agent-level, passing the conversation_id
will only append the query to the given conversation’s history; the response will not be generated in a conversation-aware manner.
Code Snippets
To enable or disable multi-turn for a given agent:
To pass the conversation_id
when querying:
Structured outputs [Beta]
Structured outputs is currently in beta and is missing some functionality, like attributions
Structured output mode is useful when you require query responses to follow a repeatable and easily parseable format. Example use cases include extracting pre-defined categories of information or generating responses that need to integrate seamlessly with downstream applications or workflows.
Contextual supports structured outputs in JSON format. To use structured ouputs:
-
First, define your schema, which must be valid JSON and include the
json_schema
key. -
Then, pass the schema as part of your
/query
request. If you are using our Python SDK, the schema must be passed under thestructrued_output
key in theextra_body
param. -
Finally, parse the returned message as a JSON
Example output: