Notion

Guide to use notion tool on your AI agent using Vity Toolkit

Automate workspace queries, pages, databases, blocks, and comments inside Notion.

Details

Supported Auth Type

AuthType.API_KEY

Quick Start

1

Install the package.

npm install vity-toolkit langchain @langchain/openai
2

Initialize 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.

3

Add the tool.

const tools = toolKit.getTools({ apps: [App.NOTION] });
4

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,
});
5

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
Description
Action.NOTION_SEARCH

Search across Notion pages and databases using Notion API.

Action.NOTION_GET_PAGE

Fetch details of a Notion page by page ID.

Action.NOTION_GET_DATABASE

Fetch a Notion database by ID.

Action.NOTION_QUERY_DATABASE

Query a Notion database with optional filter/sorts.

Action.NOTION_CREATE_PAGE

Create a Notion page in a database or under a page.

Action.NOTION_APPEND_BLOCK_CHILDREN

Append children blocks to a Notion block.

Action.NOTION_RETRIEVE_BLOCK

Retrieve a Notion block by ID.

Action.NOTION_RETRIEVE_BLOCK_CHILDREN

Retrieve children of a Notion block.

Action.NOTION_LIST_USERS

List Notion users.

Action.NOTION_LIST_COMMENTS

List comments for a discussion or block (by block_id).

Action.NOTION_CREATE_COMMENT

Create a comment on a page or discussion.

Last updated