Follow-ups and conversations

Keep context across questions with a session, read saved conversations, and export result rows.

Follow-up questions

Every answer returns a session_id. Send the next question to that conversation and the agent rewrites it into a self-contained question before answering — "Which month had the most?" becomes "Which month in 2025 had the most orders?".

There are two equivalent ways to do it:

  • POST /v1/agents/{agent_id}/sessions/{session_id}/messages with the same body as /chat (without session_id).
  • POST /v1/agents/{agent_id}/chat with "session_id" in the body.
Python
import os
import requests

API_ROOT = "https://futuresmart.ai/database-agent/api"
AGENT_ID = os.environ["DATABASE_AGENT_ID"]
HEADERS = {"X-API-Key": os.environ["DATABASE_AGENT_API_KEY"]}

first = requests.post(
    f"{API_ROOT}/v1/agents/{AGENT_ID}/chat",
    headers=HEADERS,
    json={"query": "How many orders were placed in each month of 2025?"},
    timeout=180,
)
first.raise_for_status()
session_id = first.json()["session_id"]

follow_up = requests.post(
    f"{API_ROOT}/v1/agents/{AGENT_ID}/sessions/{session_id}/messages",
    headers=HEADERS,
    json={"query": "Which month had the most?", "debug_info": True},
    timeout=180,
)
follow_up.raise_for_status()
print(follow_up.json()["response"])
print(follow_up.json()["debug_info"]["refined_query"])

A conversation belongs to one agent. Sending another agent's session_id returns 404 Session … not found for agent … before any question is asked.

Saved conversations

Every conversation on the agent — from the app, the website chat bubble, the full-page link or the API — is saved. A key can read all of them.

CallReturns
GET /v1/agents/{agent_id}/sessionssessions[], newest first: session_id, session_title, display_message (the first question) and created_time; meta.total.
GET /v1/agents/{agent_id}/sessions/{session_id}conversation_data[]: one entry per message with role (user or assistant), message, timestamp, and on answers the saved debug_info and graph_output.
PATCH /v1/agents/{agent_id}/sessions/{session_id}Rename: send {"session_title": "…"}.
DELETE /v1/agents/{agent_id}/sessions/{session_id}Delete the conversation.
Python
import os
import requests

API_ROOT = "https://futuresmart.ai/database-agent/api"
AGENT_ID = os.environ["DATABASE_AGENT_ID"]
HEADERS = {"X-API-Key": os.environ["DATABASE_AGENT_API_KEY"]}

sessions = requests.get(f"{API_ROOT}/v1/agents/{AGENT_ID}/sessions", headers=HEADERS, timeout=60).json()
latest = sessions["sessions"][0]
print(latest["session_title"], latest["created_time"])

detail = requests.get(
    f"{API_ROOT}/v1/agents/{AGENT_ID}/sessions/{latest['session_id']}", headers=HEADERS, timeout=60
).json()
for message in detail["conversation_data"]:
    print(f"{message['role']:>9}: {message['message'][:80]}")

Saved answers follow the agent's current Settings → Answers: if the agent hides SQL or result rows, a replay leaves them out too.

Exporting rows as CSV

When an answer has more than 50 rows, the answer carries a 10-row preview, the full result is stored as a CSV file, and debug_info.export_url links to it. You can also fetch a fresh link later:

Shell
curl -sS "https://futuresmart.ai/database-agent/api/v1/sessions/$SESSION_ID/export?agent_id=$DATABASE_AGENT_ID&chat_id=$CHAT_ID" \
  -H "X-API-Key: $DATABASE_AGENT_API_KEY"

The response is {"export_url": "…", "expires_in_seconds": 604800, "chat_id": "…"}; the link is valid for seven days. The agent_id query parameter is required with an API key. Smaller results have no export file and return 404 Export file not available; their rows are already in the answer. If the agent hides result rows, export returns 403.