Notion integration
The Notion module provides tools for interacting with Notion workspaces, allowing you to search, create, and manage content.
Configuration
Before using Notion tools, you need to set up the following environment variables:
NOTION_API_KEY=your-api-key
NOTION_VERSION=2022-06-28 # Or latest supported version
To get these credentials:
- Create a Notion integration at https://www.notion.so/my-integrations
- Copy the integration token (API key)
- Share the pages/databases you want to access with your integration
Available tools
Notion-search
Searches all titles of pages and databases in Notion that have been shared with the integration.
Parameters
-
query
(string, optional)- The search query to find in page/database titles
- Query should focus on subject matter likely to be in titles
- If not provided, returns all accessible pages/databases
- Case-insensitive
- Supports partial matches
-
filter
(object, optional)- Filter to only return specific types of content
- Properties:
value
: Type of content to filter- "page": Only return pages
- "database": Only return databases
property
: Must be "object"
-
start_cursor
(string, optional)- Cursor for pagination
- Use to fetch next page of results
- Obtained from previous search response
-
page_size
(integer, optional)- Number of results to return
- Default: 100
- Range: 1-100
- Use with start_cursor for pagination
Response format
The tool returns a dictionary with:
results
: Array of found pages/databases- Each result includes:
id
: Notion page/database IDtitle
: Content titleurl
: Notion URLobject
: Type ("page" or "database")created_time
: Creation timestamplast_edited_time
: Last edit timestamp
- Each result includes:
next_cursor
: Cursor for next page (if more results)has_more
: Boolean indicating if more results exist
Example Usage
from tyler.models import Agent, Thread, Message
# Create an agent with Notion tools
agent = Agent(
model_name="gpt-4o",
purpose="To help with Notion content",
tools=["notion"]
)
# Create a thread with a search request
thread = Thread()
message = Message(
role="user",
content="Find all project planning documents in Notion"
)
thread.add_message(message)
# Process the thread - agent will use notion-search tool
processed_thread, new_messages = await agent.go(thread)
Best practices
-
Search Optimization
- Use specific search terms
- Consider title patterns
- Handle pagination for large results
-
Error Handling
- Check API responses
- Handle rate limits
- Validate permissions
-
Content Access
- Share pages explicitly
- Manage integration permissions
- Track accessed content
-
Performance
- Use appropriate page sizes
- Implement pagination
- Cache results when appropriate
Common use cases
-
Content Discovery
- Find relevant documents
- Locate databases
- Search project resources
-
Content Organization
- Audit page access
- Track document changes
- Manage workspaces
-
Integration
- Connect with other tools
- Automate workflows
- Sync content
Security considerations
-
Access Control
- Share only necessary content
- Review integration permissions
- Monitor access patterns
-
API Keys
- Secure storage of keys
- Regular key rotation
- Access logging
-
Content Security
- Validate content access
- Handle sensitive data
- Respect workspace boundaries
Limitations
-
API Constraints
- Rate limits apply
- Maximum page size of 100
- Some operations require specific permissions
-
Search Limitations
- Title-only search
- No full-text search
- Limited filter options
-
Integration Scope
- Access limited to shared content
- Some operations restricted
- Workspace boundaries enforced
Error handling
Common issues and solutions:
-
Authentication Errors
- Verify API key is set
- Check environment variables
- Validate API version
-
Access Denied
- Confirm page is shared
- Check integration permissions
- Verify workspace access
-
Rate Limiting
- Implement backoff
- Monitor usage
- Optimize requests