Skip to content

fix(agent): expand regex auto-escalation to cover contacts, files, and sessions - #5749

Open
holden093 wants to merge 3 commits into
odysseus-dev:devfrom
holden093:fix/regex-auto-escalation-expansion-reopen
Open

fix(agent): expand regex auto-escalation to cover contacts, files, and sessions#5749
holden093 wants to merge 3 commits into
odysseus-dev:devfrom
holden093:fix/regex-auto-escalation-expansion-reopen

Conversation

@holden093

Copy link
Copy Markdown
Contributor

Note: Re-opening of #5089, auto-closed 2026-07-23 during the odysseus-dev org transfer (the dev history rewrite force-closed all open PRs). Same change, cleanly rebased onto the current dev. Original review thread: #5089.

Summary

The chat→agent auto-escalation (_classify_tool_intent) only covered calendar, notes, email, UI, web, research, and shell intents. Three domains reachable from plain chat were missing: contacts, files, and sessions.

This adds 15 regex patterns (IT/EN) covering:

  • Contacts: phone/number/email/address lookup ("mi dici il numero di [Name]?", "what is Mario's email?")
  • Files: read/show/open/look-at file requests ("leggi il README", "what's in config.yaml")
  • Sessions: search/find/filter chat history ("cerca nelle chat", "find the conversation about X")

File patterns guard against UI collisions by requiring a filename-like target (extension, path, or capital letter).

Target branch

  • This PR targets dev, not main.

Linked Issue

Fixes #5030

Type of Change

  • Bug fix (non-breaking — fixes a confirmed issue)

Checklist

  • I searched open issues and open PRs — this is not a duplicate.
  • This PR targets dev
  • My changes are limited to the scope described above — no unrelated refactors or whitespace changes mixed in.
  • I actually ran the app (docker compose up or uvicorn app:app) and verified the change works end-to-end. Type-checks and unit tests are not enough.

How to Test

  1. Contacts: send mi dici il numero di [Name]? in chat mode → auto-escalates to agent with category=contacts
  2. Files: send leggi il README → auto-escalates to agent with category=files
  3. Files UI guard: send open settings → stays ui (not files)
  4. Sessions: send cerca nelle chat il progetto → auto-escalates to agent with category=sessions
  5. False positive check: how do I read files? / what is a file system? → stay in chat mode

Visual / UI changes

None — backend-only change.

The chat-to-agent auto-escalation via _classify_tool_intent only covered
calendar, notes, email, UI, web search, research, and shell tools.
Questions like 'mi dici il numero di X?' or 'what is Mario's phone number?'
stayed in chat mode, leaving the model unable to call resolve_contact.

Add three patterns for contacts/address-book lookup:
- phone/number/address lookup requests (IT/EN/ES)
- explicit contact search ('look up X in contacts', 'cerca X nei contatti')
- bare contacts/address-book search ('search my contacts', 'find contacts')
Add regex patterns for chat-to-agent auto-escalation of:
- files: read/show/open/what's-in-file requests in IT/EN
- sessions: search/find in chat history in IT/EN

File patterns require the target to mention 'file' or look like a
filename (extension, path prefix, or leading capital) to avoid
collisions with UI panel names ('open settings' stays UI).

Combined with the earlier contacts patterns this covers the main
remaining tool domains reachable from a plain chat message.
@github-actions github-actions Bot added the ready for review Description complete — ready for maintainer review label Jul 25, 2026
@holden093

Copy link
Copy Markdown
Contributor Author

Heads-up: the failing Python tests (pytest) check is a pre-existing dev bug, not this PR

The pytest job fails at test collection, before any of this PR's changes are exercised:

NameError: name 'Any' is not defined

Root cause is on dev itself: src/agent_loop.py annotates with dict[str, Any] (lines 1503 and 1877) but only imports AsyncGenerator, List, Dict, Optional, Set — no Any, and no from __future__ import annotations. So importing the module raises NameError, which breaks collection for every test that transitively imports agent_loop (hence the repo-wide failure).

This PR doesn't touch agent_loop.py; every other check (syntax, CodeQL, lint, security scans) passes here, and this PR's own tests pass locally.

One-line fix (add Any to the typing import) is included in #5751. Once dev carries that fix, this PR's pytest will go green with no changes needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Description complete — ready for maintainer review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agent): contacts/phone-number lookups don't auto-escalate to agent mode

1 participant