joaomorossini commited on
Commit
51e2c4c
·
1 Parent(s): df8c722

Add DeleteTaskTool for archiving tasks in Notion and update NotionProjectAgent

Browse files
agency_ai_demo/agents/NotionProjectAgent/NotionProjectAgent.py CHANGED
@@ -5,6 +5,7 @@ from .tools.GetTasks import GetTasksTool
5
  from .tools.GetTask import GetTaskTool
6
  from .tools.CreateTask import CreateTaskTool
7
  from .tools.UpdateTask import UpdateTaskTool
 
8
 
9
 
10
  class NotionProjectAgent(Agent):
@@ -24,7 +25,13 @@ class NotionProjectAgent(Agent):
24
  instructions="./instructions.md",
25
  files_folder="./files",
26
  schemas_folder="./schemas",
27
- tools=[GetTasksTool, GetTaskTool, CreateTaskTool, UpdateTaskTool],
 
 
 
 
 
 
28
  tools_folder="./tools",
29
  model="gpt-4o",
30
  temperature=0.3,
 
5
  from .tools.GetTask import GetTaskTool
6
  from .tools.CreateTask import CreateTaskTool
7
  from .tools.UpdateTask import UpdateTaskTool
8
+ from .tools.DeleteTask import DeleteTaskTool
9
 
10
 
11
  class NotionProjectAgent(Agent):
 
25
  instructions="./instructions.md",
26
  files_folder="./files",
27
  schemas_folder="./schemas",
28
+ tools=[
29
+ GetTasksTool,
30
+ GetTaskTool,
31
+ CreateTaskTool,
32
+ UpdateTaskTool,
33
+ DeleteTaskTool,
34
+ ],
35
  tools_folder="./tools",
36
  model="gpt-4o",
37
  temperature=0.3,
agency_ai_demo/agents/NotionProjectAgent/instructions.md CHANGED
@@ -21,7 +21,6 @@ Use these IDs unless specified otherwise
21
  - Status
22
  - Priority
23
  - Due Date
24
- - Assigned To
25
 
26
  ## WORKFLOWS
27
 
 
21
  - Status
22
  - Priority
23
  - Due Date
 
24
 
25
  ## WORKFLOWS
26
 
agency_ai_demo/agents/NotionProjectAgent/tools/DeleteTask.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from dotenv import load_dotenv
3
+ from agency_swarm.tools import BaseTool
4
+ from pydantic import Field
5
+ from typing import Dict, Any
6
+
7
+ load_dotenv()
8
+
9
+ notion_integration_secret = os.getenv("NOTION_INTEGRATION_SECRET")
10
+
11
+
12
+ class DeleteTaskTool(BaseTool):
13
+ """
14
+ Tool for deleting (archiving) a task (page) in Notion.
15
+ In Notion, deleting a page is done by archiving it.
16
+ This tool archives the specified page, making it disappear from its parent database.
17
+ """
18
+
19
+ # Add example_field with a default value to satisfy BaseTool validation
20
+ example_field: str = Field(
21
+ default="notion_delete_task",
22
+ description="Identifier for this tool. Can be left at its default value.",
23
+ )
24
+
25
+ page_id: str = Field(
26
+ ...,
27
+ description="The ID of the Notion page (task) to delete/archive. This is a required field.",
28
+ )
29
+
30
+ def run(self) -> Dict[str, Any]:
31
+ """
32
+ Delete (archive) a Notion page (task) with the specified ID.
33
+
34
+ Returns:
35
+ dict: The JSON response from the Notion API confirming the page has been archived.
36
+ """
37
+ import requests
38
+
39
+ # Set up the API endpoint
40
+ url = f"https://api.notion.com/v1/pages/{self.page_id}"
41
+
42
+ # Set up the headers
43
+ headers = {
44
+ "Authorization": f"Bearer {os.getenv('NOTION_INTEGRATION_SECRET')}",
45
+ "Notion-Version": "2022-06-28",
46
+ "Content-Type": "application/json",
47
+ }
48
+
49
+ # Prepare the request body - to archive a page, set 'archived' to true
50
+ data = {"archived": True}
51
+
52
+ # Make the request (PATCH method for updates, including archiving)
53
+ response = requests.patch(url, headers=headers, json=data)
54
+
55
+ # Return the JSON response
56
+ return response.json()