Notion
Guide to use notion tool on your AI agent using Vity Toolkit
Automate workspace queries, pages, databases, blocks, and comments inside Notion.
Supported Auth Type
AuthType.API_KEYQuick Start
Install the package.
npm install vity-toolkit langchain @langchain/openaiInitialize Vity Toolkit and Langchain.
import { ChatOpenAI } from "@langchain/openai";
import { App, LangchainToolkit } from "vity-toolkit";
import { createOpenAIFunctionsAgent, AgentExecutor } from "langchain/agents";
import { ChatPromptTemplate } from "@langchain/core/prompts";
const P = (globalThis as any).process;
const model = new ChatOpenAI({ model: "gpt-4o" });
const toolKit = new LangchainToolkit({
userPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
appPrivateKey: P?.env?.SOLANA_PRIVATE_KEY,
});Make sure that you already have integrated and connected the app.
Add the tool.
const tools = toolKit.getTools({ apps: [App.NOTION] });Define the Agent.
const PARENT_PAGE_ID = P?.env?.NOTION_PARENT_PAGE_ID || "your-parent-page-id";
const prompt = ChatPromptTemplate.fromMessages([
["system", `You are an AI agent responsible for taking actions on Notion on users' behalf.
You need to take action on Notion using Notion APIs. Use correct tools from the given tool-set.`],
["placeholder", "{chat_history}"],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"],
]);
const agent = createToolCallingAgent({ llm: model, tools, prompt });
const agentExecutor = new AgentExecutor({
agent,
tools,
verbose: false,
});Execute the Agent.
const response = await agentExecutor.invoke({ input: `Create a new page called 'Product Roadmap' under page ID: ${PARENT_PAGE_ID}. On that page:
- Add a section titled 'Weekly roadmap summary'.
- Add a short bullet list of this week's key tasks (use simple placeholders if needed: title + due date).
- Add a brief paragraph with priorities for the week in plain language.
Keep it short and clear. No need to search my workspace or use any existing pages.
Also give me the link to open and view the page in Notion.` });
console.log(response);Supported Actions
Action.NOTION_SEARCHSearch across Notion pages and databases using Notion API.
Action.NOTION_GET_PAGEFetch details of a Notion page by page ID.
Action.NOTION_GET_DATABASEFetch a Notion database by ID.
Action.NOTION_QUERY_DATABASEQuery a Notion database with optional filter/sorts.
Action.NOTION_CREATE_PAGECreate a Notion page in a database or under a page.
Action.NOTION_APPEND_BLOCK_CHILDRENAppend children blocks to a Notion block.
Action.NOTION_RETRIEVE_BLOCKRetrieve a Notion block by ID.
Action.NOTION_RETRIEVE_BLOCK_CHILDRENRetrieve children of a Notion block.
Action.NOTION_LIST_USERSList Notion users.
Action.NOTION_LIST_COMMENTSList comments for a discussion or block (by block_id).
Action.NOTION_CREATE_COMMENTCreate a comment on a page or discussion.
Last updated