Skip to content

poc: v2 - ai sidekick agent loop in browser#2305

Draft
maxy-shpfy wants to merge 1 commit into
04-15-poc_ai_sidekick_agentfrom
05-21-poc_v2_-_ai_sidekick_agent_loop_in_browser
Draft

poc: v2 - ai sidekick agent loop in browser#2305
maxy-shpfy wants to merge 1 commit into
04-15-poc_ai_sidekick_agentfrom
05-21-poc_v2_-_ai_sidekick_agent_loop_in_browser

Conversation

@maxy-shpfy
Copy link
Copy Markdown
Collaborator

@maxy-shpfy maxy-shpfy commented May 21, 2026

Description

Migrates the in-browser AI agent runtime from the LangChain/deepagents stack to @openai/agents, running entirely inside a Web Worker via Comlink. The agent now communicates with the LLM through the Shopify proxy using the OpenAI Chat Completions surface, with all pipeline mutations happening directly on the live MobX spec through a typed ToolBridgeApi rather than through command serialization and replay.

Key changes:

  • New agent runtime (src/agent/): A dispatcher agent routes user intent to five specialist sub-agents — pipeline-architect, pipeline-repair, debug-assistant, general-help, and generic-assistant. Each sub-agent has a dedicated system prompt and a focused tool set.
  • Tool bridge (toolBridge.ts): Main-thread implementation of ToolBridgeApi that mutates the live MobX ComponentSpec inside undo groups. The worker calls these methods via Comlink proxy — no command serialization needed.
  • Worker entry point (src/agent/worker.ts): Exposes ask() and init() via Comlink. Includes a globalThis.process polyfill to cover an unguarded process.env read in @openai/agents-core v0.4.x.
  • Semantic search delegated to backend: search_components and search_docs tools now POST to /api/agent/search_components and /api/agent/search_docs respectively, replacing the in-browser MemoryVectorStore + OpenAIEmbeddings approach.
  • Skills loader (src/agent/skills/loader.ts): Fetches SKILL.md files from a configurable base URL with ETag-based IDB caching for revalidation on deploy.
  • Observability hooks (src/agent/middleware/observability.ts): Translates @openai/agents lifecycle events (agent_start, agent_tool_start, agent_handoff, etc.) into status text forwarded to the main thread.
  • Feature flag: The worker runtime is gated behind localStorage.setItem("agent.runtime", "worker") so the existing LangChain path remains active by default.
  • Dependency changes: Adds @openai/agents, @openai/agents-core, openai (moved from devDependencies), and comlink. Removes @langchain/anthropic and its transitive @anthropic-ai/sdk dependency.
  • New npm scripts: agent:publish-index and agent:publish-skills copy vector store files and skill assets into public/ for static serving.
  • Vite worker config: A scoped resolveId plugin forces @openai/agents-core/_shims to resolve to its browser variant inside the worker bundle, preventing the Node shim from being bundled.

Related Issue and Pull requests

Type of Change

  • Bug fix
  • New feature
  • Improvement
  • Cleanup/Refactor
  • Breaking change
  • Documentation update

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Screenshots (if applicable)

Demo - AI Sidekick - Openai Agent in Browser.mov (uploaded via Graphite)

Test Instructions

  1. Open a pipeline in the editor.
  2. Open the AI Chat panel.
  3. Enable the worker runtime: localStorage.setItem("agent.runtime", "worker") in the browser console, then reload.
  4. Ensure VITE_AI_PROXY_TOKEN and VITE_AI_PROXY_BASE_URL are set in your .env.
  5. Send a message asking the agent to explain the current pipeline — verify the generic-assistant responds with entity chip links.
  6. Ask the agent to build a simple pipeline — verify CSOM tool calls appear in the status bar and tasks are added to the canvas with undo support.
  7. Ask a question about a failed run — verify the debug-assistant fetches logs from the backend.
  8. Verify the existing LangChain path still works when the flag is not set.

Additional Comments

The LangChain/deepagents runtime is preserved and remains the default. The worker runtime can be toggled per-session via localStorage without a deploy. Per-thread conversation memory (MemorySession) lives for the lifetime of the worker and resets on page reload; persistent cross-session memory backed by Dexie is out of scope for this iteration.

@github-actions
Copy link
Copy Markdown

🎩 Preview

A preview build has been created at: 05-21-poc_v2_-_ai_sidekick_agent_loop_in_browser/77e9771

Copy link
Copy Markdown
Collaborator Author

maxy-shpfy commented May 21, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

This was referenced May 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant