Notion
Guide to use notion tool on your AI agent using Vity Toolkit
Details
AuthType.API_KEYQuick Start
1
npm install vity-toolkit langchain @langchain/openai2
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,
});3
const tools = toolKit.getTools({ apps: [App.NOTION] });4
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,
});5
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
Description
Action.NOTION_SEARCHAction.NOTION_GET_PAGEAction.NOTION_GET_DATABASEAction.NOTION_QUERY_DATABASEAction.NOTION_CREATE_PAGEAction.NOTION_APPEND_BLOCK_CHILDRENAction.NOTION_RETRIEVE_BLOCKAction.NOTION_RETRIEVE_BLOCK_CHILDRENAction.NOTION_LIST_USERSAction.NOTION_LIST_COMMENTSAction.NOTION_CREATE_COMMENTLast updated