测试基础AI智能体实战

木偶AI正在绞尽脑汁想思路ING···
木偶のAI摘要
DeepSeek-Chat

一、MD文档生成测试用例实战

Dify 中 迭代与循环的区别:

特性 迭代 (Iteration) 循环 (Loop)
核心定义 针对列表/数组数据中的每一项逐个执行相同的操作。 根据条件判断重复执行一段逻辑,直到条件不再满足。
处理对象 集合数据(如搜索结果列表、文档切片)。 逻辑状态(如“重试直到成功”、“递归搜索”)。
执行次数 预先确定的(等于列表中元素的数量)。 动态确定的(取决于条件何时满足,可能陷入死循环)。
典型场景 批量翻译一组句子、对搜索出的 5 条新闻分别做摘要。 引导 Agent 反思改进输出、不断重试 API 调用直到返回正确结果。
数据关系 每一项处理通常是独立的(也可配置为累积)。 后一次循环往往依赖前一次的结果或状态。

代码执行输出变量名称需要与执行代码中return 出来的值一致

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pathlib import Path


def main(arg1: str) -> dict:
"""实现md文档内容的提取功能
1.arg1是一个md文件的字符串
2.将md文件的第三级以下的内容(包含第三级)提取出来,并放入到一个result数组中。
3.以列表的形式返回提取到的内容
"""
if not isinstance(arg1, str):
raise TypeError("arg1 must be a markdown string")

lines = arg1.splitlines()
result = []
current_section = []
capturing = False

for original_line in lines:
stripped_line = original_line.lstrip()

if stripped_line.startswith("#"):
hash_count = len(stripped_line) - len(stripped_line.lstrip("#"))
# Ensure the hashes represent a heading (need a space/tab after them)
next_char = stripped_line[hash_count:hash_count + 1]

if next_char in {" ", "\t"}:
if hash_count == 3:
if current_section:
result.append("\n".join(current_section).strip())
current_section = []
capturing = True
current_section.append(stripped_line.rstrip())
elif hash_count > 3:
if capturing:
current_section.append(stripped_line.rstrip())
else:
if capturing and current_section:
result.append("\n".join(current_section).strip())
capturing = False
current_section = []
continue

if capturing:
current_section.append(original_line.rstrip())

if capturing and current_section:
result.append("\n".join(current_section).strip())

result = [section for section in result if section]

return {'result':result}

二、Swagger文档生成测试用例实战