Skip to content

Self-hosted AI workspace.

Python

Expose manage_notes via native function calling (#759)

tanmayraut45f2d2649f47eb
diff --git a/src/agent_loop.py b/src/agent_loop.py
index ae6289103..b72a855ab 100644
--- a/src/agent_loop.py
+++ b/src/agent_loop.py
@@ -457,6 +457,11 @@ _API_HOSTS = frozenset([
"api.together.xyz", "api.fireworks.ai",
"api.perplexity.ai", "api.x.ai",
"ollama.com",
+ # Local OpenAI-compatible endpoints (llama.cpp, vLLM, LM Studio, etc.).
+ # Without these, `_is_api_model` falls back to keyword sniffing on the
+ # model name, so well-behaved local servers don't get native tool
+ # schemas and the agent silently degrades to fenced-block parsing.
+ "localhost", "127.0.0.1", "host.docker.internal",
])
_MCP_KEYWORDS = frozenset(["browse", "browser", "website", "calendar", "event", "email",
"gmail", "screenshot", "navigate", "click", "miniflux", "rss", "feed"])
diff --git a/src/tool_implementations.py b/src/tool_implementations.py
index e5b05241f..09b0306f1 100644
--- a/src/tool_implementations.py
+++ b/src/tool_implementations.py
@@ -1853,7 +1853,13 @@ async def do_manage_notes(content: str, owner: Optional[str] = None) -> Dict:
title = text_raw.strip()
elif not content_raw and text_raw:
content_raw = text_raw
- items_raw = args.get("items")
+ # Accept both `items` (legacy/internal field) and `checklist_items`
+ # (the schema-exposed name used by native function calls). Models
+ # following the schema emit `checklist_items`; older code paths
+ # and direct API callers still use `items`.
+ items_raw = args.get("checklist_items")
+ if items_raw is None:
+ items_raw = args.get("items")
items_json = json.dumps(items_raw) if items_raw is not None else None
note_type = args.get("note_type", "checklist" if items_raw else "note")
# Accept natural-language due_date ("tomorrow at 1pm") in
@@ -1918,8 +1924,11 @@ async def do_manage_notes(content: str, owner: Optional[str] = None) -> Dict:
for field in ("title", "content", "note_type", "color", "label", "due_date"):
if field in args and args[field] is not None:
setattr(note, field, args[field])
- if "items" in args and args["items"] is not None:
- note.items = json.dumps(args["items"])
+ new_items = args.get("checklist_items")
+ if new_items is None:
+ new_items = args.get("items")
+ if new_items is not None:
+ note.items = json.dumps(new_items)
flag_modified(note, "items")
if "pinned" in args:
note.pinned = args["pinned"]
diff --git a/src/tool_schemas.py b/src/tool_schemas.py
index f0a69e002..8e10122ab 100644
--- a/src/tool_schemas.py
+++ b/src/tool_schemas.py
@@ -448,6 +448,41 @@ FUNCTION_TOOL_SCHEMAS = [
}
}
},
+ {
+ "type": "function",
+ "function": {
+ "name": "manage_notes",
+ "description": "Manage notes and checklists (Google Keep-style): list, add, update, delete, toggle_item. IMPORTANT: For to-do lists / checklists, set note_type='checklist' and pass the items as the `checklist_items` array — do NOT serialize them into `content` as plain text. For freeform notes, use note_type='note' and put the body in `content`. `due_date` accepts natural language like 'tomorrow at 9am' (parsed in the user's timezone) and fires a notification — do not also create a calendar event for the same reminder.",
+ "parameters": {
+ "type": "object",
+ "properties": {
+ "action": {"type": "string",
+ "enum": ["list", "add", "update", "delete", "toggle_item"],
+ "description": "The action to perform"},
+ "id": {"type": "string", "description": "Note id (for update/delete/toggle_item); 8-char prefix is fine"},
+ "title": {"type": "string", "description": "Note title (for add/update)"},
+ "content": {"type": "string", "description": "Freeform body text. Use this for note_type='note'. Do NOT use this for checklists — pass `checklist_items` instead."},
+ "note_type": {"type": "string", "enum": ["note", "checklist"],
+ "description": "'note' = freeform text in `content`. 'checklist' = structured to-do items in `checklist_items`. Defaults to 'checklist' if checklist_items is supplied, else 'note'."},
+ "checklist_items": {"type": "array",
+ "items": {"type": "object",
+ "properties": {
+ "text": {"type": "string", "description": "The to-do item text"},
+ "done": {"type": "boolean", "description": "Whether the item is checked off"}
+ },
+ "required": ["text"]},
+ "description": "Checklist items for note_type='checklist'. Each item is {text, done}. REQUIRED for checklists — leaving this empty produces a blank note."},
+ "color": {"type": "string", "description": "Optional color label (e.g. 'yellow', 'blue', 'green')"},
+ "label": {"type": "string", "description": "Optional category label (also used as a list filter)"},
+ "pinned": {"type": "boolean", "description": "Pin the note to the top"},
+ "archived": {"type": "boolean", "description": "For update: archive/unarchive. For list: show archived notes when true."},
+ "due_date": {"type": "string", "description": "Reminder time. Accepts natural language ('tomorrow at 9am', '11pm today') or ISO 8601. Fires a notification at that time."},
+ "index": {"type": "integer", "description": "Checklist item index (for toggle_item, 0-based)"}
+ },
+ "required": ["action"]
+ }
+ }
+ },
{
"type": "function",
"function": {