Skip to content

[OMEGA-376] LLM router, allows choice of routine or premium models - #419

Open
jazzbox35 wants to merge 41 commits into
BGI-Foundry:mainfrom
jazzbox35:LLM-Route-Phase-1-second-attempt
Open

jazzbox35 wants to merge 41 commits into
BGI-Foundry:mainfrom
jazzbox35:LLM-Route-Phase-1-second-attempt

Conversation

@jazzbox35

@jazzbox35 jazzbox35 commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

Description

This PR substantially meets the requirements specified in "phase 1" of implementing an LLM router and catalog.

TLDR: You can now specify a cheap or expensive model. This works with all of our providers.

LLM_Router.pdf

Note: I marked this ready for review since I think the review can commence. But, there are a couple of tweaks still needed that can be discussed.

How Has This Been Tested?

It does appear to work fine using the usual script and also a regular "docker run" command. Still needs testing under standalone install.

Checklist

  • PR contains autogenerated code
  • Self-review completed
  • Test scenarios above are passed with the version of the code from PR

@jazzbox35
jazzbox35 marked this pull request as ready for review November 6, 2026 06:44
@alyona-snet alyona-snet changed the title LLM router, allows choice of routine or premium models [OMEGA-376] LLM router, allows choice of routine or premium models Nov 6, 2026
Comment thread src/loop.metta Resolved
Comment thread scripts/omega Resolved
Comment thread proxy/nginx.conf.template Resolved
Comment thread src/config.py Resolved
Comment thread tests/test.sh Resolved
@andre-senna
andre-senna self-requested a review November 12, 2026 10:14
@andre-senna

andre-senna commented Nov 12, 2026 •

Copy link
Copy Markdown
Collaborator

@jazzbox35 @alyona-snet

Regarding my review of this PR, I considered that the Specification attached to the Jira card OMEGA-376 named "Omega LLM Router – General Specification" has been approved. So I approved this PR because it's compliant with that specification. However, I have a consideration regarding the design which I believe must be addressed. Ideally it should be addressed BEFORE merging the PR but optionally it could be addressed in the scope of a follow-up task.

My point is that the Router plugin really should have an abstract element used in the main loop. /plugins/routers should contain this abstract router AND any concrete implementations (currently, the "default router"). The reason for this is to avoid the need of changing anything outside plugins/routers in order to implement and setup new routers (which I strongly believe we'll want to do). This point is a very important one, IMO, as I believe ALL plugins should follow the same pattern. Although it's not currently addressed in this PR, I opted for approving it anyway because the author provided thorough instructions on how to attach a new router in the plugin README. But, again, I strongly recommend that this issue be addressed, preferably before merging this PR.

Were we implementing the router in Python it would be just a matter of creating an abstract class in a separate file and let any concrete router extend it. But our router is in MeTTa and, to be honest, I'm not sure what's the best way to implement this type of polymorphism (or something with equivalent effect) in MeTTa. However, I believe the worst-case scenario is just to have the abstract router file define a function (which will be the one called from outside i.e. the public API) and make a sort of switch in this function calling the concrete implementation we want to hook up. In other words, the abstract metta router would work as both: the public API call + a factory method that actually makes the call to the desired concrete router.

andre-senna
andre-senna previously approved these changes Nov 12, 2026
@andre-senna

Copy link
Copy Markdown
Collaborator

@jazzbox35 @alyona-snet

Another point that needs to be at least clarified if not addressed.

I'm not (hands on) familiar with the use of embedding vectors. But it seems to me like we are persisting embeddings in a DB and if the user switches from one provider to another this persistence may become invalid or corrupted. I mean, perhaps we should change where we persist embedding according to the actual provider being used. I didn't raise this as a "finding" in the PR because I'm not sure it's really an issue.

@jazzbox35

Copy link
Copy Markdown
Collaborator Author

@jazzbox35 @alyona-snet

Another point that needs to be at least clarified if not addressed.

I'm not (hands on) familiar with the use of embedding vectors. But it seems to me like we are persisting embeddings in a DB and if the user switches from one provider to another this persistence may become invalid or corrupted. I mean, perhaps we should change where we persist embedding according to the actual provider being used. I didn't raise this as a "finding" in the PR because I'm not sure it's really an issue.

Currently if the user switches embedding types (switching Local and OpenAI by rerunning the script or resetting the value in standalone mode) there will be incompatibilities. So it's in essence an existing issue. We could devise some kind of guardrails but the point is the LLM router doesn't really change the nature of the problem. It could still happen. It's just that with the router there is more than one provider. We only retrieve text back from the LLM now, so whether memory is converted to embeddings using OpenAI's tools or the local embeddings (which we get from huggingface I think), either works (local embeddings or OpenAI). It's just that you can't switch one to the other. So it really needs some kind of guardrailing anyway, and also Nebiyu has an idea of conversion too.

@jazzbox35

jazzbox35 commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator Author

@jazzbox35 @alyona-snet

Regarding my review of this PR, I considered that the Specification attached to the Jira card OMEGA-376 named "Omega LLM Router – General Specification" has been approved. So I approved this PR because it's compliant with that specification. However, I have a consideration regarding the design which I believe must be addressed. Ideally it should be addressed BEFORE merging the PR but optionally it could be addressed in the scope of a follow-up task.

My point is that the Router plugin really should have an abstract element used in the main loop. /plugins/routers should contain this abstract router AND any concrete implementations (currently, the "default router"). The reason for this is to avoid the need of changing anything outside plugins/routers in order to implement and setup new routers (which I strongly believe we'll want to do). This point is a very important one, IMO, as I believe ALL plugins should follow the same pattern. Although it's not currently addressed in this PR, I opted for approving it anyway because the author provided thorough instructions on how to attach a new router in the plugin README. But, again, I strongly recommend that this issue be addressed, preferably before merging this PR.

Were we implementing the router in Python it would be just a matter of creating an abstract class in a separate file and let any concrete router extend it. But our router is in MeTTa and, to be honest, I'm not sure what's the best way to implement this type of polymorphism (or something with equivalent effect) in MeTTa. However, I believe the worst-case scenario is just to have the abstract router file define a function (which will be the one called from outside i.e. the public API) and make a sort of switch in this function calling the concrete implementation we want to hook up. In other words, the abstract metta router would work as both: the public API call + a factory method that actually makes the call to the desired concrete router.

In practical terms the concern seems "to be avoid the need of changing anything outside plugins/routers in order to implement and setup new routers". The design I created will not require changing anything outside the plugins/router for a new router. That is, except the script, which is only set up now in a transition phase. The script will need to be modified to accommodate really using more expansive routers. But, in standalone mode we should now be able to create custom routers. But if someone sees hardcoded terms in Omega proper (not the script) then I need to fix it. I worked hard to try to make this generalized (whether "abstract" enough, I don't know...).

The design idea proposed above seems fine to me, more like using an abstract Python class than using MeTTa code. I think it would indeed be possible to slip in a Python class as most of the design now has a MeTTa module that calls a Python module of the same name, just with a .py suffix. So it can still be done probably, however my belief is that it will be pretty easy to create a new router with just MeTTa.

@TossSky

TossSky commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Tested: this PR at 3de57f6, built into an image and started in three ways, all on IRC: with the launcher from the same commit, with a bare docker run and standalone with sh run.sh. Providers were Anthropic claude-opus-4-8, OpenAI gpt-5.5 and OpenRouter z-ai/glm-5.2, with Local, OpenAI and ASICloud embeddings. Control runs used the same commands on main ba185cd.

What I checked

  • /premium and /routine switch the role, with routine on OpenRouter z-ai/glm-5.2 or OpenAI gpt-5.5 and premium on Anthropic claude-opus-4-8, and every question got an answer.
  • After a failed tool call the next cycle goes to premium, as the alert_failed rule intends. This happened in all 26 cycles after a failed query.
  • A request with 9 tool results goes to premium and one with 8 stays on routine, as the rule for more than 9 user and tool messages intends.
  • With a history longer than the 30000-character window, /premium and /routine still work.
  • scripts/omega start -p Anthropic works as on main. In the interactive setup, y starts two roles and N starts one.
  • A bare docker run with router=default and a two-role OMEGA_ROUTER_CATALOG starts both roles, and so does standalone with a catalog file.
  • An unknown provider= and an empty ANTHROPIC_API_KEY are rejected at start, and the agent process cannot see the keys.
  • test_router_mock.py passes. I added router tests to this PR (63b992e, 2aad23f, d0fa7fc). The new Autotests files and test_router_mock.py are now in run_mandatory (907163b, 9bc5d20). In the CI run on 9bc5d20 the unit tests pass, and Phase 1 ends with 298 passed and 10 failed. Each failure matches an issue below.

Issues

  • Four old ways of starting the agent work on main and fail on the PR, although the PR is meant to stay backward compatible with the old way of entering the provider and model:
    • Standalone start from the README without a catalog exits with code 2 and Could not load router catalog : [Errno 2] No such file or directory: '', with or without provider=. The empty default of routerCatalogFile (config.yaml) is compared only with none (config.metta).
    • A bare docker run with provider= and without router=, as in docs/reference-gpu.md, logs TypeError: unhashable type: 'list' and never calls the model, because llmProviderChat treats only none as no router.
    • A bare docker run without provider= exits with ASI_API_KEY is required for legacy LLM configuration. The default provider in entrypoint.sh is ASICloud, while the README and config.yaml name Anthropic as the default.
    • provider=Anthropic embeddingprovider=OpenAI exits with Unable to prepare router catalog; check catalog fields and output paths, because router_catalog.py requires an OpenAI catalog entry for OpenAI embeddings. The configuration reference does not mention this.
  • With a catalog that has no premium role, /premium keeps logging KeyError: 'premium' (providers.py), and the user gets neither an answer nor an error until they send /routine. A failed tool call with such a catalog ends in the same KeyError.
  • ASICloud embedding requests get 404 from the proxy, because the PR's nginx.conf.template has no /asicloud/ location, while main has one. With the router on, every failed query then sends the next cycle to premium, and in one run 26 of 48 cycles went to claude-opus-4-8 without a request from the user.
  • The undocumented router_catalog= argument of entrypoint.sh exposes the catalog, including its keys, in the container command (docker inspect) and in the host process list.
  • When two users write in the same cycle, the request stays on routine, although the specification names several users in one prompt as a premium case. Each cycle puts exactly one user message into the request (loop.metta), so the rule for more than one user message never fires.

Note

  • The prompt file follows the provider setting, not the provider of the role (loop.metta), so routine on OpenRouter reads prompt.txt instead of prompt_OpenRouter.txt.

Verdict: FAIL. Routing works with a router catalog, but the old ways of starting the agent and several router cases are broken.

@jazzbox35

andre-senna
andre-senna previously approved these changes Dec 4, 2026

@andre-senna andre-senna 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.

@alyona-snet @jazzbox35 @TossSky

After the latest modifications, this PR remains compliant with the specifications outlined in "Omega LLM Router – General Specification". Therefore, I am approving the changes. However, I did not verify whether these changes effectively resolved the issues raised in #419 (comment)

@jazzbox35

Copy link
Copy Markdown
Collaborator Author

This should get kicked back to QA now. Thanks

This branch has not been deployed

No deployments
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.

3 participants