Skip to content

fix(agent): make the tool-selection timeout configurable#5772

Open
MummIndia wants to merge 1 commit into
odysseus-dev:devfrom
MummIndia:tool-selection-timeout
Open

fix(agent): make the tool-selection timeout configurable#5772
MummIndia wants to merge 1 commit into
odysseus-dev:devfrom
MummIndia:tool-selection-timeout

Conversation

@MummIndia

Copy link
Copy Markdown

Summary

Tool selection has a 1.5s budget covering three steps: index init, MCP indexing, and
retrieval. That suits a warm index on quick hardware. It is tight anywhere else,
because the steps run inside a request while the app may also be loading FastEmbed,
reaching ChromaDB and spawning MCP servers.

The failure mode is what makes this worth fixing rather than the number itself. On
expiry, selection falls back to ALWAYS_AVAILABLE — which contains no MCP tool at all.
Every MCP server therefore disappears for that turn, and the agent reports it does not
have tools it is connected to and could call directly. The warning line says the
timeout expired; nothing says the consequence was dropping the entire MCP surface.

Makes the value overridable via ODYSSEUS_TOOL_SELECTION_TIMEOUT. The default is
unchanged at 1.5s, so nothing moves for existing installs.

Also adds the missing import os — the module did not import it and made no use of
os. anywhere, so the new call would have raised NameError at import time. Worth
flagging because py_compile does not catch it: it checks syntax, not name resolution.

Target branch

  • This PR targets dev, not main.

Linked Issue

Fixes #5771

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) and verified the change works end-to-end.

How to Test

  1. With an MCP server connected, send an agent request while the app is still warming
    up. Before — the [tool-rag] warning fires and the following [agent-debug]
    line contains no mcp__* tool; the agent reports it has no such tool.

  2. Set ODYSSEUS_TOOL_SELECTION_TIMEOUT=15 and repeat. Retrieval completes and the
    mcp__* tools appear in tool_names.

  3. Unset it and confirm the default is still 1.5s:

    float(os.environ.get("ODYSSEUS_TOOL_SELECTION_TIMEOUT", "1.5"))  # 1.5
  4. Confirm the module imports cleanly (python -c "import src.agent_loop"), which is
    what catches the missing import os.

Visual / UI changes

None. src/agent_loop.py only — a module-level constant and an import.

Tool selection has a 1.5s budget covering three steps: index init, MCP
indexing, and retrieval. That suits a warm index on quick hardware. It
is tight anywhere else, because the steps run inside a request while the
app may also be loading FastEmbed, reaching ChromaDB and spawning MCP
servers.

The failure mode is what makes this worth fixing rather than the number
itself. On expiry, selection falls back to ALWAYS_AVAILABLE — which
contains no MCP tool at all. Every MCP server therefore disappears for
that turn, and the agent reports it does not have tools it is connected
to and could call directly. The warning line says the timeout expired;
nothing says the consequence was dropping the entire MCP surface, so the
two are not obviously related when reading logs.

Makes the value overridable via ODYSSEUS_TOOL_SELECTION_TIMEOUT so a
slower or busier deployment can buy headroom without patching. The
default is unchanged at 1.5s, so nothing moves for existing installs.

Also adds the missing `import os` — the module did not import it and
made no use of `os.` anywhere, so the new call would have raised
NameError at import time. Worth flagging because py_compile does not
catch it: it checks syntax, not name resolution.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the ready for review Description complete — ready for maintainer review label Jul 26, 2026
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.

Tool-selection timeout drops every MCP server, and the agent then reports it has no tools

1 participant