前两天厦门的晚霞,好似云朵也会脸红~
Algorithm
本周选择的算法题是:Number of Subsequences That Satisfy the Given Sum Condition。
class Solution(object):
def numSubseq(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
nums.sort()
left, right = 0, len(nums) - 1
res = 0
while left <= right:
if nums[left] + nums[right] <= target:
res += 2 ** (right - left)
left += 1
else:
right -= 1
return res % (10 ** 9 + 7)
Review
12-Factor Agents - Principles for building reliable LLM applications
最近很火的 llm 应用构建原则,几天不见已经涨到 8.2k Star 了。
这是作者的另一篇文章:OpenAI’s Realtime API is a step towards outer-loop Agents。
作者认为 Agent 系统大致可以分为三代:
- AI 操作由确定性的软件发起
- AI 操作由人类互动发起
- AI 主动发起,并在需要时召唤人类
第 3 代也被称为控制反转:
当前的 Agent 系统里,已经有了 人 -> Agent 的接口,缺少的是 Agent -> 人的接口,这种感觉会更像真正的人类合作者。
期待有一个能看到真正的 Agent-Self 系统。
Tip
emojimix 一个好玩的网站,能将两个 emoji 合并起来,很有创意:
Share
Doubao 1.6 的调用工具出现幻觉的问题,表现为未按预期输出工具调用指令。
我使用的 Qwen-Agent 的 FnCallAgent,它的 tool prompt 如下:
FN_CALL_TEMPLATE = """# Tools
You may call one or more functions to assist with the user query.
You are provided with function signatures within <tools></tools> XML tags:
<tools>
{tool_descs}
</tools>
For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
<tool_call>
name
</tool_call>"""
要求 LLM 将工具调用以
以 LangChain 为例:
<tool>
{
"name": "工具名称", // 必须:与LangChain中注册的Tool名称完全一致
"parameters": { // 必须:工具所需参数,键值对格式
"参数1": "值1",
"参数2": "值2"
}
}
</tool>
连续多个工具调用:
<tool>
{
"name": "get_weather",
"parameters": {
"city": "北京",
"date": "2025-07-06"
}
}
</tool>
<tool>
{
"name": "get_flight_status",
"parameters": {
"flight_number": "CA1234",
"date": "2025-07-06"
}
}
</tool>
但用上述 tool prompt 调用 Doubao 1.6 时偶然会出现这样的返回格式:
{
"role": "assistant",
"content": "<|FunctionCallBegin|>[{\"name\":\"通用\",\"parameters\":{\"user_prompt\":\"一支高端牙膏产品,直立放置在白色大理石台面上,牙膏管为银色与蓝色渐变设计,管口挤出少量白色牙膏膏体,呈现细腻泡沫质感,背景为简约白色,光线明亮柔和,突出产品细节,高清商品摄影风格,阴影自然,正面视角,构图居中,适合电商平台展示,高清画质,细节丰富\",\"width\":\"512\",\"height\":\"512\"}}]<|FunctionCallEnd|>",
}
除了标签本身不同之外,标签的语义也不同,Doubao 1.6 的标签是同时返回多个工具调用。
这种情况除了优化 prompt 减少模型幻觉外,如果能放弃通用性与便利性,直接使用 Doubao 1.6 原本的格式似乎更能提高调用的成功率。