multi_agents .env tracing settings are read before load_dotenv()
Summary
multi_agents/main.py checks MONOCLE_TRACING, MONOCLE_EXPORTERS, OKAHU_API_KEY, and LANGCHAIN_API_KEY before calling load_dotenv().
As a result, tracing settings placed in the project's .env file are invisible during those checks unless they are also exported in the parent shell.
Current order
from dotenv import load_dotenv
...
if os.environ.get("MONOCLE_TRACING", "").strip().lower() in (...):
...
...
if os.environ.get("LANGCHAIN_API_KEY"):
os.environ["LANGCHAIN_TRACING_V2"] = "true"
load_dotenv()The README and .env.example both present these as environment settings, so users can reasonably place them in .env. However, load_dotenv() runs only after both tracing gates have already executed.
Expected behavior
Load .env before any tracing-related environment checks, while still keeping the Monocle setup before importing the multi-agent framework modules that need instrumentation.
A minimal fix is to call load_dotenv() immediately after imports and remove the later call.
Regression coverage
A focused test can execute multi_agents/main.py with a temporary .env containing MONOCLE_TRACING=true, stub monocle_apptrace.setup_monocle_telemetry, and verify that the setup hook is invoked from the .env value without exporting it in the parent process.
The same ordering also restores .env-provided LANGCHAIN_API_KEY visibility before LANGCHAIN_TRACING_V2 is derived.
I searched the issue/PR tracker for this specific load_dotenv ordering problem and did not find an existing report.
AI-assisted review disclosure: an AI coding assistant was used to inspect import/config ordering and help prepare this report.
Source: assafelovic/gpt-researcher