Skip to content

perf(llm): pass pre-loaded cfg dict to LLM clients, skip redundant file reads#153

Draft
CGFixIT wants to merge 2 commits into
mainfrom
claude/fix-llm-client-cfg-passthrough
Draft

perf(llm): pass pre-loaded cfg dict to LLM clients, skip redundant file reads#153
CGFixIT wants to merge 2 commits into
mainfrom
claude/fix-llm-client-cfg-passthrough

Conversation

@CGFixIT

@CGFixIT CGFixIT commented Jun 21, 2026

Copy link
Copy Markdown
Owner

Problem

gate.py loads and parses config.yaml once at startup into cfg. It then instantiates LocalLLMClient() and GrokClient(), each of which independently opens and parses config.yaml from disk again — 2 extra file reads that produce the same data already in memory.

Fix

Add an optional cfg: Optional[dict] parameter to both client constructors:

# Before
class LocalLLMClient:
    def __init__(self, config_path: str = "config.yaml"):
        with open(config_path, encoding="utf-8") as f:
            cfg = yaml.safe_load(f)

# After
class LocalLLMClient:
    def __init__(self, config_path: str = "config.yaml", cfg: Optional[dict] = None):
        if cfg is None:
            with open(config_path, encoding="utf-8") as f:
                cfg = yaml.safe_load(f)

gate.py passes the already-loaded dict at both call sites:

local_llm = LocalLLMClient(cfg=cfg)
grok = GrokClient(cfg=cfg)

Backward Compatibility

Fully backward compatible — config_path fallback is unchanged. Any existing code (tests, standalone scripts) that calls LocalLLMClient() or GrokClient() without a cfg argument continues to work exactly as before.

Files Changed

  • llm/client.py — optional cfg param on both constructors
  • gate.py — pass cfg=cfg at the two instantiation sites

Generated by Claude Code

claude added 2 commits June 21, 2026 02:53
gate.py already holds a fully-parsed cfg dict when it instantiates
LocalLLMClient and GrokClient. Both constructors previously opened and
parsed config.yaml from disk independently, adding 2 extra file reads
on every server start.

Add an optional `cfg` parameter to both constructors. When a dict is
passed the file read is skipped; when omitted (standalone use / tests)
the existing config_path fallback is used unchanged.

gate.py updated to pass cfg=cfg at the two call sites.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01RgtYPGfWiJf7Tz2AYwdBEE
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