Skip to content

Conversation

@obie
Copy link
Contributor

@obie obie commented Jun 4, 2025

Summary

  • Deprecates the loop parameter in ChatCompletion to avoid conflicts with Ruby's Kernel.loop
  • Introduces automatic continuation after tool calls, eliminating the need for the loop parameter entirely
  • Adds max_tool_calls parameter to prevent infinite tool invocation loops

Details

This PR addresses issue #11 by implementing a better solution than simply renaming the attribute. Instead of requiring users to specify loop: true, the system now automatically continues conversations after tool calls until the AI provides a text response.

Key Changes:

  1. Automatic Continuation: Chat completions now automatically continue after tool calls, making the API more intuitive.

  2. Deprecation Warning: The loop parameter still works but shows a deprecation warning to ease migration.

  3. Tool Call Limiting: Added max_tool_calls parameter (default: 25) to prevent infinite loops.

  4. Simplified API: Tool functions now just return their results - no need to manually handle continuation.

Breaking Changes:

  • loop parameter is deprecated (functional with warning)
  • Tool-based completions return strings instead of arrays
  • stop_looping\! renamed to stop_tool_calls_and_respond\!

Migration Guide:

# Before
response = ai.chat_completion(loop: true)

# After (automatic)
response = ai.chat_completion

# To limit tool calls
response = ai.chat_completion(max_tool_calls: 5)

Test plan

  • All existing tests pass
  • Updated test expectations for automatic continuation
  • Added test for max_tool_calls parameter
  • Verified deprecation warning appears when using loop parameter
  • Confirmed tool functions work without manual continuation

🤖 Generated with Claude Code

obie and others added 2 commits June 4, 2025 16:03
This commit addresses issue #11 by deprecating the `loop` parameter that
was conflicting with Ruby's `Kernel.loop` method. The system now
automatically continues conversations after tool calls until the AI
provides a text response.

Key changes:
- Chat completions automatically continue after tool execution
- Added `max_tool_calls` parameter to prevent infinite loops (default: 25)
- Deprecated `loop` parameter with warning message
- Tool functions now just return their results
- Renamed `stop_looping\!` to `stop_tool_calls_and_respond\!`

Breaking changes:
- `loop` parameter is deprecated (shows warning but still works)
- Tool-based completions return strings instead of arrays
- Functions no longer need to manually continue conversations

This solution eliminates the need for the loop parameter entirely while
providing better automatic behavior that users expect.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@obie obie merged commit a7ad66f into main Jun 4, 2025
1 check 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