Skip to content

fix(slack): prevent web search context bloat and increase max searches#1523

Merged
saddlepaddle merged 1 commit into
mainfrom
fix-web-search-slack
Feb 16, 2026
Merged

fix(slack): prevent web search context bloat and increase max searches#1523
saddlepaddle merged 1 commit into
mainfrom
fix-web-search-slack

Conversation

@saddlepaddle
Copy link
Copy Markdown
Collaborator

@saddlepaddle saddlepaddle commented Feb 16, 2026

Summary

  • Strip web_search_tool_result and server_tool_use blocks from assistant messages before subsequent API calls in the Slack agent tool loop, preventing context from blowing up when the model searches the web and then uses client-side tools (e.g., create_task)
  • Increase max_uses from 1 to 5 so the model can perform multiple searches per request
  • The synthesized text blocks already contain the answer with citations, so raw search results aren't needed for tool execution

Test plan

  • Typecheck passes
  • Lint passes
  • All 1218 tests pass
  • Manually test Slack bot with web search query followed by task creation
  • Verify web search citations still appear in final Slack response

Summary by CodeRabbit

  • New Features

    • Slack agent now supports up to 5 web searches per interaction (previously limited to 1).
  • Bug Fixes

    • Improved agent efficiency by filtering unnecessary internal data from responses, reducing processing overhead and context bloat.

Strip server-side web search content blocks (web_search_tool_result,
server_tool_use) from assistant messages before subsequent API calls.
The synthesized text already contains the answer, so raw search results
aren't needed for tool execution. Also bumps max_uses from 1 to 5.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

A helper function stripServerToolBlocks is introduced to filter server-generated tool blocks from Anthropic responses. The Slack agent's web search usage limit is increased from 1 to 5, and assistant content is now processed through this filter before subsequent API calls to reduce context bloat.

Changes

Cohort / File(s) Summary
Server Tool Block Filtering
apps/api/src/app/api/integrations/slack/events/utils/run-agent/run-agent.ts
Added stripServerToolBlocks helper to filter out server-provided tool blocks (web_search_tool_result and server_tool_use) from response content. Applied filtering to assistant content in the tool-use loop and after tool result processing. Increased web search usage limit from 1 to 5.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • superset-sh/superset#1100: Modifies the same Slack agent run-agent.ts tool-handling flow, introducing web_search integration and adjusting tool-use loop logic.
  • superset-sh/superset#1101: Also modifies run-agent.ts agent tool-use loop and assistant content handling, including tool usage limits and block processing.

Poem

🐰 A filter hops through tool-filled streams,
Sweeping server blocks from assistant dreams,
Five web searches now leap and bound,
Context cleaner, sanity found!

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (2 files):

⚔️ apps/api/src/app/api/integrations/slack/events/utils/run-agent/run-agent.ts (content)
⚔️ apps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/useCommandWatcher.ts (content)

These conflicts must be resolved before merging into main.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: preventing web search context bloat and increasing max searches in Slack, which aligns perfectly with the primary objectives.
Description check ✅ Passed The description includes a clear summary of changes, test plan with specific verification steps, and technical rationale. However, it deviates from the template by omitting standard sections like Related Issues, Type of Change, and Additional Notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-web-search-slack
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch fix-web-search-slack
  • Create stacked PR with resolved conflicts
  • Post resolved changes as copyable diffs in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
apps/api/src/app/api/integrations/slack/events/utils/run-agent/run-agent.ts (1)

255-263: Double cast (as unknown as) bypasses type safety.

The ContentBlockunknownContentBlockParam[] cast sidesteps structural differences between response and request types in the Anthropic SDK. This works today because the surviving block shapes (text, tool_use) are structurally compatible, but it's fragile against SDK upgrades.

Consider mapping each block to its corresponding param type explicitly, or at minimum add a brief inline comment noting why the cast is safe (i.e., which block types survive the filter and why they're param-compatible).

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 16, 2026

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app
  • ✅ Streams Fly.io app

Thank you for your contribution! 🎉

@saddlepaddle saddlepaddle merged commit 390a486 into main Feb 16, 2026
15 checks passed
@Kitenite Kitenite deleted the fix-web-search-slack branch February 19, 2026 21:44
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