Skip to main content

Query Stream

Used to send queries to an AI agent and receive streaming responses. This endpoint allows you to interact with an AI agent's chat history for a specific project and receive real-time responses in a streaming format.

API Endpoint

PropertyValue
Request MethodPOST
Request URLhttps://api.seliseblocks.com/ai-agent/query/stream

Request

Request Example

curl -X POST 'https://api.seliseblocks.com/ai-agent/query/stream' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "What are the features of this product?",
"session_id": "session_123456",
"base_prompt": "You are a helpful customer support assistant",
"model_id": "gpt-4",
"model_name": "GPT-4",
"model_provider": "openai",
"tool_ids": ["tool_1", "tool_2"],
"last_n_turn": 5,
"enable_summary": false,
"enable_next_suggestion": false,
"response_type": "text",
"response_format": "markdown",
"call_from": "project_slug_123",
"files": ["file_id_1"],
"images": ["image_url_1"]
}'

Request Headers

FieldTypeRequiredDescription
acceptstringYesAccepted response format. Use application/json
Content-Typeapplication/jsonYesData type, must be application/json.

Request Body

Request Body Schema

{
"query": "string",
"session_id": "string",
"base_prompt": "string",
"model_id": "string",
"model_name": "string",
"model_provider": "string",
"tool_ids": ["string"],
"last_n_turn": 5,
"enable_summary": false,
"enable_next_suggestion": false,
"response_type": "text",
"response_format": "string",
"call_from": "string",
"files": ["string"],
"images": ["string"]
}

Request Body Parameters

FieldTypeRequiredDescription
querystringYesThe user's query or message to send to the AI agent.
session_idstringNoUnique identifier for the chat session. Used to maintain conversation context.
base_promptstringNoSystem prompt or base instruction for the AI agent to follow.
model_idstringNoIdentifier of the language model to use.
model_namestringNoHuman-readable name of the model (e.g., GPT-4, Claude).
model_providerstringNoProvider of the model (e.g., openai, anthropic).
tool_idsarrayNoArray of tool identifiers that the agent can utilize to answer the query.
last_n_turnintegerNoNumber of previous conversation turns to include as context. Default: 5.
enable_summarybooleanNoWhether to enable automatic summarization of the conversation. Default: false.
enable_next_suggestionbooleanNoWhether to enable suggestions for follow-up queries. Default: false.
response_typestringNoFormat of the response (e.g., text, json). Default: text.
response_formatstringNoSpecific formatting instructions for the response (e.g., markdown, html).
call_fromstringNoProject slug identifier to specify which project's AI agent to query. Required to retrieve project-specific chat history.
filesarrayNoArray of file identifiers to include as context for the query.
imagesarrayNoArray of image URLs to include as context for the query.
note
  • The call_from parameter is used to identify which project's AI agent should handle the query and retrieve the corresponding chat history.
  • The session_id helps maintain conversation continuity across multiple queries.
  • The last_n_turn parameter controls how much previous conversation context is provided to the model.

Response

Success Response (200 OK)

Returns a streaming text response containing the AI agent's reply.

"The product includes the following features: 1. Real-time chat capabilities, 2. Integration with multiple AI models, 3. Session management, 4. Context-aware responses, and 5. Support for file and image attachments. Would you like more details on any specific feature?"

Response Description

FieldTypeDescription
(stream)stringThe response is streamed as text. The AI agent's reply to the query, which may include contextual information from the chat history and available tools. The stream continues until the complete response is transmitted.
info

The response is returned as a stream. This means the data is sent incrementally as it's generated, allowing for real-time display of the AI agent's response.

Error Response

422 Validation Error

Returned when the request body contains invalid or missing required fields.

{
"detail": [
{
"loc": ["query"],
"msg": "Field required",
"type": "missing",
"input": null,
"ctx": {}
}
]
}

Error Fields

FieldTypeDescription
detailarrayArray of validation error objects.
locarrayLocation of the error (field name).
msgstringHuman-readable error message.
typestringType of validation error.
inputanyThe input value that caused the error.

Use Cases

  • Customer Support: Send customer inquiries and retrieve AI-generated responses from a support agent.
  • Knowledge Base Queries: Query an AI agent to retrieve information from project-specific knowledge bases.
  • Multi-turn Conversations: Maintain context across multiple queries using the session_id.
  • Tool Integration: Leverage AI agent tools to provide enhanced responses with relevant data.
  • File & Image Analysis: Include files and images as context for more accurate and detailed responses.

Example Use Case

Retrieving chat history for a project's AI agent:

curl -X POST 'https://api.seliseblocks.com/ai-agent/query/stream' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"query": "Show me the order history for customer ABC123",
"session_id": "session_user_001",
"call_from": "ecommerce_project",
"model_name": "GPT-4",
"model_provider": "openai",
"tool_ids": ["order_database_tool", "customer_lookup_tool"],
"last_n_turn": 10,
"enable_summary": true
}'

This request sends a query to the AI agent associated with the ecommerce_project, utilizing tools to fetch order data and maintain context of the last 10 conversation turns.