verl icon indicating copy to clipboard operation
verl copied to clipboard

ToolAgentLoop get `tool_response_ids`

Open Squidwarder opened this issue 1 year ago • 3 comments

Hello, I have a question regarding the logic to extract tool_response_ids in class ToolAgentLoop of file experimental/agent_loop/tool_agent_loop.py:

https://github.com/volcengine/verl/blob/2bbd09245cc383510376284bd51840b451b3b267/verl/experimental/agent_loop/tool_agent_loop.py#L60-L62

https://github.com/volcengine/verl/blob/2bbd09245cc383510376284bd51840b451b3b267/verl/experimental/agent_loop/tool_agent_loop.py#L196

If I understand the logic of the above code correctly, it's trying to obtain the length of the system prompt that is a part of tokenizer, and remove that from each iteration of tool call responses in order to obtain only tool_response_ids.

However, running tokenizer.apply_chat_template([{}], add_generation_prompt=False, tokenize=True) resulted in an error in my environment due to the lack of role and content. Additionally, apply_chat_template() doesn't seem to include system prompt tokens in my local experiments, which makes me question whether or not it's really necessary to remove len(system_prompt) from tool_response_ids.

It would be great if anyone can explain the reasoning behind this logic. Huge thanks all around.

Squidwarder avatar Aug 15 '25 12:08 Squidwarder

If I understand the logic of the above code correctly, it's trying to obtain the length of the system prompt that is a part of tokenizer, and remove that from each iteration of tool call responses in order to obtain only tool_response_ids.

Yes, that's right.

>>> tokenizer.apply_chat_template([{"role": "tool", "content": "I am a tool"}], add_generation_prompt=False, tokenize=False)
'<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n<|im_start|>user\n<tool_response>\nI am a tool\n</tool_response><|im_end|>\n<|im_start|>assistant\n'

We want to remove the system prompt and only keep

I am a tool\n</tool_response><|im_end|>\n<|im_start|>assistant\n

However, running tokenizer.apply_chat_template([{}], add_generation_prompt=False, tokenize=True) resulted in an error in my environment due to the lack of role and content.

Which model do you use?

wuxibin89 avatar Aug 18 '25 03:08 wuxibin89

Thank you for responding. I'm using Qwen3-Coder-30B-A3, and in my training I didn't have to remove the system prompt to obtain only the tool_response_ids.

For example, below is a screenshot of my output without removing the system prompt length. It looks perfectly fine to me.

Image

I assume it might be something to do with the tokenizer configuration?

Squidwarder avatar Aug 18 '25 03:08 Squidwarder

Yes, it's tokenizer related. For quick fix, you can set self.system_prompt = [], we need to find a better way to remove the system_prompt.

wuxibin89 avatar Aug 18 '25 04:08 wuxibin89