Skip to content

Support local LLM endpoints for Stratus and OpenCode - #917

Merged
Saadmrp1038 merged 6 commits into
mainfrom
stratus-local-llm-endpoints
Jul 2, 2026
Merged

Saadmrp1038 merged 6 commits into
mainfrom
stratus-local-llm-endpoints

Conversation

@munimthahmid

@munimthahmid munimthahmid commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

This is the first step toward local LLM support in SREGym (#915). This PR adds local endpoint support for Stratus and OpenCode, so models such as Qwen or DeepSeek served through Ollama or other compatible local runtimes can be used by passing an API base URL.

Changes

  • Add AGENT_API_BASE / AGENT_API_KEY for the agent model endpoint
  • Add JUDGE_API_BASE / JUDGE_API_KEY for the judge model endpoint
  • Forward generic agent/judge endpoint env vars into the SREGym Docker environment
  • Pass endpoint config into the shared LiteLLM backend
  • Add per-run OpenCode config for local OpenAI-compatible endpoints
  • Automatically route loopback agent endpoints into Docker on macOS and WSL
  • Update Stratus preflight to use the same backend path as the agent and verify tool calling support

Why update Stratus preflight?

Stratus depends on tool calls during normal execution. The previous preflight only checked a minimal text completion, which can pass even if the configured local model cannot return tool calls in the shape Stratus needs. The updated preflight catches that early before starting a benchmark run.

I think it makes the local LLM support safer to use. But open to discussion about this.

Validation

  • Stratus preflight passed with gpt-5
  • Stratus preflight passed with local ollama_chat/qwen2.5:3b
  • End-to-end agent run with ollama_chat/qwen2.5:3b entered diagnosis and executed get_services, then hit the run timeout
  • End-to-end agent run with ollama_chat/qwen3-1.7b-fast produced a diagnosis after multiple tool calls, then failed in mitigation due to the model context limit
  • OpenCode local endpoint calls passed with local/qwen2.5:3b; an end-to-end run connected successfully and exported its session, but the model did not solve the task
  • Ruff passed
  • git diff --check passed

@munimthahmid
munimthahmid requested a review from Saadmrp1038 June 29, 2026 06:02

@Saadmrp1038 Saadmrp1038 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.

Thanks @munimthahmid!

The preflight update is fine.

One thing though, what value did you use for AGENT_API_BASE in your testing? I'm asking because I expected a host-local endpoint (localhost:11434) to need some networking work to be reachable from inside the agent container. We hit a similar thing with MCP_SERVER_PORT. It worked on Linux but broke on WSL and macOS, and we had to rewrite to host.docker.internal.

        if self.config.network_mode == "host" and platform.system() == "Darwin" or self.config.network_mode == "host":
            env_vars["API_HOSTNAME"] = "host.docker.internal"
            mcp_port = env_vars.get("MCP_SERVER_PORT", os.environ.get("MCP_SERVER_PORT", "9954"))
            env_vars["MCP_SERVER_URL"] = f"http://host.docker.internal:{mcp_port}"

Also, it seems there's some logic duplication here...
Instead of if (host and Darwin) or host we can simply do if host and update the comment. I think at some point we decided to just avoid the complexity and aways route to host.docker.internal . Can u please address this also?

Comment thread main.py Resolved
@Saadmrp1038

Saadmrp1038 commented Jun 29, 2026 •

Copy link
Copy Markdown
Collaborator

@munimthahmid also can you check with opencode if the local LLM works please? I do want to add more open source agents so that people can test more smootly with local LLMs.

@munimthahmid
munimthahmid force-pushed the stratus-local-llm-endpoints branch from 7800d5a to 923ec6d Compare June 29, 2026 07:14
@munimthahmid

Copy link
Copy Markdown
Collaborator Author

@Saadmrp1038 Yes, I’m already looking into OpenCode next. SREGym’s OpenCode wrapper doesn’t actually support local LLMs out of the box yet, even though OpenCode upstream does.(ex. It rejects ollama/qwen2.5:3b as an unknown provider)

@Saadmrp1038

Copy link
Copy Markdown
Collaborator

Interesting. Thanks for looking into it.

Comment thread README.md Resolved
@munimthahmid

Copy link
Copy Markdown
Collaborator Author

@Saadmrp1038 added local LLM support with OpenCode

@munimthahmid munimthahmid changed the title Support local LLM endpoints for Stratus Support local LLM endpoints for Stratus and OpenCode Jun 30, 2026
@Saadmrp1038
Saadmrp1038 self-requested a review June 30, 2026 13:18

@Saadmrp1038 Saadmrp1038 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.

@munimthahmid I think in current code logic JUDGE_MODEL_ID always gets passed to LiteLLMBackend. So, that means if someone passes a provider/model string in the --judge-model arg expecting to use local LLM as a judge it might get blocked due to litellm not recognizing it. Can you check this out? Ideal case is litellm will use that local llm as a judge. I am not sure if litellm needs something else to use local LLMs.

The edge case I am thinking about is someone runs opencode with local model using the provider/model format that opencode expects. If they just pass --model param that mode will also be used for the judge and the naming format might clash with litellm.

This could also be a nothing burger and maybe litellm is already compatible with opencode's naming format. Can you please test this out though?

@munimthahmid

Copy link
Copy Markdown
Collaborator Author

@Saadmrp1038 your observation is correct. LiteLLM is not compatible with the OpenCode style format. OpenCode expects the local LLM model to be in local/model format, whereas LiteLLM expects it to be provider/model. And for this edge case specifically, I added this in the README:

When --judge-model is not set, SREGym reuses the agent model and endpoint for the judge. This works directly for Stratus because its model identifier is LiteLLM-compatible. OpenCode's local/ provider is OpenCode-specific, so its judge must use a LiteLLM identifier such as ollama_chat/qwen3-coder:30b.

However, if we want to handle this programmatically, one approach can be to normalize the local/model name to openai/model only for the judge path, since the OpenCode local endpoint is OpenAI-compatible. Then I think it should work in most scenarios.

@Saadmrp1038

Saadmrp1038 commented Jul 1, 2026 •

Copy link
Copy Markdown
Collaborator

@munimthahmid Sounds good.

if we want to handle this programmatically

Let's try to handle this programmatically if it's easy to do. Along with #922 user will also get fast feedback on wrong model string.

@munimthahmid

Copy link
Copy Markdown
Collaborator Author

@Saadmrp1038 handled it programmatically now

@Saadmrp1038

Copy link
Copy Markdown
Collaborator

LGTM

os.environ["JUDGE_API_KEY"] = "dummy"

Also, I find it weird that litellm does not handle this natively.

@Saadmrp1038
Saadmrp1038 merged commit ae83ace into main Jul 2, 2026
6 checks passed
@Saadmrp1038
Saadmrp1038 deleted the stratus-local-llm-endpoints branch July 2, 2026 03:53
vsmart-06 pushed a commit to vsmart-06/SREGym that referenced this pull request Jul 12, 2026
* Support local LLM endpoints for Stratus

* Prefer env vars for local LLM endpoints

* Support local LLM endpoints for OpenCode

* Route local endpoints into agent containers

* Normalize OpenCode local judge models

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Saadmrp1038 added a commit that referenced this pull request Jul 22, 2026
* Updated default mitigation oracle

* Stop timeout for 0 replicas

* TBC in CloudLab

* Pushing all attempts at the problem

* Enable idempotence

* Add mutating_webhook_resource_limits problem (#847)

* Add mutating_webhook_resource_limits problem

* Add mutating_webhook_resource_limits to Problem List

* mutating_webhook_resource_limits problem docstring fix

Removed incorrect information about mitigation options.

* Additions to mutating_webhook_limits_resource_limits problem

 - Memory limit/request patching before activating the webhook
 - Decoy pods for increased complexity

* More additions to mutating_webhook problem

 - Make decoys realisticly named
 - Similar minor changes

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Derive the default problem namespace from the application (#876)

* add the the probem redundency

* base.

* the fixed and dynamic app name are fixed. hte namespace are also fixed.

* unessessry formating is reverted.

* unessessry formating is reverted.

* formating correction.

* formating correction.

* formating correction.

* add fault injection decorator markers to test_problem_bsae.py

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Confluent kafka attempt

* Custom image attempt

* Threaded producer and added consumer

* Syntax error

* Added some imports

* fix edge cases

* run ruff check adn format

* New OOM attempt

* Force crash on OOM

* Add file_descriptor_exhaustion problem (#832)

* add file_descriptor_exhaustion problem

* Modify fault injection and recovery methods

* Fix fault recovery

* Change fault injection method
Add fault injection by flooding connections

* Update fault injection method and add custom oracle

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Finalizer deadlock controller clean (#873)

* finalizzer code is reaoslve dadlock benchmark.

* yaml file corrected.

* reverting hte comments back to their place.

* read only rbac

* controller log is generalized and avoiding any sregym related name exposing.

* applied ruff linter formatter accordingly.

* replace metadata naming and includding all the oprations on mitigation side.

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add: secret_rotation_stale_env_credentials_astronomy_shop problem (#851)

* Add secret rotation stale env credentials problem

* Simplify secret rotation mitigation oracle checks

* Require rotated PostgreSQL in oracle

* Fix stale DB credential rotation shortcuts

  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods

* Fix fault recovery to satisfy the oracle

* Fix problem registry import ordering

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add cumulative_admission_webhook_timeout_hotel_reservation problem (#886)

* Add cumulative_admission_webhook_timeout_hotel_reservation problem

* Pin webhook backends to worker nodes via nodeAffinity

* Make webhook backends realistic admission services

Replace the dummy webhook backends with HTTPS admission servers that terminate TLS using Secret-mounted certificates, validate AdmissionReview

requests, and return proper admission responses. Certificates are signed by the same CA referenced in each webhook's `caBundle`, with SANs

covering the backend Service DNS names.

The admission logic enforces a trusted image registry allowlist and a

per-container CPU limit. All Hotel Reservation workloads satisfy these

policies, so the webhooks remain transparent during normal operation and

recovery.

Also:
* Vary webhook `timeoutSeconds` (12, 8, 11, 9) to make the cumulative
  timeout less obvious.

* Rename the CA CN from `sregym-webhook-ca` to
  `compliance-webhook-ca`.

* Remove a duplicate `rule.from_` check in the oracle.

* Fix create-or-replace handling for webhooks, NetworkPolicies,
  Deployments, and Services so re-injection updates existing resources
  instead of failing or silently skipping changes.

* Model the fault as a missing apiserver NetworkPolicy allow

* Model the fault as a missing apiserver allow with a near-miss policy

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Add psa_restricted_blocks_recreation problem (#891)

Labelling a namespace pod-security.kubernetes.io/enforce=restricted leaves
running pods untouched but makes the apiserver reject recreated pods that run
as root / set no seccomp profile, so a deployment silently goes
under-replicated. Unlike the existing webhook problems, the policy is enforced
by the apiserver via a namespace label, not a webhook config.

* Add copilot cli agent (#893)

* add copilot cli agent

* remove -s flag

* Fix MCP retry error handling and CRLF parsing in CI (#896)

* fix(mcp): broaden MCP retry exceptions and return error instead of raising

* fix(ci): strip CRLF from PR description before parsing problem ID

* Fix kind cluster detection (#897)

* Fix custom kind cluster detection

* Handle failed kind detection output

* fix edge cases

* run ruff check adn format

* Shell state persistence (#903)

* Include shell persistence

* Include shell persistence

* Isolate problem IDs from agent runtime artifacts

* update SREGym-applications (18620ed) (#910)

* Add Calico route-reflector label drift problem (#828)

* Add Calico route-reflector label drift problem

* Address Calico route-reflector review comments

* Harden Calico cleanup ownership tracking

* Fix Codex agent install verification

* Tighten Codex platform package detection

* Restore kubelet eviction reset cleanup

* Neutralize Calico ownership metadata

---------

Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Fail alert oracle on Prometheus query errors (#912)

* Decouple failure configmaps from mongo pods in `hotel-reservation` (#899)

* decouple failure configmaps from mongo pods

* remove empty failure configmaps creation

* Support local LLM endpoints for Stratus and OpenCode (#917)

* Support local LLM endpoints for Stratus

* Prefer env vars for local LLM endpoints

* Support local LLM endpoints for OpenCode

* Route local endpoints into agent containers

* Normalize OpenCode local judge models

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Preflight check the judge model (#924)

* Add support for uniform agent trajectory (ATIF format) (#918)

* add support for ATIF trajectory conversion and normalization, add claudecode adapter

* fix: make _finish_problem idempotent

* isolate .codex mount in container runner

* better temp dir cleanup

* add codex adapter

* add opencode adapter

* add copilot adapter

* add stratus adapter

* fix antropic caching for stratus

* add gemini adapter

* store normalized ATIF trajectories in SQLite indexed by problem type

* edge tests

* bump litellm, tikoken

* update docker lib versions

* Add node_clock_drift Problem  (#894)

* adding clock drift problem

* fixing race condition causing sidecar log delay

* fixing recover_fault to reverse time sync removal applied, improve cleanup

* global cleanup added + fixed restoration for node_clock_drift problem

* fixing mitigation oracle to ensure correct node checked

* adding problem to non emulated cluster problems list

* extending wait

* indentation error fix

* fixing time restoration in global cleanup

* adding in check to make sure it picks worker node

* adding another control plane filter, fixing clock step-back in global recovery

* increase sidecar rollout timeout, make podnames/labels generic, idempotancy check

* formatting fixes

* format fix

* fix

* fix ruff check/format issues

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>

* Minimum viable python version

* Changed diagnosis oracle

* Cleaned up fault recovery

* Edit tasklist.yml

* Removed old Java artifacts

* Updated mitigation oracle to be more robust

* Added polling

* Fail Kafka producer leak injection on timeout

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Co-authored-by: Kerem Akcalioglu <[email protected]>
Co-authored-by: ermias mulugeta <[email protected]>
Co-authored-by: Tejas Shukla <[email protected]>
Co-authored-by: Petr Myagkov <[email protected]>
Co-authored-by: Omar Faruqe Riyad <[email protected]>
Co-authored-by: Mohammad Tamimul Ehsan <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Om Kumar <[email protected]>
Co-authored-by: Munim Thahmid <[email protected]>
Co-authored-by: Tanzim Hossain Romel <[email protected]>
Co-authored-by: haani-maybe <[email protected]>
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.

2 participants