Spaces:
Runtime error
Runtime error
Commit ·
30c27ae
1
Parent(s): f2389eb
Add GetTaskTool for retrieving tasks from Notion API
Browse files
agency_ai_demo/agents/NotionProjectAgent/tools/GetTask.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from dotenv import load_dotenv
|
| 3 |
+
from agency_swarm.tools import BaseTool
|
| 4 |
+
from pydantic import Field
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
notion_integration_secret = os.getenv("NOTION_INTEGRATION_SECRET")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class GetTaskTool(BaseTool):
|
| 12 |
+
"""
|
| 13 |
+
Tool for retrieving a specific task (page) from Notion.
|
| 14 |
+
This tool fetches all properties of a specific task using its page ID.
|
| 15 |
+
Note that page content (blocks) is not retrieved, only the page properties.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
# Add example_field with a default value to satisfy BaseTool validation
|
| 19 |
+
example_field: str = Field(
|
| 20 |
+
default="notion_task",
|
| 21 |
+
description="Identifier for this tool. Can be left at its default value.",
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
page_id: str = Field(
|
| 25 |
+
...,
|
| 26 |
+
description="The ID of the Notion page (task) to retrieve. This is a required field.",
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
def run(self):
|
| 30 |
+
"""
|
| 31 |
+
Retrieve a Notion page (task) by its ID.
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
dict: The JSON response from the Notion API containing the page properties.
|
| 35 |
+
"""
|
| 36 |
+
import requests
|
| 37 |
+
|
| 38 |
+
# Set up the API endpoint
|
| 39 |
+
url = f"https://api.notion.com/v1/pages/{self.page_id}"
|
| 40 |
+
|
| 41 |
+
# Set up the headers
|
| 42 |
+
headers = {
|
| 43 |
+
"Authorization": f"Bearer {os.getenv('NOTION_INTEGRATION_SECRET')}",
|
| 44 |
+
"Notion-Version": "2022-06-28",
|
| 45 |
+
"Content-Type": "application/json",
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# Make the request
|
| 49 |
+
response = requests.get(url, headers=headers)
|
| 50 |
+
|
| 51 |
+
# Return the JSON response
|
| 52 |
+
return response.json()
|