SGLang model provider for Strands Agents SDK with Token-in/Token-out support for agentic RL training.
Project description
Strands-SGLang
Agentic RL, done correctly.
- Strands Agents SDK: a harness builder whose event-based hooks make the agent loop fully customizable.
- SGLang: a high-performance serving framework for fast, high-concurrency rollouts that exposes per-token metadata.
Strands-SGLang bridges the two so multi-turn rollouts stay on-policy — token-in, token-out, no silent retokenization drift.
Features
- Token-In/Token-Out rollouts: model-generated tokens carried through as-is
- Only new messages are tokenized each turn with incremental chat templating
- Strict tool-call parsing: parsed exactly as generated, no heuristic repair
- Harness customization: pass tools and hooks into
Agentto customize your harness - Native SGLang
/generateendpoint: high-throughput, non-streaming rollouts
For RL environment integration, please refer to
strands-env
Installation
pip install strands-sglang strands-agents-tools
Or install from source with development dependencies:
git clone https://github.com/horizon-rl/strands-sglang.git
cd strands-sglang
pip install -e ".[dev]"
Quick Start
1. Start SGLang Server
python -m sglang.launch_server --model-path Qwen/Qwen3.5-4B
2. Run an Agent
import asyncio
from transformers import AutoTokenizer
from strands import Agent
from strands_tools import calculator
from strands_sglang import SGLangClient, SGLangModel
from strands_sglang.tool_parsers import get_tool_parser
async def main():
model = SGLangModel(
client=SGLangClient(base_url="http://localhost:30000"),
tokenizer=AutoTokenizer.from_pretrained("Qwen/Qwen3.5-4B"),
tool_parser=get_tool_parser("qwen_xml"),
)
agent = Agent(model=model, tools=[calculator])
await agent.invoke_async("What is 25 * 17?")
# SGLangModel captures the full token trajectory for on-policy RL training
tm = model.token_manager
print(tm.token_ids, tm.loss_mask, tm.logprobs)
asyncio.run(main())
RL Training
In principle, Strands-SGLang can be seen as a drop-in agentic rollout service and can be integrated with any RL training framework. A concrete example of training a math coding agent (ReTool) is available at slime/examples/strands_sglang.
Some key highlights of adapting Strands-SGLang to any RL framework:
- Pass tokens and token metadata from
TokenManagerfor on-policy rollouts - Hook your harness with the built-in
ToolLimiter(or your own) for controlled rollouts - Use a shared
SGLangClientand HF tokenizer; don't create one instance per rollout - Classify the rollout's termination reason properly — it shapes reward and sampling
Testing
# Unit tests
pytest tests/unit/ -v
# Integration tests (requires SGLang server)
pytest tests/integration/ -v --sglang-base-url=http://localhost:30000
Contributing
Contributions welcome! Install pre-commit hooks for code style and commit message validation:
pip install -e ".[dev]"
pre-commit install -t pre-commit -t commit-msg
This project uses Conventional Commits. Commit messages must follow the format:
<type>(<scope>): <description>
# Examples:
feat(client): add retry backoff configuration
fix(sglang): handle empty response from server
docs: update usage examples
Allowed types: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
License
Apache License 2.0 - see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file strands_sglang-0.3.8.tar.gz.
File metadata
- Download URL: strands_sglang-0.3.8.tar.gz
- Upload date:
- Size: 69.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc4fb24e6bca925834abc023bbbeccf8b0614756a36d8804e5300c2874dfd457
|
|
| MD5 |
da206b03455717a0379f7c7ebdee7ba0
|
|
| BLAKE2b-256 |
2413d52cfd7dabab0409470c95e6b1a8230f45d300bb3a228e14fa28aa79cc21
|
Provenance
The following attestation bundles were made for strands_sglang-0.3.8.tar.gz:
Publisher:
publish.yml on strands-rl/strands-sglang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strands_sglang-0.3.8.tar.gz -
Subject digest:
bc4fb24e6bca925834abc023bbbeccf8b0614756a36d8804e5300c2874dfd457 - Sigstore transparency entry: 1674071049
- Sigstore integration time:
-
Permalink:
strands-rl/strands-sglang@1d3b8fe29f0a34b07af52529da6181bbbf882f17 -
Branch / Tag:
refs/tags/v0.3.8 - Owner: https://github.com/strands-rl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1d3b8fe29f0a34b07af52529da6181bbbf882f17 -
Trigger Event:
release
-
Statement type:
File details
Details for the file strands_sglang-0.3.8-py3-none-any.whl.
File metadata
- Download URL: strands_sglang-0.3.8-py3-none-any.whl
- Upload date:
- Size: 35.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52a4584ecad10b2e8b101cda6c22f6cd9b513dd9956ef0f7ac509d2059bb0a35
|
|
| MD5 |
68b08be766900c2eb1bc2c3a5e04386a
|
|
| BLAKE2b-256 |
b8b6f310e39eff920d76583984686f1ab87facf9bff198bc2e7b1ec0454d0b57
|
Provenance
The following attestation bundles were made for strands_sglang-0.3.8-py3-none-any.whl:
Publisher:
publish.yml on strands-rl/strands-sglang
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
strands_sglang-0.3.8-py3-none-any.whl -
Subject digest:
52a4584ecad10b2e8b101cda6c22f6cd9b513dd9956ef0f7ac509d2059bb0a35 - Sigstore transparency entry: 1674071103
- Sigstore integration time:
-
Permalink:
strands-rl/strands-sglang@1d3b8fe29f0a34b07af52529da6181bbbf882f17 -
Branch / Tag:
refs/tags/v0.3.8 - Owner: https://github.com/strands-rl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@1d3b8fe29f0a34b07af52529da6181bbbf882f17 -
Trigger Event:
release
-
Statement type: