Shortcuts

XMLBlockParser

class torchrl.envs.llm.transforms.XMLBlockParser[source]

Parser for XML-style tool blocks in LLM responses.

Parses tool calls in the format:

<tool name=”tool_name” tag=”optional_tag”>{“arg”: “value”}</tool>

Examples

>>> parser = XMLBlockParser()
>>> response = '<tool name="search" tag="A">{"query": "torchrl"}</tool>\\nSome text.'
>>> result = parser(response)
>>> print(result["text"])
Some text.
>>> print(result["calls"][0].tool)
search
>>> print(result["calls"][0].args)
{"query": "torchrl"}

Docs

Access comprehensive developer documentation for PyTorch

View Docs

Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

Resources

Find development resources and get your questions answered

View Resources