Skip to content

feat: live agent chat with client-side document tools#201

Open
jedrazb wants to merge 4 commits intomainfrom
feat/live-agent-chat
Open

feat: live agent chat with client-side document tools#201
jedrazb wants to merge 4 commits intomainfrom
feat/live-agent-chat

Conversation

@jedrazb
Copy link
Copy Markdown
Contributor

@jedrazb jedrazb commented Mar 19, 2026

Summary

  • EditorBridge (packages/agent-use/bridge.ts): connects AI agent tools to a live DocxEditor — agent reads content, adds comments, suggests tracked changes, scrolls, all on the client without reloading the document
  • 6 new methods on DocxEditorRef: addComment, replyToComment, resolveComment, proposeReplacement, scrollToIndex, getComments
  • Tool definitions (packages/agent-use/tools/): 6 tools with OpenAI-compatible schemas + executeToolCall() dispatcher + getToolSchemas() helper
  • useAgentChat hook: wires tools to editor ref — returns { executeToolCall, toolSchemas }
  • agent-chat-demo: Next.js example with chat panel beside the editor, tool-use loop on the client

Test plan

  • Typecheck passes (bun run typecheck)
  • Demo builds (cd examples/agent-chat-demo && next build)
  • Upload a DOCX, send "review this document" — agent reads doc via tool, adds comments/changes live
  • Multi-turn conversation preserves context (tool call history maintained)
  • Comments appear in sidebar immediately after agent adds them
  • Tracked changes appear inline after agent suggests replacements

🤖 Generated with Claude Code

Add EditorBridge that connects AI agent tools to a live DocxEditor instance.
The agent can read the document, add comments, suggest tracked changes, and
scroll — all executing on the client without reloading the document.

Key changes:
- DocxEditorRef: 6 new methods (addComment, replyToComment, resolveComment,
  proposeReplacement, scrollToIndex, getComments)
- EditorBridge (packages/agent-use/bridge.ts): wraps DocxEditorRef for agent use
- Tool definitions (packages/agent-use/tools/): 6 tools with OpenAI-compatible
  schemas (read_document, read_comments, read_changes, add_comment,
  suggest_replacement, scroll_to)
- useAgentChat hook: wires tools to editor ref
- agent-chat-demo: Next.js example with chat panel beside the editor

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 19, 2026

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

Project Deployment Actions Updated (UTC)
docx-editor Ready Ready Preview, Comment Mar 19, 2026 4:53pm

Request Review

- Replace getOpenAITools/getAnthropicTools with single getToolSchemas()
  (OpenAI format is the de facto standard)
- Simplify useAgentChat hook: returns { executeToolCall, toolSchemas }
  (removed stale bridge, getSystemContext, provider-specific helpers)
- Demo uses useAgentChat hook instead of manual bridge creation
- Fix multi-turn history: persistent openaiHistoryRef preserves tool
  call context across turns
- Fix bridge.getComments(): reads from live editor state, not stale
  Document model
- Fix replyToComment: validates parent comment exists
- Add 29 tests for tools + bridge (bun:test)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Extract getCommentText() helper, replacing inline type-cast chain
- Fix O(n^2) reply matching: pre-group with Map (same pattern as discovery.ts)
- Guard redundant editorRef.getComments() call when doc comments exist
- Memoize toolSchemas as module-level constant (static, never changes)
- Cache bridge creation via useMemo in useAgentChat hook
- Move msgId counter from module-level to useRef (scoped to component)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mthenw
Copy link
Copy Markdown
Contributor

mthenw commented Mar 27, 2026

Hey @jedrazb, quick question about this PR. Is it a high priority for you? I'm asking because I started working on something similar in my app, and there’s definitely some overlap with this PR. Do you plan to merge it soon, or is it more of an experiment?

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.

2 participants