Full Flow Guide
This guide walks through the four major workflows in the Imbrace SDK from start to finish. Each section is self-contained — follow them in order or jump to the one you need.
1. Create an AI Agent and Start Chatting
-
Initialize the client
import { ImbraceClient } from "@imbrace/sdk"const client = new ImbraceClient({accessToken: process.env.IMBRACE_ACCESS_TOKEN,env: "stable",})import osfrom imbrace import ImbraceClientclient = ImbraceClient(access_token=os.environ["IMBRACE_ACCESS_TOKEN"],env="stable",)import { ImbraceClient } from "@imbrace/sdk"const client = new ImbraceClient({apiKey: process.env.IMBRACE_API_KEY,organizationId: process.env.IMBRACE_ORGANIZATION_ID,env: "stable",})import osfrom imbrace import ImbraceClientclient = ImbraceClient(api_key=os.environ["IMBRACE_API_KEY"],organization_id=os.environ.get("IMBRACE_ORGANIZATION_ID"),env="stable",) -
Create an AI agent
workflow_namemust be unique within your organization.const agent = await client.chatAi.createAiAgent({name: "Support Bot",workflow_name: "support_bot_v1",description: "Handles tier-1 customer support queries",instructions: "You are a helpful support agent. Be concise and friendly.",provider_id: "system", // use the org's default LLM providermodel_id: "Default", // routes to the org's configured default modelstreaming: true, // emit text-delta SSE events (see Aside below)})const aiAgentId = agent.id // UUID — use this for all subsequent callsconsole.log("AI agent created:", aiAgentId)agent = client.chat_ai.create_ai_agent({"name": "Support Bot","workflow_name": "support_bot_v1","description": "Handles tier-1 customer support queries","instructions": "You are a helpful support agent. Be concise and friendly.","provider_id": "system", # use the org's default LLM provider"model_id": "Default", # routes to the org's configured default model"streaming": True, # emit text-delta SSE events (see Aside below)})ai_agent_id = agent["id"]print("AI agent created:", ai_agent_id)provider_idandmodel_idare optional — the SDK auto-fills{ provider_id: "system", model_id: "Default" }when omitted."Default"routes to whatever the org has configured as its system default model and is the org-portable choice. Pass them explicitly to override:provider_id: "<uuid>"to pin a custom LLM provider, ormodel_id: "gpt-4o"etc. — but a literal model name only works in orgs whosesystemprovider actually exposes it. List your org’s models withclient.ai.listModels()(TypeScript) /client.ai.list_models()(Python) before hardcoding. -
Stream a chat response using the AI agent
Use
streamChatText/stream_chat_text— it wrapsstreamChat, parses the SSE event stream, and yields plain text chunks. Assumes the agent was created withstreaming: true(see the Aside in step 2).for await (const chunk of client.aiAgent.streamChatText({assistant_id: aiAgentId,messages: [{ role: "user", content: "How do I reset my password?" }],// id is the session UUID — reuse it to maintain conversation history.// If omitted, a new UUID is auto-generated each call.})) {process.stdout.write(chunk)}for chunk in client.ai_agent.stream_chat_text({"assistant_id": ai_agent_id,"messages": [{"role": "user", "content": "How do I reset my password?"}],# id is the session UUID — reuse it to maintain conversation history.# If omitted, a new UUID is auto-generated each call.}):print(chunk, end="", flush=True) -
Maintain conversation history (session ID)
Pass the same
id(must be a UUID) across calls to keep context:import { randomUUID } from "crypto"const sessionId = randomUUID()// First messageawait client.aiAgent.streamChat({assistant_id: aiAgentId,id: sessionId,messages: [{ role: "user", content: "What's your refund policy?" }],})// Follow-up — same session, AI agent remembers contextawait client.aiAgent.streamChat({assistant_id: aiAgentId,id: sessionId,messages: [{ role: "user", content: "How long does it take?" }],})import uuidsession_id = str(uuid.uuid4())# First messageclient.ai_agent.stream_chat({"assistant_id": ai_agent_id,"id": session_id,"messages": [{"role": "user", "content": "What's your refund policy?"}],})# Follow-up — same session, AI agent remembers contextclient.ai_agent.stream_chat({"assistant_id": ai_agent_id,"id": session_id,"messages": [{"role": "user", "content": "How long does it take?"}],})
2. Create a Workflow and Bind it to an AI Agent
-
Get your project ID
Copy your Project ID from the Imbrace Dashboard → Workflows, or resolve it programmatically if your org already has flows:
// Option A — hardcode from the Dashboard (recommended for new orgs)const projectId = "your_project_id"// Option B — resolve from an existing flow (throws if org has no flows yet)const projectId = await client.workflows.resolveProjectId()# Option A — hardcode from the Dashboard (recommended for new orgs)project_id = "your_project_id"# Option B — resolve from an existing flow (throws if org has no flows yet)project_id = client.workflows.resolve_project_id() -
Create a new flow
const flow = await client.workflows.createFlow({displayName: "CRM Update on New Lead",projectId,})console.log("Flow created:", flow.id)flow = client.workflows.create_flow(display_name="CRM Update on New Lead",project_id=project_id,)print("Flow created:", flow["id"]) -
Add a Webhook trigger and publish the flow
A freshly created flow is in DRAFT with no trigger — the webhook URL doesn’t exist yet, so
triggerFlowwould 404. Add the Webhook piece as the trigger, then publish:// Set the Webhook piece as the flow's triggerawait client.workflows.applyFlowOperation(flow.id, {type: "UPDATE_TRIGGER",request: {name: "trigger",type: "PIECE_TRIGGER",valid: true,displayName: "Webhook",settings: {pieceName: "@activepieces/piece-webhook",pieceVersion: "0.1.24",triggerName: "catch_webhook",input: { authType: "none" },propertySettings: {},},},})// Publish — flow status flips DISABLED → ENABLED and webhook URL becomes liveawait client.workflows.applyFlowOperation(flow.id, {type: "LOCK_AND_PUBLISH",request: {},})# Set the Webhook piece as the flow's triggerclient.workflows.apply_flow_operation(flow["id"], {"type": "UPDATE_TRIGGER","request": {"name": "trigger","type": "PIECE_TRIGGER","valid": True,"displayName": "Webhook","settings": {"pieceName": "@activepieces/piece-webhook","pieceVersion": "0.1.24","triggerName": "catch_webhook","input": {"authType": "none"},"propertySettings": {},},},})# Publish — DISABLED → ENABLED, webhook URL becomes liveclient.workflows.apply_flow_operation(flow["id"], {"type": "LOCK_AND_PUBLISH","request": {},}) -
Trigger the flow manually with a payload
// Fire and forget (async)await client.workflows.triggerFlow(flow.id, {contact_name: "Jane Smith",email: "jane@example.com",})// Sync trigger — for this to actually return data instead of timing out,// the flow needs a "Return Response" action added via applyFlowOperation// ADD_ACTION (otherwise the gateway waits 30s for a response and gives up).const result = await client.workflows.triggerFlowSync(flow.id, {contact_name: "Jane Smith",email: "jane@example.com",})console.log("Flow result:", result)# Fire and forget (async)client.workflows.trigger_flow(flow["id"], {"contact_name": "Jane Smith","email": "jane@example.com",})# Sync trigger — for this to actually return data instead of timing out,# the flow needs a "Return Response" action added via apply_flow_operation# ADD_ACTION (otherwise the gateway waits 30s and gives up).result = client.workflows.trigger_flow_sync(flow["id"], {"contact_name": "Jane Smith","email": "jane@example.com",})print("Flow result:", result) -
Bind the flow to your AI agent
Open your AI agent in the Imbrace dashboard, go to Tools → Workflows, and attach the flow. The AI agent will be able to trigger it during a conversation when appropriate.
Alternatively, update the AI agent to reference the workflow by name:
await client.chatAi.updateAiAgent(aiAgentId, {name: "Support Bot",workflow_name: "support_bot_v1",workflow_function_call: [{ flow_id: flow.id, description: "Update CRM on new lead" }],})client.chat_ai.update_ai_agent(ai_agent_id, {"name": "Support Bot","workflow_name": "support_bot_v1","workflow_function_call": [{"flow_id": flow["id"], "description": "Update CRM on new lead"}],}) -
Check run history
const { data: runs } = await client.workflows.listRuns({flowId: flow.id,limit: 10,})for (const run of runs) {console.log(run.id, run.status, run.startTime)}res = client.workflows.list_runs(flow_id=flow["id"], limit=10)for run in res.get("data", []):print(run["id"], run.get("status"), run.get("startTime"))
3. Manage Knowledge Hubs and Attach to an AI Agent
Knowledge Hub files and folders live in the data-board service (client.boards). The folder’s _id is what you pass to an AI agent as its knowledge source.
-
Create a folder
const folder = await client.boards.createFolder({name: "Product Documentation",organization_id: process.env.IMBRACE_ORGANIZATION_ID,parent_id: "root",})console.log("Folder ID:", folder._id)folder = client.boards.create_folder({"name": "Product Documentation","organization_id": os.environ.get("IMBRACE_ORGANIZATION_ID"),"parent_id": "root",})print("Folder ID:", folder["_id"]) -
Upload a file to the folder
import { readFileSync } from "fs"const fileBuffer = readFileSync("./docs/faq.pdf")const formData = new FormData()formData.append("file", new Blob([fileBuffer], { type: "application/pdf" }), "faq.pdf")formData.append("folder_id", folder._id)formData.append("organization_id", process.env.IMBRACE_ORGANIZATION_ID ?? "")const uploaded = await client.boards.uploadFile(formData)console.log("File uploaded:", uploaded.file_id)from pathlib import Pathpath = Path("./docs/faq.pdf")files = {"file": (path.name, path.read_bytes(), "application/pdf"),"folder_id": (None, folder["_id"]),"organization_id": (None, os.environ.get("IMBRACE_ORGANIZATION_ID")),}uploaded = client.boards.upload_file(files)print("File uploaded:", uploaded.get("file_id") or uploaded.get("_id")) -
Attach the folder to the AI agent
Pass the folder
_idinfolder_ids— the AI agent retrieves from every file in that folder. Useboard_idsto attach a CRM data-board (its items become a knowledge source — see Resources → Boards & items). The legacyknowledge_hubsfield is deprecated.await client.chatAi.updateAiAgent(aiAgentId, {name: "Support Bot",workflow_name: "support_bot_v1",folder_ids: [folder._id],// board_ids: [boardId], // optional: attach a CRM data-board too})client.chat_ai.update_ai_agent(ai_agent_id, {"name": "Support Bot","workflow_name": "support_bot_v1","folder_ids": [folder["_id"]],# "board_ids": [board_id], # optional: attach a CRM data-board too}) -
Inspect and manage folders and files
// Search foldersconst folders = await client.boards.searchFolders({ q: "Product" })// Get folder with contentsconst contents = await client.boards.getFolderContents(folder._id)console.log("Files:", contents.files?.length)// Rename a folderawait client.boards.updateFolder(folder._id, { name: "Product Docs v2" })// Search files in a folderconst files = await client.boards.searchFiles({ folderId: folder._id })// Delete foldersawait client.boards.deleteFolders({ ids: [folder._id] })# Search foldersfolders = client.boards.search_folders(q="Product")# Get folder with contentscontents = client.boards.get_folder_contents(folder["_id"])print("Files:", len(contents.get("files") or []))# Rename a folderclient.boards.update_folder(folder["_id"], {"name": "Product Docs v2"})# Search files in a folderfiles = client.boards.search_files(folder_id=folder["_id"])# Delete foldersclient.boards.delete_folders([folder["_id"]])
4. Manage Data Boards and Items (CRM Pipelines)
-
Create a board
A board is a CRM pipeline — leads, deals, tasks, or any structured data.
const board = await client.boards.create({name: "Sales Pipeline",description: "Track all active deals",})console.log("Board ID:", board._id)board = client.boards.create(name="Sales Pipeline",description="Track all active deals",)print("Board ID:", board["_id"]) -
Add a custom field
Field types are
ShortText,LongText,Number,Dropdown,Date,Checkbox, etc.createFieldreturns the newly-created field. To inspect all fields on the board, fetch the board separately.await client.boards.createField(board._id, {name: "Company",type: "ShortText",})// Boards auto-create an identifier field — fetch the board to see all fieldsconst boardWithFields = await client.boards.get(board._id) as anyconst identifierField = boardWithFields.fields?.find((f: any) => f.is_identifier)client.boards.create_field(board["_id"], {"name": "Company","type": "ShortText",})# Fetch the board to see all fields (including the auto-created identifier)board_with_fields = client.boards.get(board["_id"])identifier_field = next(f for f in board_with_fields.get("fields", []) if f.get("is_identifier")) -
Create board items (records)
Items use
{ fields: [{ board_field_id, value }] }format:const item = await client.boards.createItem(board._id, {fields: [{ board_field_id: identifierField._id, value: "Acme Corp" },],})console.log("Item ID:", item._id)item = client.boards.create_item(board["_id"], {"fields": [{"board_field_id": identifier_field["_id"], "value": "Acme Corp"},],})print("Item ID:", item["_id"]) -
List and search items
// Paginate through itemsconst { data: items } = await client.boards.listItems(board._id, { limit: 20, skip: 0 })// Full-text searchconst { data: results } = await client.boards.search(board._id, {q: "Acme",limit: 10,})# Paginate through itemsitems = client.boards.list_items(board["_id"], limit=20, skip=0)# Full-text searchresults = client.boards.search(board["_id"], q="Acme", limit=10) -
Update and delete items
Update uses
{ data: [{ key, value }] }(note:key, notboard_field_id):await client.boards.updateItem(board._id, item._id, {data: [{ key: identifierField._id, value: "Acme Corp — Closed Won" }],})await client.boards.deleteItem(board._id, item._id)client.boards.update_item(board["_id"], item["_id"], {"data": [{"key": identifier_field["_id"], "value": "Acme Corp — Closed Won"}],})client.boards.delete_item(board["_id"], item["_id"]) -
Export to CSV
const csv = await client.boards.exportCsv(board._id)// csv is a string — write to a file or send as a downloadcsv = client.boards.export_csv(board["_id"])# csv is a str — write to a file or send as a download
Next steps
- Resources → — per-namespace method reference for all four workflows
- AI Agent → — deeper dive into
streamChat, embeddings, and parquet - Workflows → — flow operations, MCP servers, and run history
- Document AI → — AI-powered document parsing and extraction
- Data Board → — board fields, items, search, segments, and CSV