Skip to content

feat: add depth>1 recursive subcalls with limits and cost tracking#84

Merged
alexzhang13 merged 13 commits intoalexzhang13:mainfrom
rawwerks:depth_PR_prep
Feb 18, 2026
Merged

feat: add depth>1 recursive subcalls with limits and cost tracking#84
alexzhang13 merged 13 commits intoalexzhang13:mainfrom
rawwerks:depth_PR_prep

Conversation

@rawwerks
Copy link
Contributor

@rawwerks rawwerks commented Feb 2, 2026

Summary

This PR adds full depth>1 recursive subcall support for RLM, enabling nested RLM calls when code inside the REPL invokes llm_query().

Features

  • Recursive subcalls: _subcall() spawns child RLM instances with incremented depth
  • Uniform return type: _subcall() returns RLMChatCompletion (aligns with LM completion struct)
  • Budget/cost tracking: max_budget parameter with BudgetExceededError, OpenRouter cost extraction
  • Execution limits: max_timeout, max_tokens, max_errors with corresponding exceptions
  • Event callbacks: on_subcall_start, on_subcall_complete, on_iteration_start, on_iteration_complete

Files Changed

  • rlm/core/rlm.py - Core subcall logic, limits, callbacks
  • rlm/core/types.py - UsageSummary cost aggregation
  • rlm/environments/local_repl.py - subcall_fn integration
  • rlm/clients/openai.py - OpenRouter cost extraction
  • rlm/logger/verbose.py - Limit exceeded display
  • docs/getting-started.md, docs/api/rlm.md - Documentation

Tests

  • 13 unit tests for subcall behavior
  • 1 e2e test with google/gemini-3-flash-preview via OpenRouter
  • All 148+ existing tests pass

Breaking Changes

None - all existing APIs remain compatible.


🤖 Generated with Claude Code

rawwerks and others added 5 commits February 2, 2026 13:54
- Add max_budget parameter to RLM (in USD)
- Add BudgetExceededError exception
- Track cumulative cost across iterations
- Propagate remaining budget to child RLMs
- Add print_budget_exceeded to VerbosePrinter
- Export BudgetExceededError from rlm module

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@alexzhang13 alexzhang13 merged commit 76abb9c into alexzhang13:main Feb 18, 2026
3 checks passed
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