fix: prevent empty stream error after summary reset due to AIMessage-first context When reset_summary is triggered at stage completion, the previous code computed the tail message index by walking backward past ToolMessages. If the resulting cutoff landed on an AIMessage (because _find_safe_cutoff_point backtracks to keep AI/Tool pairs together), the rebuilt context would begin with [SystemMessage, AIMessage, …] after REMOVE_ALL_MESSAGES is applied. Strict LLM APIs (e.g. Anthropic) require the first non-system message to be a HumanMessage; sending an AIMessage-first context returns an empty stream which raises ‘No generations found in stream’. Changes: Reset path: use SummarizationMiddleware._find_safe_cutoff_point for consistent cutoff calculation, then walk backward to the nearest HumanMessage so the rebuilt tail always starts with a HumanMessage. The original safe-cutoff slice is preserved and the anchor HumanMessage is prepended only when it falls outside that slice. Summarization path: replace the manual backward-scan loop with _find_safe_cutoff_point for correctness and consistency. Add abefore_model override that delegates to before_model so the middleware is invoked correctly in async execution paths as well.
fix: prevent empty stream error after summary reset due to AIMessage-first context
When reset_summary is triggered at stage completion, the previous code computed the tail message index by walking backward past ToolMessages. If the resulting cutoff landed on an AIMessage (because _find_safe_cutoff_point backtracks to keep AI/Tool pairs together), the rebuilt context would begin with [SystemMessage, AIMessage, …] after REMOVE_ALL_MESSAGES is applied.
Strict LLM APIs (e.g. Anthropic) require the first non-system message to be a HumanMessage; sending an AIMessage-first context returns an empty stream which raises ‘No generations found in stream’.
Changes:
基于大模型进行自动化 UT 验证 AI 代理
English Introduction | UCAgent 在线文档
UCAgent 是一个基于大语言模型的自动化硬件验证 AI 代理,专注于芯片设计的单元测试(Unit Test)验证工作。通过 AI 技术自动分析硬件设计,生成测试用例,执行验证任务并生成测试报告,从而提高验证效率。
核心特点:
更多详细介绍请参考 UCAgent 在线文档
git clone https://github.com/XS-MLVP/UCAgent.git cd UCAgent
pip3 install -r requirements.txt
请参考 https://qwenlm.github.io/qwen-code-docs/en/ 安装qwen-code-cli,然后按以下示例配置MCP Server。
~/.qwen/settings.json 示例:
~/.qwen/settings.json
{ "mcpServers": { "unitytest": { "httpUrl": "http://localhost:5000/mcp", "timeout": 300000 } } }
由于测试用例多了后运行时间较长,建议 timeout 值设置大一些,例如 300 秒。
timeout
其他Code Agent 请参考对应文档,例如 claude code, opencode, copilot-cli, kilo-cli, iflow 等。
以 example 中的 Adder 为例。
# 默认后端为 langchain,需要配置:OPENAI_API_BASE 等环境变量 # backend can be: langchian, claude, opencode, copilot, kilo, qwen, iflow, etc. make mcp_Adder ARGS="--loop --backend=qwen"
已经支持的后端请参考 ucagent/setting.yaml 中的backend部分。
backend
(1)启动 MCP-Server
make mcp_Adder # workspace 设置为当前目录下的 output/workspace_Adder # 调用了如下命令: # picker export Adder/Adder.v --rw 1 --sname Adder --tdir output/workspace_Adder/ -c -w output/workspace_Adder/Adder/Adder.fst # ucagent output/workspace_Adder/ Adder -s -hm --tui --mcp-server-no-file-tools --no-embed-tools # 浏览器 Web UI 模式: # ucagent output/workspace_Adder/ Adder -s -hm --web-console --mcp-server-no-file-tools --no-embed-tools # 自定义 Web UI 地址/端口/密码(HTTP Basic Auth): # ucagent output/workspace_Adder/ Adder -s -hm --web-console 0.0.0.0:18000:secret --mcp-server-no-file-tools --no-embed-tools
MCP Server的默认地址为:http://127.0.0.1:5000/mcp
(2)启动 qwen 执行任务
cd output/workspace_Adder qwen
按以上方式启动qwen后,输入任务提示词:
请通过工具RoleInfo获取你的角色信息和基本指导,然后完成任务。请使用工具ReadTextFile读取文件。你需要在当前工作目录进行文件操作,不要超出该目录。
RoleInfo
ReadTextFile
注意:
提示:
继续,请通过工具Complete判断是否完成所有任务
💡 更多使用方式: 除了 MCP 协同模式,UCAgent 还支持直接接入 LLM、人机协同等多种模式,详见 使用文档
默认情况下,UCAgent只是启用内部的Python Checker进行阶段结果检查,属于启发式。如果需要验证质量提升,可以引入 LLM 阶段结果检查,如果需要达到“交付级”质量,还需要进一步引入人工阶段检查。
Python Checker
LLM 阶段结果检查
人工阶段检查
开启LLM阶段结果检查
开启人工阶段结果检查
阶段默认检查顺序:Python Checker -> LLM -> 人工
UCAgent提供了Master模式,基于它可以通过Web界面进行Agent集中管理、创建任务、查看状态、在线终端等操作。
# 编辑一个自定义文件export ucagent需要的环境变量,例如: # export OPENAI_API_BASE=<your_openai_api_base> # export OPENAI_API_KEY=<your_openai_api_key> # export OPENAI_MODEL=<your_openai_model> vim ~/.ucagent_env # 然后加载环境变量 source ~/.ucagent_env
make as_master_persist # 或者,如果安装了ucagent,也可以直接运行ucagent启动master模式 ucagent --as-master-persist --as-master
然后在浏览器中访问 http://localhost:8800 即可。
http://localhost:8800
docker run -it --rm \ -e OPENAI_API_BASE=<your_openai_api_base> \ -e OPENAI_API_KEY=<your_openai_api_key> \ -e OPENAI_MODEL=<your_openai_model> \ -p 8800:8800 \ ghcr.io/xs-mlvp/ucagent:latest ucagent --as-master-persist --as-master
如果 ghcr.io 无法访问,可以直接替换其为 ghcr.nju.edu.cn 等镜像地址。
启动成功后,在浏览器中访问 http://localhost:8800 即可。
+
ctrl + 上/下/左/右
ctrl + h/j/k/l
ctrl + c
ctrl + t
ctrl + /
f1
shift + 右
shift + 左
tab
pageup / pagedown
esc
白色
红色
绿色
*
hmcheck_pass [msg]
黄色
q
tui
tool_list
help
loop [prompt]
📖 详细操作说明: 查看 TUI 使用文档
Q: 如何配置不同的 AI 模型?
A: 在 config.yaml 中修改 openai.model_name 字段,支持任何 OpenAI 兼容的 API。详见配置文档。
config.yaml
openai.model_name
Q: 验证过程中出现错误怎么办?
A: 使用 Ctrl+C 进入交互模式,通过 status 查看当前状态,使用 help 获取调试命令。
Ctrl+C
status
Q: MCP 服务器无法连接?
A: 检查端口是否被占用,确认防火墙设置,可以通过 --mcp-server-port 指定其他端口。
--mcp-server-port
Q: 为何有上次执行信息残留?
A: UCAgent 默认会从工作目录中查找 .ucagent/ucagent_info.json 文件,来加载上次执行信息接着执行。如果不需要历史信息,请删除该文件或者使用参数 --no-history 忽略加载历史。
.ucagent/ucagent_info.json
--no-history
Q: 如何运行长时间验证?
A: 请参考 CodeAgent 的自定义后端 examples/CustomBackend/README.md。
Q: 可以自定义验证阶段吗?
A: 可以,详见自定义文档。
Q: 如何添加自定义工具?
A: 在 ucagent/tools/ 目录下创建新的工具类,继承 UCTool 基类,并通过 --ex-tools 参数加载。详见工具列表文档。
ucagent/tools/
UCTool
--ex-tools
🔍 更多问题: 查看完整 FAQ 文档
Makefile 提供文档相关辅助目标(MkDocs + Material):
make docs-help
make docs-install
docs/requirements-docs.txt
make docs-serve
make docs-build
docs/site
make docs-clean
第一次使用(安装依赖):
make docs-install # 安装 mkdocs 和 material 主题等依赖
日常开发(预览文档):
make docs-serve # 启动本地服务器,访问 http://127.0.0.1:8030 查看 # 修改文档后浏览器会自动刷新
本地生成和查看(构建生产版本):
make docs-build # 生成静态网站到 docs/site 目录 # 在本地浏览器中打开 docs/site/index.html 查看 make docs-clean # 清理构建产物(可选)
# 1. 首次设置:安装依赖 make docs-install # 2. 开发阶段:预览文档(可反复执行) make docs-serve # 在浏览器中访问 http://127.0.0.1:8030 # ...编辑文档... # 按 Ctrl+C 停止服务 # 3. 本地生成:构建生产版本 make docs-build # 生成 docs/site 目录 # 在本地浏览器中打开 docs/site/index.html 查看 # 4. 清理(可选) make docs-clean # 删除 docs/site 目录
docs/Makefile
用于生成较高排版质量开发者 PDF 手册:
make pdf
ucagent-doc.pdf
make pdf-one
pdf
make pdf-clean
make pdf make MONO="JetBrains Mono" pdf # 覆盖等宽字体 make TWOSIDE=1 pdf # 双面排版(文件名添加 -twoside) make pdf-clean
pandoc-crossref
MONO
TWOSIDE
fonts-noto-cjk
texlive-full
输出:ucagent-doc.pdf 可随版本发布分发。
欢迎提交 Issue 和 Pull Request!
UnityChip Verification AI-Agent
版权所有:中国计算机学会技术支持:开源发展技术委员会 京ICP备13000930号-9 京公网安备 11010802032778号
UCAgent(UnityChip verification Agent)
基于大模型进行自动化 UT 验证 AI 代理
English Introduction | UCAgent 在线文档
项目简介
UCAgent 是一个基于大语言模型的自动化硬件验证 AI 代理,专注于芯片设计的单元测试(Unit Test)验证工作。通过 AI 技术自动分析硬件设计,生成测试用例,执行验证任务并生成测试报告,从而提高验证效率。
核心特点:
更多详细介绍请参考 UCAgent 在线文档
系统要求
快速开始
1. 下载源码
2. 安装依赖
3. 安装配置 qwen
请参考 https://qwenlm.github.io/qwen-code-docs/en/ 安装qwen-code-cli,然后按以下示例配置MCP Server。
~/.qwen/settings.json示例:由于测试用例多了后运行时间较长,建议
timeout值设置大一些,例如 300 秒。其他Code Agent 请参考对应文档,例如 claude code, opencode, copilot-cli, kilo-cli, iflow 等。
4. 开始验证
以 example 中的 Adder 为例。
4.1 方式一:指定后端自动运行 qwen(推荐)
已经支持的后端请参考 ucagent/setting.yaml 中的
backend部分。4.2 方式二:手动运行qwen(适用于未适配的 CodeAgent )
(1)启动 MCP-Server
MCP Server的默认地址为:http://127.0.0.1:5000/mcp
(2)启动 qwen 执行任务
按以上方式启动qwen后,输入任务提示词:
注意:
提示:
继续,请通过工具Complete判断是否完成所有任务5. 如何提升验证质量(可选)
默认情况下,UCAgent只是启用内部的
Python Checker进行阶段结果检查,属于启发式。如果需要验证质量提升,可以引入LLM 阶段结果检查,如果需要达到“交付级”质量,还需要进一步引入人工阶段检查。开启LLM阶段结果检查
开启人工阶段结果检查
阶段默认检查顺序:Python Checker -> LLM -> 人工
通过Web界面交互
UCAgent提供了Master模式,基于它可以通过Web界面进行Agent集中管理、创建任务、查看状态、在线终端等操作。
本地启动
1. 配置环境变量
2. 启动 UCAgent Master
然后在浏览器中访问
http://localhost:8800即可。容器启动
如果 ghcr.io 无法访问,可以直接替换其为 ghcr.nju.edu.cn 等镜像地址。
启动成功后,在浏览器中访问
http://localhost:8800即可。基本操作
+按钮(或者launch按钮),创建一个新的任务。基本操作
TUI 快捷键
ctrl + 上/下/左/右:调节界面布局(Console 高度 / Mission 面板宽度)ctrl + h/j/k/l:Vim 风格调节界面布局(等同于 ctrl+左/下/上/右)ctrl + c:取消运行中的命令;无命令运行时退出 TUIctrl + t:打开主题选择器ctrl + /或f1:显示/隐藏快捷键帮助面板shift + 右:清空控制台输出shift + 左:清空输入行tab:命令补全;连续按 Tab 循环浏览候选项pageup / pagedown:Console 输出区翻页esc:退出滚动/分页/帮助面板,或清空输入行阶段颜色提示
白色:待执行红色:正在执行绿色:执行通过*:hmcheck_pass [msg]后 AI 才能继续黄色:跳过该阶段常用交互命令
q:退出 TUI(或退出 UCAgent)tui:进入 TUItab: 命令补全tool_list:列出所有可用工具help:查看所有命令帮助loop [prompt]:继续当前任务常见问题 (FAQ)
Q: 如何配置不同的 AI 模型?
A: 在
config.yaml中修改openai.model_name字段,支持任何 OpenAI 兼容的 API。详见配置文档。Q: 验证过程中出现错误怎么办?
A: 使用
Ctrl+C进入交互模式,通过status查看当前状态,使用help获取调试命令。Q: MCP 服务器无法连接?
A: 检查端口是否被占用,确认防火墙设置,可以通过
--mcp-server-port指定其他端口。Q: 为何有上次执行信息残留?
A: UCAgent 默认会从工作目录中查找
.ucagent/ucagent_info.json文件,来加载上次执行信息接着执行。如果不需要历史信息,请删除该文件或者使用参数--no-history忽略加载历史。Q: 如何运行长时间验证?
A: 请参考 CodeAgent 的自定义后端 examples/CustomBackend/README.md。
Q: 可以自定义验证阶段吗?
A: 可以,详见自定义文档。
Q: 如何添加自定义工具?
A: 在
ucagent/tools/目录下创建新的工具类,继承UCTool基类,并通过--ex-tools参数加载。详见工具列表文档。文档构建与预览(MkDocs)
Makefile 提供文档相关辅助目标(MkDocs + Material):
make docs-helpmake docs-installdocs/requirements-docs.txt安装构建依赖make docs-servemake docs-builddocs/sitemake docs-cleandocs/site目录使用流程
第一次使用(安装依赖):
日常开发(预览文档):
本地生成和查看(构建生产版本):
完整工作流示例
说明
docs/Makefile中,可自行修改。make docs-serve适合开发时使用,支持热重载make docs-build生成完整的静态网站文件,输出到 docs/site 目录,可本地预览最终效果(打开 docs/site/index.html)PDF 手册构建(Pandoc + XeLaTeX)
用于生成较高排版质量开发者 PDF 手册:
make pdfucagent-doc.pdfmake pdf-onepdf等价(方便 CI 调用)make pdf-clean示例
依赖
pandoc-crossref自定义变量
MONO更换等宽字体TWOSIDE非空启用双面模式常见问题
fonts-noto-cjk)。texlive-full)。pandoc-crossref在 PATH 中。输出:
ucagent-doc.pdf可随版本发布分发。获取更多帮助
贡献指南
欢迎提交 Issue 和 Pull Request!