Write a smolagent that can help me manage my Google Tasks
- User
Write a smolagent that can help me manage my Google Tasks
Assistant
Here's a smolagent implementation to manage Google Tasks using Hugging Face's smolagent framework and Google's Tasks API:
from smolagent import Agent, Model, Tool import google.auth from googleapiclient.discovery import build # Configure Google Tasks API SCOPES = ['https://www.googleapis.com/auth/tasks'] creds, project = google.auth.default(scopes=SCOPES) service = build('tasks', 'v1', credentials=creds) class GoogleTasksModel(Model): def __init__(self): super().__init__() self.service = service def create_task(self, title, due_date=None): """Create new task with optional due date""" body = {'title': title} if due_date: body['due'] = due_date return self.service.tasks().insert(tasklist='@default', body=body).execute() def list_tasks(self): """List all tasks in default tasklist""" return self.service.tasks().list(tasklist='@default').execute() def update_task(self, task_id, title=None, due_date=None): """Update existing task""" body = {} if title: body['title'] = title if due_date: body['due'] = due_date return self.service.tasks().update(tasklist='@default', task=task_id, body=body).execute() def delete_task(self, task_id): """Delete task""" return self.service.tasks().delete(tasklist='@default', task=task_id).execute() class GoogleTasksAgent(Agent): def __init__(self): super().__init__() self.model = GoogleTasksModel() self.tools = [ Tool("create_task", self.model.create_task, ["title", "due_date"]), Tool("list_tasks", self.model.list_tasks), Tool("update_task", self.model.update_task, ["task_id", "title", "due_date"]), Tool("delete_task", self.model.delete_task, ["task_id"]) ] def act(self, observation): """Process user input and execute appropriate action""" if "create task" in observation.lower(): return self.run_tool("create_task", title=observation.split("create task ")[1]) elif "list tasks" in observation.lower(): return self.run_tool("list_tasks") elif "update task" in observation.lower(): # Parse task ID and new details parts = observation.split("update task ") task_id = parts[1].split(" to ") new_title = parts[1].split(" to ")[1] if " to " in parts[1] else None return self.run_tool("update_task", task_id=task_id, title=new_title) elif "delete task" in observation.lower(): task_id = observation.split("delete task ")[1] return self.run_tool("delete_task", task_id=task_id) else: return "I didn't understand that command. Try 'create task [title]', 'list tasks', 'update task [id] to [new title]', or 'delete task [id]'" # Initialize and run agent agent = GoogleTasksAgent() print(agent.act("Create task Buy groceries")) print(agent.act("List tasks"))Key Features [1][5][8]:
- Task Creation: Automatically generate tasks from natural language input
- Task Management: Update due dates, titles, and delete tasks
- Task Listing: Retrieve all tasks in default tasklist
- API Integration: Direct access to Google Tasks API endpoints
Setup Requirements [11]:
- Enable Google Tasks API in Google Cloud Console
- Create OAuth credentials with
https://www.googleapis.com/auth/tasksscope - Install required packages:
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
Usage Examples:
# Create task with due date agent.act("Create task Submit report by 2025-04-15") # Update task title agent.act("Update task 1234567890 to Finalize Q1 budget") # Delete task agent.act("Delete task 9876543210")Deployment Options [2]:
- Local Execution: Run directly in Python environment
- Vertex AI: Deploy using Reasoning Engine for scalable operations
- API Service: Expose as REST endpoint for programmatic access
Limitations [5][11]:
- Requires OAuth authentication
- Limited to default tasklist
- No support for subtasks
- API rate limits apply
This implementation provides basic task management capabilities. For advanced features like prioritization or team collaboration, consider integrating with additional tools like Sembly AI [1] or Make.com workflows [13].
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.