Skip to main content

Strands-SGLang

Awesome Strands Agents

CI PyPI License Ask DeepWiki Blog Strands-Agents

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 Agent to customize your harness
  • Native SGLang /generate endpoint: 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/strands-rl/strands-sglang.git
cd strands-sglang
uv sync

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, tool
from strands_sglang import SGLangClient, SGLangModel
from strands_sglang.tool_parsers import get_tool_parser

@tool
def calculator(expression: str) -> str:
    """Evaluate an arithmetic expression."""
    return str(eval(expression))

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
    rollout = model.rollout
    print(rollout.token_ids, rollout.loss_mask, rollout.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 Rollout for on-policy rollouts
  • Hook your harness with the built-in LoopLimiter (or your own) for controlled rollouts
  • Use a shared SGLangClient and 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:

uv sync
pre-commit install

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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strands_sglang-0.6.1.tar.gz (60.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strands_sglang-0.6.1-py3-none-any.whl (31.2 kB view details)

Uploaded Python 3

File details

Details for the file strands_sglang-0.6.1.tar.gz.

File metadata

  • Download URL: strands_sglang-0.6.1.tar.gz
  • Upload date:
  • Size: 60.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for strands_sglang-0.6.1.tar.gz
Algorithm Hash digest
SHA256 136215ef403344587c8b0591ff8940147feb6f4508d188b9369bbfccfe96bab0
MD5 e8e78a9066298cc93d919aaa8b5c717b
BLAKE2b-256 fdd1e27ed23304f06fa590e8a355edd20849e7d2aa83a38118b2d61081ac63be

See more details on using hashes here.

Provenance

The following attestation bundles were made for strands_sglang-0.6.1.tar.gz:

Publisher: publish.yml on strands-rl/strands-sglang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file strands_sglang-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: strands_sglang-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 31.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for strands_sglang-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85bf5fad57075ac423ed53a326f130b49491988c7c780c7fc36895672a97ebc8
MD5 8d87bf8a57783c66cab85fcb59abfe9d
BLAKE2b-256 9446f3454075fd9ebdd8ad79500c97439f04a946906be967b5dfebd52248662d

See more details on using hashes here.

Provenance

The following attestation bundles were made for strands_sglang-0.6.1-py3-none-any.whl:

Publisher: publish.yml on strands-rl/strands-sglang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.6.1 This release

2 files

0.6.0

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.3.8

2 files

0.3.7

2 files

0.3.6

2 files

0.3.5

2 files

0.3.4

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page