Skip to content

Refactor agent starter for multi-chat helper agents#154

Open
threepointone wants to merge 1 commit into
mainfrom
refactor-multi-chat-agent-starter
Open

Refactor agent starter for multi-chat helper agents#154
threepointone wants to merge 1 commit into
mainfrom
refactor-multi-chat-agent-starter

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

Summary

This PR refactors the starter from a single chat-agent example into a richer multi-chat launch point for building agent applications on Cloudflare.

The new architecture is centered around an Inbox root agent that owns app-level state and shared MCP configuration. Each conversation is represented by a Chat subagent, and focused helper agents such as Researcher and Planner are exposed through agentTool so the main assistant can delegate work while preserving inspectable helper transcripts.

What changed

  • Reworked the server architecture around Inbox, Chat, Researcher, and Planner agents.
  • Added multi-chat state and metadata management, including chat creation, rename, deletion, sorting, and last-message previews.
  • Added shared MCP configuration at the Inbox level and proxied MCP tools into each Chat so external tools can be configured once and reused across conversations.
  • Added retained helper-agent tools for research and planning, with guarded drill-in routing for helper transcripts.
  • Removed the old data URL conversion workaround now that the AI SDK handles data URLs correctly.
  • Removed aggressive default message pruning so the starter preserves full context by default; the README now documents pruning/summarization as production context-management options.
  • Refactored the React UI into focused modules:
    • src/app.tsx for the app shell, header, inbox connection, and chat sidebar.
    • src/components/active-chat.tsx for the chat pane, composer, attachments, messages, and scheduling toasts.
    • src/components/mcp-panel.tsx for shared MCP server controls.
    • src/components/tool-views.tsx for tool cards, helper run cards, markdown output, and readonly drill-in panels.
    • src/constants.ts for shared starter constants.
  • Improved loading behavior by moving Suspense boundaries down to the chat pane and drill-in panel, avoiding full-app loading flashes when switching chats or opening helper drill-ins.
  • Rendered string tool/helper outputs with Streamdown so markdown responses from helper tools display correctly.
  • Made helper drill-ins readonly to avoid confusing side conversations with the main chat.
  • Added explanatory source comments for retained helper agents, shared MCP proxying, and subagent access guards.
  • Updated wrangler.jsonc and regenerated env.d.ts for the root Inbox Durable Object binding.
  • Rewrote the README to explain the multi-agent architecture, customization points, helper-agent workflow, shared MCP behavior, Durable Object routing, long-conversation guidance, model-provider swaps, and updated project structure.

Why

The starter is meant to be a launching point. The previous shape demonstrated a capable single chat agent, but it did not clearly show how to build a multi-chat app, delegate work to retained subagents, share MCP tools across conversations, or inspect helper-agent runs. This refactor keeps the demo approachable while giving users a more realistic foundation for production agent apps.

Test plan

  • Ran npm run check successfully.
  • Ran npx vite build successfully.
  • Regenerated Cloudflare environment types with npm run types.
  • Manually smoke test chat creation, switching, rename, and delete in the browser.
  • Manually smoke test image attachment, timezone tool, approval tool, scheduling toast, helper-agent delegation, helper drill-in, and MCP server add/remove flows.

Notes for reviewers

  • Inbox is the only directly bound Durable Object in wrangler.jsonc; Chat, Researcher, and Planner are reached as subagents through the Agents SDK routing layer.
  • The helper registry is intentionally simple for a starter. Adding a new helper currently requires touching both server registration/guards and the UI helper display list.
  • MCP discovery is still synchronous before each chat response. For production hardening, a follow-up could fall back to normal chat if MCP servers are slow or unavailable.

Made with Cursor

Rework the starter from a single chat agent into a richer launch point for multi-chat agent applications. The app now has an Inbox root agent that owns chat metadata and shared MCP configuration, per-chat Chat subagents for independent conversations, and retained Researcher/Planner helper agents exposed through agentTool.

The UI now includes a multi-chat sidebar, contained Suspense boundaries for chat and drill-in loading, inline helper run cards, markdown-rendered tool/helper output, and readonly helper drill-in panels. The React code is split into focused components for the app shell, active chat pane, MCP panel, and tool/drill-in rendering so the starter is easier to understand and customize.

Update the server-side implementation with clearer helper-agent and subagent access guard comments, remove the old data URL workaround and aggressive message pruning, and keep full message history by default for easier starter behavior. Shared MCP tool descriptors are proxied from Inbox into each Chat so external tools can be configured once and reused across conversations.

Refresh the README to document the new architecture, customization paths, helper-agent workflow, shared MCP behavior, Durable Object routing, long-conversation guidance, and updated project structure. Regenerate Wrangler environment types to match the current root Inbox binding.

Co-authored-by: Cursor <cursoragent@cursor.com>
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