Agent Query Stream
Stream a response to a query in a simple markdown format.
This endpoint provides a simplified streaming response:
- First, it streams the ID mapping for source linking
- Then it streams raw markdown content as it comes from the LLM
The client only needs to concatenate the markdown chunks to get the full document, and can use the ID mapping to resolve citations to their sources.
Request body:
- query: The query to ask the agent (required)
- tickers: Optional list of ticker symbols to filter documents by
- sourceType: Optional source type(s) to include (available options: '10-K', '10-Q', '8-K', '20-F', '40-F', '6-K', 'transcript', 'DEF 14A', etc.). Can be a single string or a list of strings.
- startDate: Optional start date for document filtering (format: YYYY-MM-DD)
- endDate: Optional end date for document filtering (format: YYYY-MM-DD)
- sourceLink: Optional source link(s) to search within. Can be a single string or a list of strings. No other documents will be queried by the agent but these. Use to restrict the search to user-selected documents.
Returns a streaming response with these event types:
-
'id_mapping': A mapping of IDs to source links for citation resolution
{
"type": "id_mapping",
"mapping": {
"#uuid1234": {
"sourceLink": "http://rest-api.captide.co/document?id=12345678",
"sourceMetadata": {
"sourceType": "10-K",
"ticker": "AAPL",
"date": "2024-01-01",
"fiscalPeriod": "FY 2023",
"documentId": "12345678"
}
}
}
} -
'markdown_chunk': A chunk of markdown text
{
"type": "markdown_chunk",
"content": "This is a part of the markdown response with a citation [#uuid1234]."
} -
'warning': Notification when requested information is not found
{
"type": "warning",
"message": "Could not find information about X in the provided documents."
} -
'done': Signals the end of the stream
{
"type": "done"
} -
'error': Error information if something goes wrong
{
"type": "error",
"detail": "An error occurred while processing the request."
}
Client implementation recommendations:
- First process the 'id_mapping' event to obtain source information for citations
- Then accumulate all 'markdown_chunk' events to build the complete response
- Display warnings to the user when 'warning' events are received
- When a 'done' event is received, the response is complete
- Use the ID mapping to create clickable citations in the rendered markdown
Integration with document search: The 'sourceLink' parameter can be used in conjunction with the document search endpoint to:
- Let users search and select specific documents they want to analyze
- Then pass those document IDs to this endpoint to ensure the AI only references those selected documents
- This creates a more user-controlled research experience where they can direct the AI to specific filings
Note: All JSON fields use camelCase naming convention.
Request Body — REQUIRED |
---|
query Query — REQUIREDThe query to ask the agent |
tickers TickersList of ticker symbols to filter documents by (e.g., ['AAPL', 'MSFT']). Check the '/companies' endpoint for available tickers. |
sourceType SourcetypeSource type(s) to include. Available options: 10-K, 10-Q, 8-K, 20-F, 40-F, 6-K, transcript, DEF 14A, DEFM14A, DEF 14C, DEFM14C. Can be a single string or a list of strings. |
start_date Start DateStart date for document filtering (format: YYYY-MM-DD) |
end_date End DateEnd date for document filtering (format: YYYY-MM-DD) |
sourceLink SourcelinkSource link(s) to search within. No other documents will be queried by the agent but these. Can be a single string or a list of strings. Use to restrict the search to user-selected documents. |
Responses | |||||
---|---|---|---|---|---|
200 Successful Response
| |||||
422 Validation Error
|