agent 的一些思考

1、 多轮的tool use 更难一些,主要是数据难以获取和建模方式,最近的工作还是集中在涉及 multi turn tool-use 的 prompt template
2、 agent 的 tool use 的prompt 该如何写,下面是一个示例, 一个包哈了chat template 的 tool prompt,具体包括,chat template, toool schema, tool call, tool response dengdeng , system prompt 一般写tool schema信息, assistant 是模型的响应, thinking 过程包含在 中, tool 调用的参数包含在</tool_call> 中, tool 执行的response 放在user 中,包括在 </tool_response> 标签中:

<|im_start|>system
In this environment you have access to a set of tools you can use to assist with the user query. You may perform multiple rounds of function calls. In each round, you can call one or more functions.  Here are available functions in JSONSchema format:  
\```json 
tool_schema 
\```  

In your response, you need to first think about the reasoning process in the mind and then conduct function calling to get the information or perform the actions if needed. The reasoning process and function calling are enclosed within <think> </think> and <tool_call> </tool_call> tags. The results of the function calls will be given back to you after execution, and you can continue to call functions until you get the final answer for the user's question. Finally, if you have got the answer, enclose it within \boxed{} with latex format and do not continue to call functions, i.e., <think> Based on the response from the function call, I get the weather information. </think> The weather in Beijing on 2025-04-01 is \[ \boxed{20C} \].  

For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags: 
<tool_call> 
{"name": <function-name>, "arguments": <args-json-object>}
</tool_call><|im_end|>
<|im_start|>user
User 1 wants to return all books by Jane Doe they have checked out. Each book is 5 days overdue, what is the total late fee?
<|im_end|>
<|im_start|>assistant
<think> First, I need to find out which books by Jane Doe the user has checked out. Then, I will calculate the late fee for each book based on the number of days it is overdue. </think>
<tool_call> 
{"name": "get_user_checked_out_books", "arguments": {"user_id": 1}}
</tool_call>
<tool_call>
{"name": "search_books_by_author", "arguments": {"author": "Jane Doe"}} 
</tool_call>
<|im_end|>
<|im_start|>user
<tool_response> {"name": "get_user_checked_out_books", "arguments": {"user_id": 1}}
['Python Basics', 'Advanced Python', 'Data Structures'] 
</tool_response>
<tool_response> {"name": "search_books_by_author", "arguments": {"author": "Jane Doe"}}
[{'title': 'Python Basics', 'author': 'Jane Doe', 'copies_available': 3}, {'title': 'Advanced Python', 'author': 'Jane Doe', 'copies_available': 0}] 
</tool_response>
<|im_end|>
<|im_start|>assistant
<think> ... ...

3、Formate Checking :训练过程中加入了格式检查,以验证模型的输出是否符合预期的结构规范——具体来说,推理过程是否包含在 ... 标签中,工具调用是否正确包含在 ...</tool_call> 标签中。这种结构约束鼓励模型在工具调用之前进行明确的推理,而不是快速得出最终答案。通过强制遵循格式,旨在培养模型的内在推理能力,这可能有助于提升泛化能力——尤其是在处理分布外的输入时。

4、 system prompt 系统提示,以及user prompt 区别和作用

  • 控制主体:开发者,系统设计者 终端用户
  • 作用目标:定义AI 的基准行为与身份 提供当前任务的上下文和指令
  • 核心目的:安全防护、角色设定、输出约束 任务解析,即时响应
    system prompt:
    1、角色定义 2、安全与合规 3、输出格式规范 4、思维链引导
    user prompt:
    1、上下文的注入 2、结构化的指令
posted @ 2025-06-10 16:04  wsl-hitsz  阅读(25)  评论(0)    收藏  举报