Skip to content

feat(ai): add tool_docs meta-tool with per-category usage guides - #1411

Closed
2witstudios wants to merge 4 commits into
masterfrom
pu/search-tool-docs
Closed

2witstudios wants to merge 4 commits into
masterfrom
pu/search-tool-docs

Conversation

@2witstudios

@2witstudios 2witstudios commented May 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Adds a new tool_docs non-core tool that agents can call to get rich usage documentation (concept, data model, workflows, common mistakes) for any tool category before calling tools they're unfamiliar with
  • Extends tool_search responses to include docs_available: true and a docs_hint inline on relevant tool results (30 tools mapped across 7 categories), so agents see the hint at the exact moment they pull a schema
  • Updates system prompt discovery text to surface tool_docs alongside tool_search

Problem

Agents discovering tools via tool_search only received JSON schemas — no usage guidance. This caused first-attempt failures on: edit_sheet_cells (A1 addressing isn't obvious), update_task (status group system requires read_page first), create_calendar_event (recurrence rules, timezone requirement), and general page hierarchy patterns.

Changes

New files:

  • apps/web/src/lib/ai/docs/index.ts — Inline documentation for 7 categories: pages, task-lists, sheets, calendar, agents, channels, drives
  • apps/web/src/lib/ai/tools/tool-docs-tool.ts — tool_docs tool implementation

Modified files:

  • tool-search-tool.ts — Added DOCS_HINT_MAP (30 tool→category entries); matching tools in results get docs_available + docs_hint
  • system-prompt.ts — Updated TOOL_DISCOVERY_PROMPT and buildNonCoreToolNamesPrompt header to mention tool_docs
  • messages/route.ts — Wired tool_docs: createToolDocsTool() into finalTools
  • ToolCallRenderer.tsx + CompactToolCallRenderer.tsx — Suppress tool_docs calls from UI (invisible to users)

Agent workflow after this change

  1. Agent calls tool_search("select:update_task") → gets schema + docs_hint
  2. Agent calls tool_docs({category:"task-lists"}) → gets status group system, nested FOLDER+TASK_LIST patterns, mandatory read_page-first workflow
  3. Agent calls execute_tool("update_task", {...}) correctly on the first attempt

Test plan

  • Call tool_search("select:edit_sheet_cells") in a chat — confirm response includes docs_hint pointing to "sheets"
  • Call tool_docs({category:"sheets"}) — confirm A1 addressing explanation is returned
  • Call tool_docs({category:"task-lists"}) — confirm status group system and nested org pattern appear
  • Verify tool_docs calls produce no visible card in the chat UI
  • Verify system prompt includes tool_docs mention in the NON-CORE TOOLS section

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added a comprehensive AI tool documentation system covering pages, task-lists, sheets, calendar, agents, channels, and drives.
    • AI can consult detailed tool docs (concepts, workflows, composition patterns, common mistakes) before using unfamiliar tools.
    • Tool search results now include documentation hints and availability flags to guide the AI.
    • Chat UI suppresses raw tool-call renderings for internal search/docs tool calls to keep conversations cleaner.

Review Change Stack

Agents that discover tools via tool_search only received JSON schemas,
giving them no guidance on usage patterns, data models, or common
mistakes. This meant first-attempt failures on tools like edit_sheet_cells
(A1 addressing), update_task (status group system), and create_calendar_event
(recurrence rules + timezone handling).

- Add tool_docs non-core tool: accepts a typed category enum and returns
  a markdown guide covering concept, data model, workflows, and mistakes
- Add docs/index.ts with inline content for 7 categories: pages, task-lists,
  sheets, calendar, agents, channels, drives
- Extend tool_search responses with docs_available + docs_hint on tools
  that have a matching category (30 tools mapped)
- Update TOOL_DISCOVERY_PROMPT and buildNonCoreToolNamesPrompt to mention tool_docs
- Wire tool_docs into finalTools in the global assistant messages route
- Suppress tool_docs calls in ToolCallRenderer and CompactToolCallRenderer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@vercel

vercel Bot commented May 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
pagespace-marketing Ready Ready Preview, Comment May 25, 2026 1:51am

@coderabbitai

coderabbitai Bot commented May 24, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@2witstudios, we couldn't start this review because you've used your available PR reviews for now.

Your plan includes 1 review of capacity. Refill in 47 minutes and 2 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 82698858-5a65-451d-8997-83fbda15aa4d

📥 Commits

Reviewing files that changed from the base of the PR and between 4ec6dbb and 760a6e1.

📒 Files selected for processing (3)
  • apps/web/src/lib/ai/core/system-prompt.ts
  • apps/web/src/lib/ai/docs/index.ts
  • apps/web/src/lib/ai/tools/tool-search-tool.ts
📝 Walkthrough

Walkthrough

Introduces a new tool_docs AI tool with Markdown documentation for seven feature categories (pages, task-lists, sheets, calendar, agents, channels, drives). The tool integrates into the AI discovery flow: system prompts guide model usage, tool search results include documentation hints, the tool registers in the message route, and renderers suppress its output in chat UI.

Changes

Tool Documentation Discovery System

Layer / File(s) Summary
Tool Documentation Catalog
apps/web/src/lib/ai/docs/index.ts
Exports seven documentation categories (pages, task-lists, sheets, calendar, agents, channels, drives) via a readonly tuple, defines ToolDocCategory union type, provides a 488-line internal DOCS map with full Markdown content for each category, and exports getToolDoc(category: string) helper to retrieve docs by category.
Tool Implementation and Search Integration
apps/web/src/lib/ai/tools/tool-docs-tool.ts, apps/web/src/lib/ai/tools/tool-search-tool.ts
Introduces createToolDocsTool() AI tool that accepts a category and returns documentation content or error; enriches createToolSearchTool() results with a DOCS_HINT_MAP that maps tool names to categories and adds docs_available and docs_hint fields instructing callers to invoke tool_docs() for each matched tool.
System Prompt Guidance and Tool Registration
apps/web/src/lib/ai/core/system-prompt.ts, apps/web/src/app/api/ai/global/[id]/messages/route.ts
Updates TOOL_DISCOVERY_PROMPT and buildNonCoreToolNamesPrompt() to instruct the model to use tool_docs({category}) for usage guidance before calling unfamiliar tools; imports createToolDocsTool and registers the tool_docs tool in finalTools alongside existing meta-tools.
UI Rendering Suppression
apps/web/src/components/ai/shared/chat/tool-calls/ToolCallRenderer.tsx, apps/web/src/components/ai/shared/chat/tool-calls/CompactToolCallRenderer.tsx
Expands early-return filters in both renderers to suppress tool_docs alongside tool_search, applied both before and after execute_tool name resolution so tool_docs calls do not appear in chat UI.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • 2witstudios/PageSpace#1301: Introduced the earlier tool_search meta-tool foundation that this PR extends with documentation discovery.
  • 2witstudios/PageSpace#1314: Updates the same chat tool-call renderers (ToolCallRenderer and CompactToolCallRenderer) to adjust conditional rendering based on resolved/unwrapped tool names.
  • 2witstudios/PageSpace#212: Modifies the messages route tool-set wiring; changes there affect how newly added tools like tool_docs are merged/sanitized before dispatch.

Poem

🐰 A curious rabbit hops through docs so bright,
Tool guidance flows from pages, sheets, and sites,
No more fumbling through features unknown,
Now search hints point to wisdom fully shown!
Pages✨ tasks📋 drives🎯 all in one.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main feature: adding a tool_docs meta-tool with per-category usage guides, which aligns with the core objective of introducing documentation support for AI tools.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch pu/search-tool-docs

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ec6cf71dc6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread apps/web/src/lib/ai/docs/index.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/web/src/lib/ai/core/system-prompt.ts`:
- Line 41: The prompt instructs the model to call tool_docs({category}) with
values from CATEGORY_MAP that don't match the tool_docs enum; update
CATEGORY_MAP (or the prompt) so categories map to the exact enum values expected
by tool_docs (e.g., map "tasks"->"task-lists", "drive"->"drives"), or change the
prompt to transform values before calling tool_docs; locate CATEGORY_MAP and the
prompt string using the symbols CATEGORY_MAP and tool_docs in system-prompt.ts
and ensure the category names produced/used match the tool_docs API exactly.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 52d05601-7644-4e03-b65a-db589dd56a64

📥 Commits

Reviewing files that changed from the base of the PR and between b7b60c3 and ec6cf71.

📒 Files selected for processing (7)
  • apps/web/src/app/api/ai/global/[id]/messages/route.ts
  • apps/web/src/components/ai/shared/chat/tool-calls/CompactToolCallRenderer.tsx
  • apps/web/src/components/ai/shared/chat/tool-calls/ToolCallRenderer.tsx
  • apps/web/src/lib/ai/core/system-prompt.ts
  • apps/web/src/lib/ai/docs/index.ts
  • apps/web/src/lib/ai/tools/tool-docs-tool.ts
  • apps/web/src/lib/ai/tools/tool-search-tool.ts

Comment thread apps/web/src/lib/ai/core/system-prompt.ts
2witstudios and others added 2 commits May 24, 2026 20:36
CATEGORY_MAP was using 'drive', 'tasks', and grouping edit_sheet_cells
under 'pages' — none of which matched tool_docs categories ('drives',
'task-lists', 'sheets'). Agents reading the non-core tools listing would
call tool_docs({category:"tasks"}) and get a not-found error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
update_task creation takes pageId (the TASK_LIST page's own ID), not the
internal taskListId DB field. Also adds create_task_status workflow example
and fixes the 'common mistakes' section accordingly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The tool is documented in task-lists.md but was not listed in the
non-core tools prompt or given a docs_hint in tool_search results.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@2witstudios
2witstudios deleted the pu/search-tool-docs branch May 26, 2026 21:43

This branch was previously deployed

1 inactive deployment
Preview — 760a6e19 Deployed May 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant