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}/messageswith the same body as/chat(withoutsession_id).POST /v1/agents/{agent_id}/chatwith"session_id"in the body.
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"])const API_ROOT = "https://futuresmart.ai/database-agent/api";
const AGENT_ID = process.env.DATABASE_AGENT_ID;
const HEADERS = {
"X-API-Key": process.env.DATABASE_AGENT_API_KEY,
"Content-Type": "application/json",
};
async function ask(path, body) {
const res = await fetch(`${API_ROOT}${path}`, { method: "POST", headers: HEADERS, body: JSON.stringify(body) });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
return res.json();
}
const first = await ask(`/v1/agents/${AGENT_ID}/chat`, {
query: "How many orders were placed in each month of 2025?",
});
const next = await ask(`/v1/agents/${AGENT_ID}/sessions/${first.session_id}/messages`, {
query: "Which month had the most?",
debug_info: true,
});
console.log(next.response);
console.log(next.debug_info.refined_query);SESSION_ID=$(curl -sS -X POST "https://futuresmart.ai/database-agent/api/v1/agents/$DATABASE_AGENT_ID/chat" \
-H "X-API-Key: $DATABASE_AGENT_API_KEY" -H "Content-Type: application/json" \
-d '{"query": "How many orders were placed in each month of 2025?"}' \
| python3 -c 'import json,sys; print(json.load(sys.stdin)["session_id"])')
curl -sS -X POST "https://futuresmart.ai/database-agent/api/v1/agents/$DATABASE_AGENT_ID/sessions/$SESSION_ID/messages" \
-H "X-API-Key: $DATABASE_AGENT_API_KEY" -H "Content-Type: application/json" \
-d '{"query": "Which month had the most?"}'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.
| Call | Returns |
|---|---|
GET /v1/agents/{agent_id}/sessions | sessions[], 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. |
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]}")curl -sS "https://futuresmart.ai/database-agent/api/v1/agents/$DATABASE_AGENT_ID/sessions" \
-H "X-API-Key: $DATABASE_AGENT_API_KEY"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:
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.