Code questions and short factual questions put different demands on a chat model. AnythingLLM's model router sends matching prompts to a chosen model while a fallback model handles other messages.

Calculated rules compare message content or other properties without an extra LLM classification call. Keyword matching fits a known term in the prompt; it does not estimate how difficult a question is.

Start with an existing workspace, permission to edit instance and workspace settings, and a working Ollama connection with two downloaded chat models. Assigning a router changes which model handles subsequent prompts for everyone using that workspace.

Steps to create a model router in AnythingLLM with Ollama:

  1. Open AnythingLLM's settings with the wrench icon at the bottom of the sidebar.
  2. Expand AI Providers in the settings sidebar.
  3. Open Model Router under AI Providers.
  4. Click New Router.
  5. Enter Prompt Router in Name.

    The router name can be any unused name. Primary Provider & Model should already show Ollama from the system provider settings.

  6. Select your smaller chat model under Primary Provider & Model.

    This is the fallback when no rule matches. The screenshots use installed models named small-chat:latest and code-chat:latest; your downloaded models can have different names. The fallback is small-chat:latest and the rule will use code-chat:latest.

  7. Set Cache Cooldown (seconds) to 0.

    The default is 300 seconds. A positive cooldown keeps the last matched model active for non-matching follow-ups within that window. Zero disables this sticky routing so the fallback can answer the next non-matching prompt.

  8. Click Create Router.
  9. Open Prompt Router from the saved router list.
  10. Click New Rule.
  11. Enter code_questions in Title.

    Rule Type starts at Calculated, which uses message properties rather than asking an LLM to classify the prompt.

  12. Select Prompt Content under Property.
  13. Set Comparator to contains.
  14. Enter python in Value.

    The match is case-insensitive. A prompt containing python will match this rule even when it is not asking for code.

  15. Select Ollama under Route to Provider & Model.
  16. Select your other chat model in the rule's model dropdown.

    The screenshots select code-chat:latest, which must differ from the fallback model for the two routing results to be distinguishable.

  17. Click Create Rule.
  18. Return to workspaces with the back arrow at the bottom of the settings sidebar.
  19. Open your workspace's settings with its sidebar gear icon.

    Router Desk is the existing workspace shown in the screenshots.

  20. Open the Chat Settings tab.
  21. Select Chat under Chat mode.

    New workspaces start in Agent mode. Chat mode tests ordinary replies without entering an agent session.

  22. Open the Workspace LLM Provider menu.
  23. Select Model Router from the provider list.
  24. Select Prompt Router from Select a router.
  25. Reload Chat Settings after Saved appears.

    The provider, router, and mode remain at Model Router, Prompt Router, and Chat after reload. A reverted selection means the settings were not retained.

  26. Return to the workspace chat with the back arrow above the settings tabs.
  27. Enter Write one line of python that prints hello. in the message box.
  28. Send the prompt with the upward-arrow button.
  29. Confirm that the completed reply shows Routed to code-chat:latest via code_questions.

    The model name must match your rule's selected model. The reply wording can vary; a model's claim about its own identity is not a routing check.

  30. Enter Say hello. in the same conversation's message box.

    This prompt does not contain python, so it does not match the rule.

  31. Send the greeting with the upward-arrow button.
  32. Hover over the completed greeting reply to reveal its model footer.
  33. Confirm that the greeting's footer names your fallback model.

    The screenshots show small-chat:latest after the earlier reply used code-chat:latest. An error, an unfinished reply, or the rule model answering both prompts with cooldown zero means routing is not working as configured.

Share this guide