Automation & agent integration
Two complete, copy-paste-able automations, followed by guidance for agent
builders. Both use only the standard library / requests so they drop into
any environment.
Ask your knowledge base from a script
Section titled “Ask your knowledge base from a script”import requests
BASE = "https://dashboard.insightai.pro/api/v1" # or your own instanceMODEL = "llama3.2"
session = requests.Session()
def signin(email: str, password: str) -> None: r = session.post(f"{BASE}/signin", json={"email": email, "password": password}) r.raise_for_status() # session now carries the auth cookie
def ask(question: str, chat_id: str | None = None, timeout: int = 300) -> tuple[str, str]: """Ask a question; returns (chat_id, answer). Reuse chat_id for follow-ups.""" if chat_id is None: r = session.post(f"{BASE}/chats", json={"model_name": MODEL, "message": question}, timeout=timeout) r.raise_for_status() chat = r.json() return chat["id"], chat["messages"][-1]["content"] r = session.post(f"{BASE}/chats/{chat_id}/followup", json={"model_name": MODEL, "message": question}, timeout=timeout) r.raise_for_status() return chat_id, r.json()[-1]["content"]
signin("you@example.com", "YourPass123")chat_id, answer = ask("What does our expense policy say about pre-approval?")print(answer)_, followup = ask("What's the receipt deadline?", chat_id)print(followup)Notes that matter in practice:
- Generous timeouts. The blocking endpoints return only when the answer is fully generated. If you’d rather show progress, the streaming endpoints deliver the reply as NDJSON tokens.
- Handle 401 by re-signing-in — tokens last 24 hours.
- Answers are grounded in whatever indexed collections the account can
access. Pass
collection_idswhen creating the chat (orPUT /chats/{id}/collectionslater) to narrow retrieval to specific collections. - The generating response carries a
sourcesarray — the retrieved chunks with file paths and similarity scores. Capture it then if you want citations: sources aren’t persisted, so re-reading the chat later returns them empty.
Scheduled re-indexing
Section titled “Scheduled re-indexing”Content on a file share drifts; a nightly re-run keeps the knowledge base current. Pair this with cron:
import time, requests
BASE = "https://dashboard.insightai.pro/api/v1"PIPELINE = "<pipeline_id>"
session = requests.Session()session.post(f"{BASE}/signin", json={"email": "svc@example.com", "password": "…"}).raise_for_status()
r = session.post(f"{BASE}/data_pipelines/{PIPELINE}/ingest")if r.status_code == 409: raise SystemExit("a run is already in progress")r.raise_for_status()
while True: s = session.get(f"{BASE}/data_pipelines/{PIPELINE}/ingest/status").json() if s["status"] == "completed": print(f"done: {s['entities_processed']} files indexed") break if s["status"] == "failed": raise SystemExit(f"failed: {s['error_message']}") time.sleep(10)Remember each run rebuilds the collection from scratch — schedule runs when a briefly incomplete index is acceptable, and don’t overlap pipelines that share a collection (they shouldn’t share one at all).
Wiring Insight AI into an AI agent
Section titled “Wiring Insight AI into an AI agent”The chat endpoint makes Insight AI a natural tool for an agent: a “company knowledge” function the agent can call when a task needs internal context. The pattern:
- Expose one function to your agent, e.g.
search_company_knowledge(question: str) -> str, implemented exactly likeask()above with a fresh chat per call (stateless) or a persistentchat_idper agent session (conversational memory on the Insight side). - Describe it honestly in the tool description: “Answers questions
using the organization’s indexed documents (policies, reports, shared
drives).” Agents make better call decisions when the description
matches reality. If your tool surfaces the
sourcesarray alongside the answer, say so — file paths and similarity scores give the agent something to cite and a way to judge retrieval quality. - Pick a capable model for the
model_name— the quality of tool results is bounded by the model answering them. - Treat answers as evidence, not ground truth. Retrieval is best-effort similarity search; have the agent verify critical figures against the source documents where it matters.
For heavier integrations (ingest-on-demand, provisioning, model management), everything in the resource map is available — the dashboard has no private APIs.
