Skip to content

Conversation

@lakshyaag
Copy link
Contributor

@lakshyaag lakshyaag commented Jan 5, 2026

Summary

This PR adds support for passing additional kwargs through the entire RLM stack to underlying LM client APIs, enabling fine-grained control over completion parameters like max_tokens, temperature, reasoning_effort, and provider-specific options.

Key Changes

1. Enhanced Client Interface (rlm/clients/)

  • Updated BaseLM abstract methods to accept model and **kwargs parameters
  • Modified OpenAIClient.completion() and OpenAIClient.acompletion() to accept and forward kwargs to OpenAI API
  • Improved _track_cost() to safely handle missing usage data with getattr() fallbacks

2. Core Communication Updates (rlm/core/)

  • Extended LMRequest dataclass with optional kwargs field for passing parameters through socket/HTTP protocol
  • Updated send_lm_request_batched() to accept and forward kwargs
  • Modified LMHandler and LMRequestHandler to unpack and pass kwargs to client completion calls
  • Updated RLM.completion() to accept kwargs and propagate them through:
    • _run_iteration() for main completions
    • _default_answer() for fallback completions
    • _fallback_answer() for max-depth fallback

3. Environment Integration (rlm/environments/)

  • LocalREPL: Updated _llm_query() and _llm_query_batched() to accept and forward kwargs via socket
  • ModalREPL: Updated broker exec script's llm_query() and llm_query_batched() to include kwargs in HTTP payloads
  • DockerREPL: Updated proxy handler and exec script to pass kwargs through HTTP requests

4. Testing & Examples

  • Added tests/clients/_openai.py with basic tests demonstrating:
    • Completion with kwargs (e.g., reasoning_effort="high")
    • Completion without kwargs (backward compatibility)
  • Updated MockLM implementations in tests and examples to match new BaseLM signature

Backward Compatibility

All changes are fully backward compatible:

  • **kwargs parameters default to empty, so existing code works unchanged
  • model parameter formalizes existing pattern used by all client implementations
  • No breaking changes to public APIs
  • All existing tests should continue to pass

Example Usage

# Root-level RLM call with kwargs
rlm = RLM(backend="openai", model="gpt-4")
result = rlm.completion(
    prompt="Solve this problem", 
    max_tokens=1000, 
    temperature=0.7
)

Open questions

  1. Should the sub-LLM be extended to inherit kwargs from the root LM? Another direction here is to let the root LM decide additional kwargs.

@lakshyaag lakshyaag marked this pull request as ready for review January 5, 2026 02:26
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.

1 participant