from gaia import Agent, DatabaseMixin, tool
class NotesAgent(Agent, DatabaseMixin):
"""Agent that manages personal notes."""
def __init__(self, db_path: str = "data/notes.db", **kwargs):
super().__init__(**kwargs)
self.init_db(db_path)
# Create schema on first run
if not self.table_exists("notes"):
self.execute("""
CREATE TABLE notes (
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
content TEXT,
created_at TEXT DEFAULT CURRENT_TIMESTAMP
)
""")
def _get_system_prompt(self) -> str:
return """You are a notes assistant. You can:
- Create new notes with add_note
- List all notes with list_notes
- Search notes with search_notes
- Delete notes with delete_note
"""
def _register_tools(self):
agent = self
@tool
def add_note(title: str, content: str = "") -> dict:
"""Create a new note."""
note_id = agent.insert("notes", {"title": title, "content": content})
return {"id": note_id, "message": f"Created note: {title}"}
@tool
def list_notes() -> dict:
"""List all notes."""
notes = agent.query("SELECT id, title, created_at FROM notes ORDER BY created_at DESC")
return {"notes": notes, "count": len(notes)}
@tool
def search_notes(query: str) -> dict:
"""Search notes by title or content."""
notes = agent.query(
"SELECT * FROM notes WHERE title LIKE :q OR content LIKE :q",
{"q": f"%{query}%"}
)
return {"results": notes, "count": len(notes)}
@tool
def delete_note(note_id: int) -> dict:
"""Delete a note by ID."""
count = agent.delete("notes", "id = :id", {"id": note_id})
return {"deleted": count > 0}
# Usage
if __name__ == "__main__":
agent = NotesAgent()
# Agent is ready to use with chat interface