Skip to content

Add runtime model router route updates - #6835

Merged
malhotra5 merged 2 commits into
feat/router-llm-statefrom
feat/runtime-model-router-routes
Nov 19, 2026
Merged

malhotra5 merged 2 commits into
feat/router-llm-statefrom
feat/runtime-model-router-routes

Conversation

@malhotra5

@malhotra5 malhotra5 commented Nov 14, 2026 •

Copy link
Copy Markdown
Member

HUMAN:

Tested downstream in agent canvas; created model router mid conversation and performed manual switches (as per video below)


AGENT:

Why

This stacks on PR 6789. It adds the runtime route-addition path needed for clients to start a conversation with a plain LLM, add another LLM through the model-router API, and then manually switch routes without using the deprecated whole-LLM switch endpoint.

Summary

  • Adds ConfigurableRouter plus RouterLLM.with_route(...), and teaches LocalConversation.add_model_router_route(...) to wrap a plain LLM into a router when needed.
  • Adds POST /api/conversations/{id}/model_router/routes, EventService support, server capability advertising, and Python/TypeScript remote client helpers.
  • Adds SDK, agent-server, and TypeScript tests for route addition, duplicate rejection, and manual switching after adding a route.

REST API contract changes

Compared with base OpenAPI 001a75e50778 for public /api/** paths.

--- base public OpenAPI
+++ head public OpenAPI
@@ -133,0 +134 @@
+operation POST /api/conversations/{conversation_id}/model_router/routes operationId=add_conversation_model_router_route_api_conversations__conversation_id__model_router_routes_post
@@ -360,0 +362 @@
+parameter POST /api/conversations/{conversation_id}/model_router/routes path:conversation_id required=true schema=type="string" format="uuid"
@@ -426,0 +429 @@
+requestBody POST /api/conversations/{conversation_id}/model_router/routes application/json required=true schema=AddModelRouterRouteRequest
@@ -768,0 +772,4 @@
+response POST /api/conversations/{conversation_id}/model_router/routes 200 application/json schema=ModelRouterStatus
+response POST /api/conversations/{conversation_id}/model_router/routes 400 no-content
+response POST /api/conversations/{conversation_id}/model_router/routes 404 no-content
+response POST /api/conversations/{conversation_id}/model_router/routes 422 application/json schema=HTTPValidationError
@@ -1087,0 +1095,4 @@
+schema AddModelRouterRouteRequest property base_route_name optional schema=type="string" default="default"
+schema AddModelRouterRouteRequest property profile_name required schema=type="string"
+schema AddModelRouterRouteRequest property route_name optional schema=anyOf=[type="string",type="null"]
+schema AddModelRouterRouteRequest type="object"

Issue Number

Refs #6860. Stacked on PR 6789.

How to Test

  • uv run pytest tests/sdk/llm/test_router_llm.py tests/sdk/conversation/test_switch_model.py tests/agent_server/test_conversation_router.py tests/agent_server/test_server_details_router.py -q
  • uv run pre-commit run --files .pr/model-router-design.html clients/typescript/src/__tests__/api-clients.test.ts clients/typescript/src/client/conversation-client.ts clients/typescript/src/conversation/conversation-manager.ts clients/typescript/src/conversation/remote-conversation.ts openhands-agent-server/openhands/agent_server/conversation_router.py openhands-agent-server/openhands/agent_server/event_service.py openhands-agent-server/openhands/agent_server/models.py openhands-agent-server/openhands/agent_server/server_details_router.py openhands-sdk/openhands/sdk/conversation/impl/local_conversation.py openhands-sdk/openhands/sdk/conversation/impl/remote_conversation.py openhands-sdk/openhands/sdk/llm/__init__.py openhands-sdk/openhands/sdk/llm/router/__init__.py openhands-sdk/openhands/sdk/llm/router/base.py openhands-sdk/openhands/sdk/llm/router/impl/configurable.py tests/agent_server/test_conversation_router.py tests/agent_server/test_server_details_router.py tests/sdk/conversation/test_switch_model.py tests/sdk/llm/test_router_llm.py
  • cd clients/typescript && npm test -- src/__tests__/api-clients.test.ts
  • cd clients/typescript && npm run lint && npm run build && npm run format:check

Video/Screenshots

Screen.Recording.2026-11-14.at.2.53.58.PM.mov

Design Doc

https://htmlpreview.github.io/?https://github.com/OpenHands/software-agent-sdk/blob/feat/runtime-model-router-routes/.pr/model-router-design.html

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

This PR was created by an AI agent (OpenHands) on behalf of the user.

@malhotra5 can click here to continue refining the PR


🐳 Agent Server images for this PR — GHCR package, pull/run commands, and all pushed tags (click to expand)

• GHCR package: https://github.com/OpenHands/agent-sdk/pkgs/container/agent-server

Variants & Base Images

Variant Architectures Base Image Docs / Tags
java amd64, arm64 eclipse-temurin:17-jdk Link
python-slim amd64, arm64 python-node-runtime Link
python-minimal amd64, arm64 python-node-runtime Link
python amd64, arm64 python-node-runtime Link
golang amd64, arm64 golang:1.21-bookworm Link

Pull (multi-arch manifest)

# Each variant is a multi-arch manifest supporting both amd64 and arm64
docker pull ghcr.io/openhands/agent-server:29694c0-python

Run

docker run -it --rm \
  -p 8000:8000 \
  --name agent-server-29694c0-python \
  ghcr.io/openhands/agent-server:29694c0-python

All tags pushed for this build

ghcr.io/openhands/agent-server:29694c0-golang-amd64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-golang-amd64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-golang-amd64
ghcr.io/openhands/agent-server:29694c0-golang_tag_1.21-bookworm-amd64
ghcr.io/openhands/agent-server:29694c0-golang-arm64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-golang-arm64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-golang-arm64
ghcr.io/openhands/agent-server:29694c0-golang_tag_1.21-bookworm-arm64
ghcr.io/openhands/agent-server:29694c0-java-amd64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-java-amd64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-java-amd64
ghcr.io/openhands/agent-server:29694c0-eclipse-temurin_tag_17-jdk-amd64
ghcr.io/openhands/agent-server:29694c0-java-arm64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-java-arm64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-java-arm64
ghcr.io/openhands/agent-server:29694c0-eclipse-temurin_tag_17-jdk-arm64
ghcr.io/openhands/agent-server:29694c0-python-amd64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-amd64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-amd64
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-amd64
ghcr.io/openhands/agent-server:29694c0-python-arm64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-arm64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-arm64
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-arm64
ghcr.io/openhands/agent-server:29694c0-python-minimal-amd64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-minimal-amd64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-minimal-amd64
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-minimal-amd64
ghcr.io/openhands/agent-server:29694c0-python-minimal-arm64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-minimal-arm64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-minimal-arm64
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-minimal-arm64
ghcr.io/openhands/agent-server:29694c0-python-slim-amd64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-slim-amd64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-slim-amd64
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-slim-amd64
ghcr.io/openhands/agent-server:29694c0-python-slim-arm64
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-slim-arm64
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-slim-arm64
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-slim-arm64
ghcr.io/openhands/agent-server:29694c0-golang
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-golang
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-golang
ghcr.io/openhands/agent-server:29694c0-golang_tag_1.21-bookworm
ghcr.io/openhands/agent-server:29694c0-java
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-java
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-java
ghcr.io/openhands/agent-server:29694c0-eclipse-temurin_tag_17-jdk
ghcr.io/openhands/agent-server:29694c0-python-minimal
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-minimal
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-minimal
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-minimal
ghcr.io/openhands/agent-server:29694c0-python-slim
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python-slim
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python-slim
ghcr.io/openhands/agent-server:29694c0-python-node-runtime-slim
ghcr.io/openhands/agent-server:29694c0-python
ghcr.io/openhands/agent-server:29694c0cd5974292d4f32099546c39dadaf49ac1-python
ghcr.io/openhands/agent-server:feat-runtime-model-router-routes-python
ghcr.io/openhands/agent-server:29694c0-python-node-runtime

About Multi-Architecture Support

  • Each variant tag (e.g., 29694c0-python) is a multi-arch manifest supporting both amd64 and arm64
  • Docker automatically pulls the correct architecture for your platform
  • Individual architecture tags (e.g., 29694c0-python-amd64) are also available if needed

@github-actions

github-actions Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Coverage

Coverage Report •
FileStmtsMissCoverMissing
openhands-agent-server/openhands/agent_server
   conversation_router.py3672194%130–131, 134–135, 347, 481, 530, 615, 696, 712, 769, 773–774, 874, 936–938, 982, 1019–1020, 1051
   event_service.py117711890%206, 212–213, 347–348, 472, 476, 481, 508, 515, 550, 553–554, 558–559, 570, 576, 647–648, 654, 710–711, 832, 852, 881, 891, 915–916, 920, 973, 1008, 1012–1013, 1048, 1055, 1061, 1278, 1311, 1314, 1392, 1410, 1424, 1597–1598, 1654, 1688, 1844–1847, 1851, 1898, 1902, 1909, 1923, 1939, 1947, 1971, 2018–2020, 2111, 2133, 2136–2137, 2164, 2172, 2188, 2190, 2197, 2205, 2207–2208, 2212, 2229, 2249, 2302, 2313–2316, 2325, 2330, 2333, 2338, 2347–2348, 2355, 2370, 2381, 2422–2425, 2509–2510, 2512–2519, 2521–2522, 2532, 2543, 2559–2560, 2571, 2598, 2604, 2615, 2624–2625, 2647, 2657
   server_details_router.py82298%34–35
openhands-sdk/openhands/sdk/conversation/impl
   local_conversation.py14219593%204, 452, 519, 555–558, 560, 815–816, 940, 1402, 1404, 1475, 1599, 1631, 1766–1767, 1773, 1782–1785, 1832, 1845, 1869–1870, 1876–1878, 1902, 1909–1912, 1965, 1986–1988, 2037, 2169, 2508–2509, 2513, 2518, 2521, 2529–2530, 2534–2536, 2558–2562, 2565, 2569–2570, 2580–2582, 2588, 2592–2593, 2693, 2890, 2893–2894, 3114, 3151, 3155, 3159, 3180, 3232, 3236, 3270, 3277–3278, 3286, 3290–3291, 3295, 3302, 3611–3612, 3630–3631, 3666, 3881, 3885, 3906, 3957, 3964–3965
   remote_conversation.py8898491%146, 223, 250, 263, 265–268, 314–315, 338–341, 348–349, 354–357, 441, 451–453, 459, 543–544, 720, 726–729, 732, 753, 761, 874, 910, 969–970, 974–975, 990, 1061, 1067, 1176–1179, 1230–1231, 1255–1256, 1289–1290, 1324–1325, 1347, 1357, 1361, 1370–1371, 1415, 1571–1572, 1671–1672, 1676, 1681–1685, 1755, 1760, 1769, 1774, 1780, 1785, 1791, 1794, 1799, 1810, 2103–2104
openhands-sdk/openhands/sdk/llm/router
   base.py1612982%63, 66, 78, 89–90, 95–96, 105, 112–114, 118–119, 126, 144, 150, 157, 175, 193, 196, 199, 294, 314, 336, 357–359, 362, 365
TOTAL57526927984% 

@github-actions

github-actions Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Contributor

REST API breakage checks (OpenAPI) — ✅ PASSED

Result: ✅ PASSED

Action log

@malhotra5
malhotra5 force-pushed the feat/runtime-model-router-routes branch from 512ca65 to 06f43c3 Compare November 15, 2026 00:34
@github-actions

Copy link
Copy Markdown
Contributor

📁 PR Artifacts Notice

This PR adds or changes temporary PR-specific documents under .pr/. They stay available on this branch for review; after merge, the next release PR removes .pr/ from main.

@all-hands-bot all-hands-bot mentioned this pull request Nov 15, 2026
1 of 5 tasks
@malhotra5
malhotra5 marked this pull request as ready for review November 15, 2026 04:43
@malhotra5
malhotra5 force-pushed the feat/runtime-model-router-routes branch from 06f43c3 to e07f796 Compare November 15, 2026 04:53
@malhotra5
malhotra5 force-pushed the feat/runtime-model-router-routes branch 2 times, most recently from 7e6a552 to 8beddba Compare November 15, 2026 18:31
Co-authored-by: openhands <openhands@all-hands.dev>
@malhotra5
malhotra5 force-pushed the feat/runtime-model-router-routes branch from 8beddba to 39722c2 Compare November 15, 2026 18:47
…outes

# Conflicts:
#	openhands-agent-server/openhands/agent_server/conversation_router.py
#	openhands-agent-server/openhands/agent_server/event_service.py
#	openhands-agent-server/openhands/agent_server/models.py
#	openhands-agent-server/openhands/agent_server/server_details_router.py
#	tests/agent_server/test_server_details_router.py
@github-actions

Copy link
Copy Markdown
Contributor

Agent-server conversation start benchmark

Base feat/router-llm-state@1215a88b0a6ddffcd2feb22031226238543442 vs this PR merge 71a23ac538, measured in the same job on the same runner, interleaved: 5 server starts per side and scenario. Medians with 95% bootstrap CIs. The LLM is a mock that answers instantly, so this is agent-server overhead only.

base this PR change
Create conversation (warm) 0.133 s [0.102, 0.155] 0.110 s [0.092, 0.141] -18% ≈ same
↳ first agent event 0.188 s [0.148, 0.209] 0.142 s [0.135, 0.192] -24% ≈ same
First create right after server start 0.352 s [0.195, 0.524] 0.306 s [0.109, 0.456] -13% ≈ same
↳ first agent event 0.505 s [0.338, 0.759] 0.452 s [0.238, 0.657] -10% ≈ same
First create 3 s after server start 0.165 s [0.120, 0.230] 0.145 s [0.122, 0.293] -12% ≈ same
↳ first agent event 0.376 s [0.274, 0.465] 0.304 s [0.287, 0.629] -19% ≈ same
Create in a new git worktree (warm, 0.5 s git fetch) 0.702 s [0.689, 0.752] 0.691 s [0.657, 0.714] -2% ≈ same
↳ first agent event 0.763 s [0.739, 0.817] 0.750 s [0.710, 0.772] -2% ≈ same
Worktree creates that stalled the server > 20 ms 1/20 (5%) 0/20 (0%) -5 pts ≈ same
Create with one stdio MCP server (warm, 3 s startup) 1.146 s [1.101, 1.169] 1.183 s [1.158, 1.191] +3% ≈ same
↳ first agent event 4.019 s [3.665, 4.223] 4.294 s [3.982, 4.404] +7% ≈ same
Creates that stalled the server > 20 ms 0/35 (0%) 0/35 (0%) +0 pts ≈ same
Server startup (/alive) 4.159 s [3.873, 6.065] 4.656 s [3.924, 6.331] +12% ≈ same
How this is measured

Each create is a Canvas-shaped POST /api/conversations (agent profile, worktree: true, first message included, so the request waits for agent startup). A side task polls /alive every 20 ms to catch event-loop stalls. Scenarios, each on its own server starts:

  • default: a fresh directory per create, 8 creates per start.
  • pause: the first create waits 3 s after startup, as a user opening the UI would.
  • worktree: every create branches a new worktree from a local repository whose origin answers fetches after 0.5 s.
  • mcp: the agent profile enables one stdio MCP server that starts after 3 s, like an npx/uvx launch.

A timing is flagged when the 95% CIs do not overlap and the medians differ by at least 50 ms, or when a row with at least 8 samples per side moves by at least 150 ms and 25%. A create stalled the server when its slowest /alive took over 20 ms; stall rows are flagged when the share of stalled creates moves by at least 20 points with a Fisher exact p below 0.01. The first-create rows have one sample per server start, so they are flagged only on a clear change. A "↳ first agent event" row times the create above it until the agent's first event arrives on a socket opened after the create returns, as Agent Canvas does, so it includes the connect and replay. Runner: blacksmith-2vcpu-ubuntu-2404-bq3h5i4cic7szgsk, 176 environment variables. Run it locally with python scripts/agent_server_benchmarks/conversation_start.py --help.

@all-hands-bot all-hands-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This review was posted by an AI agent (OpenHands).

Scope gate: pass. The change sits squarely in this repository's ownership (Python SDK router, Agent Server REST endpoint, TypeScript client mirror, in the documented SDK → OpenAPI → clients/typescript flow). Linked issue #6860 is open, labeled enhancement/llm/sdk, and marked ready-for-dev; the PR's scope matches the issue's acceptance criteria, so no maintainer decision is needed.

Verification on head 29694c0c:

  • All GitHub Actions checks pass for this exact head (REST API OpenAPI contract, persisted settings, endpoint audit, benchmark, sdk/agent-server/typescript suites included).
  • Ran locally: tests/sdk/llm/test_router_llm.py + tests/sdk/conversation/test_switch_model.py (51 passed), tests/agent_server/test_conversation_router.py + test_server_details_router.py (145 passed), TypeScript api-clients.test.ts (103 passed), plus npm run build and npm run lint (0 errors; the 5 warnings are pre-existing in files this PR does not touch).
  • Exercised the real runtime path on a LocalConversation (throwaway script, deleted afterward): starting from a plain LLM, add_model_router_route wraps the agent LLM into a RouterLLM with routes [default, reviewer]; a second route extends the existing router; duplicate route names are rejected with a clear ValueError; manual switch and return-to-auto update selection correctly; registry identity is preserved (profile:<name> resolves to the installed route LLM); the persisted-state round-trip keeps the route snapshot taken at install time; missing profiles raise FileNotFoundError.

Cross-layer checks: the new POST /model_router/routes endpoint is additive (OpenAPI contract check green) and advertised via the conversation_model_router_routes_v1 capability; EventService.add_model_router_route delegates to the conversation on an executor and publishes a state update, mirroring add_mcp_servers, and its ValueError("inactive_service") matches the documented ServiceInactive type/message contract; except ValueError → 400 mirrors the existing add_mcp_servers route. RemoteConversation gains the full model-router surface (get_model_router, add_model_router_route, selection update/switch/auto), closing the previous gap where the PATCH /model_router endpoint had no Python remote client method. LLM registration after the swap (_register_agent_llms) follows the same policy as conversation-init registration. Existing switch_llm/switch_profile behavior is untouched, matching the issue's non-goal, and no persisted-settings schema migration is involved.

No dependency changes (seven-day release-age policy not triggered). One eval note for the human maintainer, not a defect: this adds a new routing API surface; the benchmark and behavior checks pass, and the PR includes a downstream Agent Canvas manual-switching video, but per the review guide the maintainer may opt for a lightweight evaluation if desired.

No material correctness, security, compatibility, or acceptance-criterion defects found.

✅ APPROVED

@juanmichelini juanmichelini left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@malhotra5
malhotra5 merged commit 70ead0f into main Nov 19, 2026
108 of 110 checks passed
@malhotra5
malhotra5 deleted the feat/runtime-model-router-routes branch November 19, 2026 00:07
@enyst enyst mentioned this pull request Nov 19, 2026
1 of 5 tasks
VascoSch92 added a commit that referenced this pull request Nov 25, 2026
…store

Main gained two profile loads that pass the cipher per call:
LocalConversation.add_model_router_route (#6835) and resolution_judge
(#6962). The conversation's store and the server's store are bound to
their cipher, so both now load and save without naming it.

resolution_judge(cipher=...) was published in 1.63.0. It stays as a
deprecated argument that binds the store, scheduled for removal in 1.70.0.
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.

4 participants