Repository navigation
Add frontend tools implementation guide to HTTP API docs - #1867
Conversation
…eference nav Add a step-by-step "Implementing Frontend Tools in Your Client" section to the HTTP API docs covering tool definition, SSE stream parsing, pause-mode resume flow, and noop-mode fire-and-forget handling with JavaScript examples. Move HTTP API to first position in reference nav. https://claude.ai/code/session_013fd6r27uVfY2RijXoJhJs2 Signed-off-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
✅ Files skipped from review due to trivial changes (1)
WalkthroughReordered Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant FrontendToolExecutor
rect rgba(100, 150, 255, 0.5)
Note over Client,Server: Request 1: Initial /api/chat with frontend_tools
Client->>Server: POST /api/chat (SSE stream)
Server->>Server: Process chat, detect pause-mode tool calls
Server-->>Client: Stream events including approval_required (pending_frontend_tool_calls + conversation_history)
Server-->>Client: Stream ends
end
rect rgba(100, 200, 100, 0.5)
Note over Client,FrontendToolExecutor: Client-side execution
Client->>FrontendToolExecutor: Execute pending frontend tools
FrontendToolExecutor-->>Client: Return frontend_tool_results (JSON-encoded strings)
end
rect rgba(255, 180, 100, 0.5)
Note over Client,Server: Request 2: Resume /api/chat with results
Client->>Server: POST /api/chat (SSE) with conversation_history + frontend_tool_results
Server->>Server: Resume processing using provided tool results
Server-->>Client: Stream remaining response
end
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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. Comment |
✅ Deploy Preview for holmes-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…t guide Replace hand-rolled ReadableStream + regex parsing with @microsoft/fetch-event-source, which is what real projects use for POST-based SSE endpoints. Consolidate steps 2+3 into one and update the resume flow to reuse the streamChat helper. https://claude.ai/code/session_013fd6r27uVfY2RijXoJhJs2 Signed-off-by: Claude <noreply@anthropic.com>
Add a numbered request-pause-resume explanation to the Frontend Tools section showing that a single LLM turn is split across request 1 (stream until pause) and request 2 (resume with tool results). Update the implementation guide headings and code comments to label which request is which. https://claude.ai/code/session_013fd6r27uVfY2RijXoJhJs2 Signed-off-by: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
docs/reference/http-api.md (1)
512-539: Consider clarifying theoriginalQuestionvariable scope.Line 534 references
originalQuestion, but this variable is not defined in the function parameters or shown in scope. While this is example code, it might help to add a comment or parameter to clarify where this value should come from (e.g., stored from the initial request or passed as a parameter).💡 Suggested clarification
-async function handleFrontendToolCalls(pendingCalls, conversationHistory) { +async function handleFrontendToolCalls(pendingCalls, conversationHistory, originalQuestion) { const results = []; for (const call of pendingCalls) {Or add a comment:
// Request 2: resume the LLM with tool results + // originalQuestion should be saved from the initial request streamChat({ ask: originalQuestion,🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/reference/http-api.md` around lines 512 - 539, The example uses originalQuestion inside handleFrontendToolCalls but originalQuestion is not defined; update handleFrontendToolCalls to either accept originalQuestion as a parameter (e.g., function handleFrontendToolCalls(pendingCalls, conversationHistory, originalQuestion)) or add a clear inline comment above the streamChat call explaining that originalQuestion must be captured from the initial request scope and passed into this function, and ensure streamChat is called with that passed-in value so references to originalQuestion (and the streamChat call) are unambiguous.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/reference/http-api.md`:
- Around line 512-539: The example uses originalQuestion inside
handleFrontendToolCalls but originalQuestion is not defined; update
handleFrontendToolCalls to either accept originalQuestion as a parameter (e.g.,
function handleFrontendToolCalls(pendingCalls, conversationHistory,
originalQuestion)) or add a clear inline comment above the streamChat call
explaining that originalQuestion must be captured from the initial request scope
and passed into this function, and ensure streamChat is called with that
passed-in value so references to originalQuestion (and the streamChat call) are
unambiguous.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: ddc788ef-383f-4237-b77d-56c8b96506ab
📒 Files selected for processing (2)
docs/reference/.nav.ymldocs/reference/http-api.md
'Turn' could mean a single LLM iteration or the full multi-iteration request. Replaced with 'iteration' when referring to one LLM tool-call cycle and 'request' when referring to the full HTTP request. https://claude.ai/code/session_013fd6r27uVfY2RijXoJhJs2 Signed-off-by: Claude <noreply@anthropic.com>
https://claude.ai/code/session_013fd6r27uVfY2RijXoJhJs2 Signed-off-by: Claude <noreply@anthropic.com>
Summary
Added comprehensive documentation for implementing frontend tools in client applications, including step-by-step examples and best practices. Also reordered the navigation to prioritize the HTTP API reference.
Key Changes
New implementation guide section: Added "Implementing Frontend Tools in Your Client" to the HTTP API documentation with 6 detailed steps covering:
Code examples: Included practical JavaScript examples for each step, demonstrating:
Implementation notes: Added critical guidance on:
Navigation reordering: Moved "HTTP API" to the top of the reference documentation navigation for better discoverability
Implementation Details
The guide follows a progressive learning approach, building from basic tool definition through advanced scenarios like mixed pause types and error handling. All examples use realistic use cases (chart rendering, page navigation) to illustrate concepts clearly.
https://claude.ai/code/session_013fd6r27uVfY2RijXoJhJs2
Summary by CodeRabbit