Examples
Build a stateful, knowledge, or web-enabled assistant.
#Stateful assistant
Architecture: Continue a thread → extract selected memory → reuse it across threads.
await elektric.chat({ userId:"user_123", conversationId:"thread_a", message:"Remember that my project is Orion." });
const answer = await elektric.chat({ userId:"user_123", conversationId:"thread_b", message:"What project am I building?" });
console.log(answer.message);Expected result: The second response can use the selected fact when Conversation and Memory are enabled.
#Knowledge assistant
Architecture: Upload material → wait for ready → ask a grounded question → delete when finished.
import { readFile } from "node:fs/promises";
const source = await elektric.knowledge.add({ file: await readFile("handbook.md"), name:"handbook.md", mediaType:"text/markdown" });
let current = source;
while (current.status === "processing") {
await new Promise(resolve => setTimeout(resolve, 2000));
current = await elektric.knowledge.get({ sourceId: source.id });
}
const answer = await elektric.chat({ userId:"user_123", conversationId:"handbook_1", message:"Summarize the vacation policy." });
console.log(answer.message);Expected result: The answer is grounded in ready project Knowledge.
#Web-enabled agent
Architecture: Enable Web Search → define a function → validate, execute, and return the result.
const weather = elektric.tool({ name:"get_weather", description:"Return current weather", inputSchema:{ type:"object", properties:{city:{type:"string"}}, required:["city"] } });
const response = await elektric.chat({ message:"Check current sources, then compare Boston weather.", tools:[weather] });
// Validate arguments, authorize, execute, and return the tool result.Expected result: The model may request the function; your application executes it.
Authentication →Standard errors →Pricing & Billing →Limits →