Skip to content

⚡ Bolt: Optimize agent thread fetching with getFullThread - #649

Open
schmug wants to merge 1 commit into
mainfrom
bolt-agent-get-full-thread-4770454058648516496
Open

⚡ Bolt: Optimize agent thread fetching with getFullThread#649
schmug wants to merge 1 commit into
mainfrom
bolt-agent-get-full-thread-4770454058648516496

Conversation

@schmug

@schmug schmug commented Jul 25, 2026

Copy link
Copy Markdown
Owner

💡 What: Replaced the N+1 getEmails + getEmail loop in workers/agent/index.ts with a single call to getFullThread. Removed the manual date sort since getFullThread handles sorting internally.
🎯 Why: To significantly reduce the latency and RPC overhead when the agent loads conversation context for a long email thread.
📊 Impact: Replaces N+1 backend queries/RPC calls with exactly 2 queries when loading context for thread processing.
🔬 Measurement: Tested via the agent unit tests (tests/agent/). The agent interactions will load context much faster for multi-email conversations.


PR created automatically by Jules for task 4770454058648516496 started by @schmug

The agent currently fetches a thread context by executing an N+1 query: it first fetches all thread message metadata (`stub.getEmails`), then iterates over each one to fetch the full content (`stub.getEmail`). This introduces multiple sequential RPC calls and database reads.

Replaced this with a single call to `getFullThread(stub, threadId)`, which handles the complete retrieval in 2 queries inside the DO instead of N+1. This improves performance when loading agent context for longer threads.

Co-authored-by: schmug <38227427+schmug@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 25, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
agentic-inbox 4582441 Jul 25 2026, 05:46 AM

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 25, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
ais-hub 4582441 Commit Preview URL

Branch Preview URL
Jul 25 2026, 05:45 AM

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