Skip to content

feat(escalating): add live web tool detection and routing for requests#270

Open
Zochory wants to merge 1 commit into
mainfrom
feat/escalating-live-web-routing
Open

feat(escalating): add live web tool detection and routing for requests#270
Zochory wants to merge 1 commit into
mainfrom
feat/escalating-live-web-routing

Conversation

@Zochory
Copy link
Copy Markdown
Member

@Zochory Zochory commented May 30, 2026

Summary

  • Adds _requires_live_web_tools() in escalating.py to detect live web requests via URL regex and action-keyword patterns, routing them directly to the RLM path before lightweight respond is attempted
  • Fixes case-insensitive Content-Type header lookup in document_tools.py so PDF detection works regardless of server header casing
  • Registers fetch_document_text as a @tool_fn so it appears in the ReAct tool registry and is discoverable by agents

Test plan

  • test_url_fetch_request_forces_rlm_before_lightweight_response — verifies URL in request bypasses respond and goes straight to RLM
  • test_suffix_from_url_uses_case_insensitive_content_type_for_pdf — validates lowercase content-type header is recognized
  • test_phase3_tools_are_registered — confirms fetch_document_text is now in the registered tool set

🤖 Generated with Claude Code

fix(document_tools): improve content type handling for URL suffix extraction

test(escalating): add test for URL fetch request forcing RLM escalation

test(tools): add case insensitive content type test for URL suffix
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 30, 2026

Warning

Review limit reached

@Zochory, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 25 minutes and 36 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 8229e935-4517-4589-84f8-ee3558584df9

📥 Commits

Reviewing files that changed from the base of the PR and between 7f02373 and 27dc718.

📒 Files selected for processing (5)
  • src/fleet_rlm/runtime/modules/escalating.py
  • src/fleet_rlm/runtime/tools/document_tools.py
  • tests/unit/runtime/test_escalating_module.py
  • tests/unit/runtime/test_phase3_tools.py
  • tests/unit/runtime/test_tools.py

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

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces routing logic to escalate user requests requiring live web tools to the RLM path, utilizing regex matching for URLs and specific action/target keywords. It also registers fetch_document_text as a tool, ensures case-insensitive retrieval of the Content-Type header when determining file suffixes, and adds corresponding unit tests. Feedback focuses on improving the keyword matching regex to be order-independent and more efficient by splitting it into separate action and target patterns, updating the routing check accordingly, and adding tests for keyword-based routing.

Comment on lines +31 to +38
_LIVE_WEB_REQUEST_RE = re.compile(
r"\b("
r"browse|download|fetch|open|read|retrieve|scrape|summari[sz]e"
r")\b.*\b("
r"internet|online|page|pdf|site|url|web|website"
r")\b",
flags=re.IGNORECASE,
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current regex _LIVE_WEB_REQUEST_RE enforces a strict order where the action verb (e.g., browse) must precede the target noun (e.g., website) due to the .* pattern. This means queries like "Is there a website I can browse?" or "pdf to summarize" will fail to match, even though they clearly require live web tools.

Additionally, using .* can introduce backtracking overhead on long inputs.

We can resolve this by splitting the pattern into two separate, simpler regexes for actions and targets, making the check completely order-independent and more efficient.

Suggested change
_LIVE_WEB_REQUEST_RE = re.compile(
r"\b("
r"browse|download|fetch|open|read|retrieve|scrape|summari[sz]e"
r")\b.*\b("
r"internet|online|page|pdf|site|url|web|website"
r")\b",
flags=re.IGNORECASE,
)
_LIVE_WEB_ACTION_RE = re.compile(
r"\b(browse|download|fetch|open|read|retrieve|scrape|summari[sz]e)\b",
flags=re.IGNORECASE,
)
_LIVE_WEB_TARGET_RE = re.compile(
r"\b(internet|online|page|pdf|site|url|web|website)\b",
flags=re.IGNORECASE,
)

Comment on lines +45 to +49
def _requires_live_web_tools(user_request: str) -> bool:
"""Return whether a turn should skip lightweight chat and use web-capable tools."""
if _LIVE_WEB_URL_RE.search(user_request):
return True
return bool(_LIVE_WEB_REQUEST_RE.search(user_request))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Update _requires_live_web_tools to use the new order-independent _LIVE_WEB_ACTION_RE and _LIVE_WEB_TARGET_RE regexes.

Suggested change
def _requires_live_web_tools(user_request: str) -> bool:
"""Return whether a turn should skip lightweight chat and use web-capable tools."""
if _LIVE_WEB_URL_RE.search(user_request):
return True
return bool(_LIVE_WEB_REQUEST_RE.search(user_request))
def _requires_live_web_tools(user_request: str) -> bool:
"""Return whether a turn should skip lightweight chat and use web-capable tools."""
if _LIVE_WEB_URL_RE.search(user_request):
return True
return bool(_LIVE_WEB_ACTION_RE.search(user_request) and _LIVE_WEB_TARGET_RE.search(user_request))

Comment on lines +72 to +83
def test_url_fetch_request_forces_rlm_before_lightweight_response(self) -> None:
module = _make_module()
_stub_respond(module, reasoning="I cannot browse the live web.", response="no web access")
rlm_pred = _FakePrediction(answer="fetched document")
module._rlm = MagicMock(return_value=rlm_pred)
_stub_summarize(module)

result = module(user_request="fetch https://arxiv.org/pdf/2512.24601 please", execution_mode="auto")

module.respond.assert_not_called()
module._rlm.assert_called_once()
assert getattr(result, "answer", None) == "fetched document"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The test only verifies routing when a URL is present in the request (which matches _LIVE_WEB_URL_RE). We should also add a test case to verify that keyword-based requests (e.g., "please browse the internet for me" or "pdf to summarize") successfully trigger the RLM path without a URL.

Suggested change
def test_url_fetch_request_forces_rlm_before_lightweight_response(self) -> None:
module = _make_module()
_stub_respond(module, reasoning="I cannot browse the live web.", response="no web access")
rlm_pred = _FakePrediction(answer="fetched document")
module._rlm = MagicMock(return_value=rlm_pred)
_stub_summarize(module)
result = module(user_request="fetch https://arxiv.org/pdf/2512.24601 please", execution_mode="auto")
module.respond.assert_not_called()
module._rlm.assert_called_once()
assert getattr(result, "answer", None) == "fetched document"
def test_url_fetch_request_forces_rlm_before_lightweight_response(self) -> None:
module = _make_module()
_stub_respond(module, reasoning="I cannot browse the live web.", response="no web access")
rlm_pred = _FakePrediction(answer="fetched document")
module._rlm = MagicMock(return_value=rlm_pred)
_stub_summarize(module)
# Test URL-based routing
result = module(user_request="fetch https://arxiv.org/pdf/2512.24601 please", execution_mode="auto")
module.respond.assert_not_called()
module._rlm.assert_called_once()
assert getattr(result, "answer", None) == "fetched document"
# Test keyword-based routing (order-independent)
module.respond.reset_mock()
module._rlm.reset_mock()
result_kw = module(user_request="please browse the internet for me", execution_mode="auto")
module.respond.assert_not_called()
module._rlm.assert_called_once()
assert getattr(result_kw, "answer", None) == "fetched document"

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