Skip to content

interrupt: return the agent from LLM.interrupt - #293

Merged
altruby merged 1 commit into
r-uby-dev:mainfrom
muhammadsamad99:interrupt-returns-agent
Oct 18, 2026
Merged

altruby merged 1 commit into
r-uby-dev:mainfrom
muhammadsamad99:interrupt-returns-agent

Conversation

@muhammadsamad99

Copy link
Copy Markdown
Contributor

Fixes #292

LLM.interrupt now returns the agent it found and interrupted instead of true, and still returns false when nothing was registered. On a hit it returns from inside attempts.times; on a miss it returns false after the loop, so it can't fall through to the Integer that times returns.

  • lib/llm.rb: return the agent, and @return [LLM::Agent, false].
  • spec/llm/interrupt_spec.rb: be(true) is now be(agent), plus an example that the returned agent had interrupt! called on it. The false cases are unchanged.
  • docs/deepdive/advanced/cancellation.md: a hit answers with the agent it interrupted.
  • README.md: the interrupt section said the method "returns true when it sent an interrupt", so it now says it returns the agent. This one wasn't in the issue's steps.
  • CHANGELOG.md: a Migration row and an Agent entry under "What's next", since the issue asks for one. It says it's a soft break: == true stops matching, and a caller that stores or serializes the result (a JSON response, say) now gets the agent. I see contributor PRs here usually leave the changelog to you, and a Breaking heading implies the next major, so feel free to drop or reword it.

I kept the local named record, as in the issue's sketch, to keep the diff small. Happy to rename it to found if you prefer.

Verified locally on Ruby 4.0.6 (Docker), with the Linux CI job's env (JSON_PARSER=JSON, DASHSCOPE_API_HOST set):

  • bundle exec rspec spec/llm/interrupt_spec.rb: the two changed examples fail on main (they get true) and pass with the change; 10 examples, 0 failures.
  • bundle exec rake spec: 1962 examples, 0 failures, 37 pending (the PostgreSQL ORM specs, since LLMRB_POSTGRESQL_URL wasn't set). On main: 1961 examples, 0 failures, 37 pending.
  • bundle exec rubocop lib/llm.rb spec/llm/interrupt_spec.rb: no new offenses. The two Style/ItBlockParameter offenses in lib/llm.rb are on main too.

@altruby
altruby merged commit 85205d2 into r-uby-dev:main Oct 18, 2026
5 checks passed
@altruby

altruby commented Oct 18, 2026

Copy link
Copy Markdown
Member

Thanks for the patch!

@altruby altruby added this to the v18.0.0 milestone Oct 18, 2026
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.

interrupt: return the agent instead of true from LLM.interrupt

2 participants