Skip to content

Tinker Integration#245

Merged
ultmaster merged 101 commits into
mainfrom
feature/tinker-example
Oct 30, 2025
Merged

Tinker Integration#245
ultmaster merged 101 commits into
mainfrom
feature/tinker-example

Conversation

@ultmaster
Copy link
Copy Markdown
Contributor

This pull request adds a new example integration for using Tinker as a backend training service with Agent-lightning. It introduces a comprehensive bridge package (agl_tinker) that adapts Agent-lightning rollouts and datasets to Tinker’s reinforcement learning workflow, allowing seamless fine-tuning and evaluation workflows. The changes include documentation, environment setup, and core adapter modules that enable interoperability between the two frameworks.

New Example Integration and Documentation:

  • Added a new tinker example to the catalog, with a clear note on its unmaintained status and compatibility with Agent-lightning v0.2.1.
  • Provided a detailed README.md in examples/tinker/ explaining the integration, setup instructions, workflow differences, troubleshooting, and included files.
  • Added an .env.example template for environment variables required to run the Tinker integration, including keys for Tinker, OpenAI, WANDB, and CrewAI telemetry settings.

Core Bridge Package (agl_tinker/) Implementation:

  • Introduced agl_tinker/algo.py, implementing an Algorithm wrapper that plugs Tinker’s training loop into Agent-lightning’s resource management and dataset system.
  • Added agl_tinker/env.py, which provides adapters for Tinker’s RL environment and dataset builders, allowing Agent-lightning tasks to be used in Tinker workflows without modifying rollout logic.
  • Included license headers in new package files for compliance.

Copilot AI review requested due to automatic review settings October 30, 2025 04:24
Comment thread examples/tinker/hello.py
An available port number.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))

Check warning

Code scanning / CodeQL

Binding a socket to all network interfaces Medium

'' binds a socket to all interfaces.

Copilot Autofix

AI 7 months ago

To fix the issue, the code should avoid binding the socket to all interfaces ("" or "0.0.0.0"). In the context of port discovery, it is safer and functionally equivalent to bind the socket to the loopback address (127.0.0.1), which restricts the socket to local traffic only and avoids any potential security risk. In file examples/tinker/hello.py, replace s.bind(("", 0)) with s.bind(("127.0.0.1", 0)) in the _find_available_port() function. No other changes, methods, or imports are needed.

Suggested changeset 1
examples/tinker/hello.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/tinker/hello.py b/examples/tinker/hello.py
--- a/examples/tinker/hello.py
+++ b/examples/tinker/hello.py
@@ -58,7 +58,7 @@
         An available port number.
     """
     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
-        s.bind(("", 0))
+        s.bind(("127.0.0.1", 0))
         return s.getsockname()[1]
 
 
EOF
@@ -58,7 +58,7 @@
An available port number.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))
s.bind(("127.0.0.1", 0))
return s.getsockname()[1]


Copilot is powered by AI and may make mistakes. Always verify output.
An available port number.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))

Check warning

Code scanning / CodeQL

Binding a socket to all network interfaces Medium

'' binds a socket to all interfaces.

Copilot Autofix

AI 7 months ago

To fix this problem, change the s.bind(("", 0)) line in _find_available_port() so it binds to the loopback interface only, by specifying '127.0.0.1' instead of the empty string. This restricts the socket to accept connections only from the local machine during the port discovery. No additional imports or significant code changes are needed; just one argument needs updating in the identified function in examples/tinker/q20_train.py at line 61.

Suggested changeset 1
examples/tinker/q20_train.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/examples/tinker/q20_train.py b/examples/tinker/q20_train.py
--- a/examples/tinker/q20_train.py
+++ b/examples/tinker/q20_train.py
@@ -58,7 +58,7 @@
         An available port number.
     """
     with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
-        s.bind(("", 0))
+        s.bind(("127.0.0.1", 0))
         return s.getsockname()[1]
 
 
EOF
@@ -58,7 +58,7 @@
An available port number.
"""
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind(("", 0))
s.bind(("127.0.0.1", 0))
return s.getsockname()[1]


Copilot is powered by AI and may make mistakes. Always verify output.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a comprehensive Tinker integration example to Agent-lightning, enabling reinforcement learning fine-tuning using Tinker as the backend training service. The integration bridges Agent-lightning's rollout architecture with Tinker's training infrastructure.

Key changes:

  • Added new Tinker integration example with bridge code (agl_tinker/) to connect Agent-lightning with Tinker's RL training
  • Implemented two example agents: a minimal "Hello" agent and a complex 20 Questions game using CrewAI
  • Added wandb dependency to the tinker extra in project configuration

Reviewed Changes

Copilot reviewed 17 out of 18 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
uv.lock Added wandb dependency for tinker extra
pyproject.toml Added wandb to tinker dependencies
examples/tinker/README.md Comprehensive documentation for Tinker integration
examples/tinker/hello.py Minimal training example demonstrating identity repetition
examples/tinker/q20_*.py 20 Questions game implementation with training and evaluation scripts
examples/tinker/agl_tinker/*.py Bridge package connecting Agent-lightning with Tinker
examples/tinker/.env.example Environment variable template
examples/README.md Updated examples catalog with Tinker entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/tinker/hello.py Outdated
rew = 1.0
elif ("not " + task) in content_lower:
rew = -1.0
elif ("you're" + task) in content_lower or ("you are" + task) in content_lower:
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing space in string concatenation for 'you're' check. Should be (\"you're \" + task) and (\"you are \" + task) to properly match phrases like "you're 42" instead of "you're42".

Suggested change
elif ("you're" + task) in content_lower or ("you are" + task) in content_lower:
elif ("you're " + task) in content_lower or ("you are " + task) in content_lower:

Copilot uses AI. Check for mistakes.
Comment thread examples/tinker/agl_tinker/env.py Outdated
len(val_indices),
)
train_dataset = [train_dataset[i] for i in train_indices]
val_dataset = [train_dataset[i] for i in val_indices]
Copy link

Copilot AI Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation dataset is being created from the wrong source. It should use the original train_dataset variable from line 233, but after line 251, train_dataset has been reassigned to a list. This line should reference the original dataset before reassignment. Store the original dataset in a separate variable to avoid this issue.

Copilot uses AI. Check for mistakes.
@ultmaster ultmaster merged commit 496e793 into main Oct 30, 2025
12 checks passed
totoluo pushed a commit to totoluo/agent-lightning that referenced this pull request Nov 14, 2025
@ultmaster ultmaster deleted the feature/tinker-example branch December 11, 2025 16: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.

3 participants