> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getbindu.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 1.6 Notion Agent

> Agent with Notion workspace integration

Agent with Notion workspace integration.

## Code

```python theme={null}
import os
from dotenv import load_dotenv
from bindu.penguin.bindufy import bindufy
from agno.agent import Agent
from agno.models.openrouter import OpenRouter
from notion_client import Client

load_dotenv()

NOTION_API_KEY = os.getenv("NOTION_API_KEY")
NOTION_DATABASE_ID = os.getenv("NOTION_DATABASE_ID")
OPENROUTER_API_KEY = os.getenv("OPENROUTER_API_KEY")

notion = Client(auth=NOTION_API_KEY)

def create_notion_page(title: str, content: str):
    """Create a page in Notion database"""
    return notion.pages.create(
        parent={"database_id": NOTION_DATABASE_ID},
        properties={"Name": {"title": [{"text": {"content": title}}]}},
        children=[{
            "object": "block",
            "type": "paragraph",
            "paragraph": {"text": [{"type": "text", "text": {"content": content}}]},
        }],
    )

def search_notion(query: str):
    """Search pages in Notion database"""
    return notion.databases.query(
        database_id=NOTION_DATABASE_ID,
        filter={
            "or": [
                {"property": "Name", "title": {"contains": query}},
                {"property": "Content", "rich_text": {"contains": query}},
            ]
        }
    )

agent = Agent(
    instructions="You are a Notion assistant. Use tools to create and search Notion pages.",
    model=OpenRouter(id="openai/gpt-oss-120b", api_key=OPENROUTER_API_KEY),
    tools=[create_notion_page, search_notion],
)

config = {
    "author": "paras.chamoli@gmail.com",
    "name": "agno-notion-agent",
    "description": "Notion assistant agent (OpenRouter)",
    "deployment": {
        "url": "http://localhost:3773",
        "expose": True,
        "cors_origins": ["http://localhost:5173"]
    },
}

def handler(messages: list[dict[str, str]]):
    return agent.run(input=messages)

bindufy(config, handler)
```

## How It Works

**Custom Tools**

* `create_notion_page()`: Creates pages in Notion
* `search_notion()`: Searches database entries
* Tools passed to agent via `tools` parameter

**Notion Client**

* `notion_client` library for API access
* Authenticated with `NOTION_API_KEY`
* Targets specific database via `NOTION_DATABASE_ID`

**Environment Variables**

* `NOTION_API_KEY`: Your Notion integration token
* `NOTION_DATABASE_ID`: Target database ID
* `OPENROUTER_API_KEY`: LLM access

## Dependencies

```bash theme={null}
uv init
uv add bindu agno python-dotenv notion-client
```

## Environment Setup

Create `.env` file:

```bash theme={null}
NOTION_API_KEY=secret_xxx
NOTION_DATABASE_ID=xxx
OPENROUTER_API_KEY=sk-or-v1-xxx
```

## Setup

1. Create Notion integration at [notion.so/my-integrations](https://www.notion.so/my-integrations)
2. Share database with integration
3. Copy database ID from URL

## Run

```bash theme={null}
uv run agno_notion_agent.py
```

**Examples:**

* "Create a page titled 'Meeting Notes' with content 'Discussed Q1 goals'"
* "Add a task to my Notion database: 'Review project documentation'"
* "Create a database entry for 'Client Meeting' with status 'In Progress'"

## Example API Calls

<AccordionGroup>
  <Accordion title="Message Send Request">
    ```json theme={null}
    {
      "jsonrpc": "2.0",
      "method": "message/send",
      "params": {
        "message": {
          "role": "user",
          "kind": "message",
          "messageId": "9f11c870-5616-49ad-b187-d93cbb100001",
          "contextId": "9f11c870-5616-49ad-b187-d93cbb100002",
          "taskId": "9f11c870-5616-49ad-b187-d93cbb100003",
          "parts": [
            {
              "kind": "text",
              "text": "Create a page titled 'Meeting Notes' with content 'Discussed Q1 goals'"
            }
          ]
        },
        "configuration": {
          "acceptedOutputModes": ["application/json"]
        }
      },
      "id": "9f11c870-5616-49ad-b187-d93cbb100003"
    }
    ```
  </Accordion>

  <Accordion title="Task get Request">
    ```json theme={null}
    {
      "jsonrpc": "2.0",
      "method": "tasks/get",
      "params": {
        "taskId": "9f11c870-5616-49ad-b187-d93cbb100003"
      },
      "id": "9f11c870-5616-49ad-b187-d93cbb100004"
    }
    ```
  </Accordion>
</AccordionGroup>

## Frontend Setup

```bash theme={null}
# Clone the Bindu repository
git clone https://github.com/GetBindu/Bindu

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start frontend development server
npm run dev
```

Open [http://localhost:5173](http://localhost:5173) and try to chat with Notion agent
