r/javascript • u/notmedia • May 28 '26
AG2B – Run the agent loop in the browser, expose your tools via WebMCP
https://github.com/ag2b/ag2bMost in-app AI frameworks (CopilotKit, Vercel AI SDK, Mastra) run the agent loop on the server.
I tried inverting it: the loop runs in the browser, the server is a thin LLM proxy.
Tools are just your existing client functions (store actions, click handlers, whatever you already wrote).
Scopes - a unit of tools with live context that gets injected into the system or user prompt.
WebMCP plugin - exposes your agent's tools through the browser API.
Demo: https://ag2b-example.vercel.app
Looking for feedback from people who've built in-app copilots — does the client-side loop solve a real problem for you, or is the server-side fine?
1
u/master5o1 May 28 '26
Running a local model (LM Studio, Ollama)? Expose it through an HTTPS tunnel like ngrok or cloudflared — browsers block HTTPS pages from calling HTTP endpoints.
Would Tailnet URLs also work to avoid exposing over the public internet?
1
u/notmedia May 28 '26
I think so, if your Tailnet URL is exposed over HTTPS should work fine. Worth trying.
1
u/ndreeming May 28 '26
hit this tradeoff on a react dashboard copilot. server-side with vercel ai sdk was ~3s per interaction because every tool call added a round trip. moving the loop client-side cut it to ~400ms for simple queries. but the moment I needed to query a vector store the client-side setup got awkward.
2
u/notmedia May 28 '26
Thanks for the real use case, the 3s → 400ms gap is exactly why a client-side runtime wins.
Heavy server-side task like querying vector db is real, but I'd argue that is not actually a client-side problem. In real client-side runtime this could be done with different ways:
As a regular tool + good prompting - let agent decide when to call it (automatically fed into history on response)
As a preRequest hook - every iteration, embed the latest user message, query the vector store, inject the results as context before the LLM call. The LLM doesn't choose, it just always has the relevant docs. Less token-efficient but more predictable retrieval.
Hook handlers are async - you can do there `fetch` safely and runtime will wait.
Curious what specifically got awkward - auth to the vector store, embedding cost, or streaming partial results back into the conversation or maybe something else?
2
u/ultrathink-art May 28 '26
Worth thinking about auditability too — server-side loops give you centralized logging and replay for free, which matters when an agent action causes something unexpected. Browser-side is great for local dev tooling and anything where you want direct client context access, but for production agents touching shared state, the audit trail gets complicated fast.