Skip to main content

Agent Query Stream

Stream a response to a query in a simple markdown format.

This endpoint provides a simplified streaming response:

  1. First, it streams the ID mapping for source linking
  2. 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:

  1. First process the 'id_mapping' event to obtain source information for citations
  2. Then accumulate all 'markdown_chunk' events to build the complete response
  3. Display warnings to the user when 'warning' events are received
  4. When a 'done' event is received, the response is complete
  5. 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:

  1. Let users search and select specific documents they want to analyze
  2. Then pass those document IDs to this endpoint to ensure the AI only references those selected documents
  3. 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 REQUIRED

The query to ask the agent

tickers Tickers

List of ticker symbols to filter documents by (e.g., ['AAPL', 'MSFT']). Check the '/companies' endpoint for available tickers.

sourceType Sourcetype

Source 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 Date

Start date for document filtering (format: YYYY-MM-DD)

end_date End Date

End date for document filtering (format: YYYY-MM-DD)

sourceLink Sourcelink

Source 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

Schema OPTIONAL
undefined
422

Validation Error

Schema OPTIONAL
detail object[] OPTIONAL
loc undefined[]
msg Message
type Error Type