Skip to content

[Bug][multi-agent-shared-context]: LLM_MODEL in .env is ignored - read at import time, before load_dotenv() #483

Open
smaramwbc/statewave-multi-agent-shared-context
#2

Description

@jy7lsna

Affected Component

statewave-multi-agent-shared-context — main.py

Bug Description

LLM_MODEL set in .env is ignored. The model is read at import time, before .env is loaded:

# main.py:34  (module level, runs on import)
_LLM_MODEL = os.getenv("LLM_MODEL", "groq/llama-3.3-70b-versatile")

# main.py:91  (inside main(), runs later)
load_dotenv()

LLM_API_KEY is picked up from .env, because it's read inside _build_llm_client() after load_dotenv() has run. So a user who follows .env.example and sets LLM_MODEL=openai/gpt-4o-mini with an OpenAI key gets the Groq default with an OpenAI key, and an authentication error that looks like a bad key. The README troubleshooting section (line 288) even describes that symptom.

timeline_inspector.py gets this right: it calls load_dotenv() first (line 199).

Expected Behavior

LLM_MODEL from .env is honoured.

Suggested fix

Move load_dotenv() to module level, right after the imports in main.py (before line 34). Alternatively, read LLM_MODEL inside main().

Steps to Reproduce

  1. In .env: LLM_MODEL=openai/gpt-4o-mini, LLM_API_KEY=<openai key>.
  2. python main.py --mode naive → LiteLLM calls groq/llama-3.3-70b-versatile and fails auth.
  3. export LLM_MODEL=openai/gpt-4o-mini in the shell instead → works.

Environment

main @ eb66ddc.

Severity

Medium for a first run — the documented way to choose a provider doesn't work.

Activity

  1. stealth-raptor commented on Oct 5, 2026

    @stealth-raptor

    Hi @jy7lsna @Infrasity-Labs I would like to take this up. Please assign it to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions