Wrap the SDK read surface as model tools so an LLM can answer from Coconut with page-path citations. A terminal REPL where the model can list pages, read markdown, search content, inspect record types, and query records.
View source
Chat with a space
Wrap the SDK read surface as model tools so an LLM can answer from Coconut with page-path citations. A terminal REPL where the model can list pages, read markdown, search content, inspect record types, and query records.
Read the codeBefore you run it
Run Write back first for the sample deal questions.
Set ANTHROPIC_API_KEY or sign in with ant auth login.
Optionally set CHAT_MODEL when you want a model other than the default.
What it does
Create tools for list_pages, read_page, search_pages, list_record_types, and query_records.
Prime the system message with the current space overview.
Send model tool requests through SDK calls.
Return every tool result in one user message.
Ask the model to cite page paths instead of answering from memory.
Core SDK calls
These are intentionally smaller than the source files. They show the backend shape to copy first.
Tool handlers over Coconut
async function runTool(name: string, input: Record<string, unknown>) {
switch (name) {
case "search_pages":
return coco.search.text(String(input.query), { space: "demo", limit: 10 });
case "list_record_types":
return coco.records.types("demo");
case "read_page":
return coco.pages.getMarkdown(String(input.path));
}
}Use structured state when the question is about state
const hotDeals = await coco.records.query("demo", "deal-memo", {
filters: [{ key: "stage", op: "eq", value: "diligence" }],
orderBy: "conviction-score",
order: "desc",
});CLI companion
Use the CLI to inspect or exercise the same backend surface from a terminal while your app code uses the SDK.
coco search 'management call' --space demo
coco query --filter stage=diligence --filter 'conviction-score>=0.7' --space demo --order-by conviction-score --desc