Metadata-Version: 2.4
Name: UCAgent
Version: 2.0.1
Summary: UnityChip Verification Agent - AI-powered hardware verification tool
Author-email: XS-MLVP <unitychip@bosc.ac.cn>
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/XS-MLVP/UCAgent
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE.md
Requires-Dist: langchain>=1.2.15
Requires-Dist: langchain_community>=0.3.31
Requires-Dist: openai>=1.109.1
Requires-Dist: langgraph>=1.0.5
Requires-Dist: langchain_openai>=1.1.6
Requires-Dist: mem0ai>=0.1.118
Requires-Dist: mcp<3.0,>=2.3.0
Requires-Dist: psutil>=7.1.0
Requires-Dist: langfuse>=3.9.1
Requires-Dist: gitpython>=3.1.43
Requires-Dist: uc-toffee[runner]<3,>=2.4
Requires-Dist: textual>=7.3.0
Requires-Dist: Jinja2>=3.1.6
Requires-Dist: fastapi>=0.135.0
Requires-Dist: uvicorn[standard]>=0.42.0
Requires-Dist: aiohttp<4,>=3.13.5
Requires-Dist: docker>=7.1.0
Requires-Dist: kubernetes>=33.1.0
Requires-Dist: wavekit<0.8.0,>=0.7.0
Requires-Dist: pywellen<0.26,>=0.25.7
Requires-Dist: pylibfst<0.3,>=0.2.1
Requires-Dist: packaging<27,>=24
Requires-Dist: PyYAML<7.0,>=6.0
Requires-Dist: pydantic<3,>=2.7
Requires-Dist: markdown-it-py<5,>=3
Requires-Dist: regex>=2024.11.6
Dynamic: license-file


# UCAgent (UnityChip Verification Agent)

AI-powered automated UT verification agent based on large language models

[中文介绍](https://github.com/XS-MLVP/UCAgent/blob/main/README.zh.md) | [UCAgent Online Documentation](https://ucagent.open-verify.cc/)

[![PyPI](https://img.shields.io/pypi/v/ucagent?style=flat-square&logo=pypi&logoColor=white)](https://pypi.org/project/ucagent/)

## Introduction

UCAgent is an automated hardware verification AI agent based on large language models, focusing on Unit Test verification for chip design. It automatically analyzes hardware designs, generates test cases, executes verification tasks, and produces test reports through AI technology, thereby improving verification efficiency.

**Key Features:**

- Automated chip verification workflow
- Support for functional coverage and code coverage analysis
- Consistency assurance among documentation, code, and reports
- Deep collaboration with mainstream Code Agents (OpenHands, Copilot, Claude Code, Gemini-CLI, Qwen-Code, etc.) via MCP protocol
- Three intelligent interaction modes (standard, enhanced, advanced)

**For more details, please refer to [UCAgent Online Documentation](https://ucagent.open-verify.cc/)**

> [!TIP]
> The slide, code and environment for UCAgent workshop presented at **RISC-V Summit Europe 2026** are available at the official repository: [https://github.com/XS-MLVP/tutorial-records](https://github.com/XS-MLVP/tutorial-records)

---

## System Requirements

- Python 3.11+
- Supported OS: Linux, macOS
- Memory: 4GB+ recommended
- Network: Access to AI model API (OpenAI compatible)
- picker: https://github.com/XS-MLVP/picker

---

## Install from PyPI

Install **UCAgent 2.0** from [PyPI](https://pypi.org/project/ucagent/) in a Python 3.11+ virtual environment:

```bash
python -m pip install UCAgent
ucagent --version
```

See the [installation guide](https://ucagent.open-verify.cc/en/content/01_start/00_installation/) for environment setup and RTL verification dependencies.

## Quick Start

Once the RTL build tools and OpenCode are ready, open Global from the project directory containing your RTL and specification:

```bash
ucagent --agent-mode multi --backend opencode --tui
```

In one sentence, request ToffeeUT verification and name the DUT top module, RTL, and specification. See the [Global Agent guide](https://ucagent.open-verify.cc/en/content/02_usage/13_global_agent/) for a complete example.

To launch the bundled Adder example directly from a source checkout, follow the steps below.

### 1. Clone the Repository

```bash
git clone https://github.com/XS-MLVP/UCAgent.git
cd UCAgent
```

### 2. Install Dependencies

```bash
pip3 install -r requirements.txt
```

### 3. Install OpenCode

Please refer to [https://opencode.ai/](https://opencode.ai/) to install opencode.
For other Code Agents, please refer to their documentation, e.g., [claude code](https://claude.com/product/claude-code), [copilot-cli](https://docs.github.com/en/copilot/how-tos/use-copilot-agents/use-copilot-cli), [kilo-cli](https://kilo.ai/cli), [qwen-code](https://qwenlm.github.io/qwen-code-docs/en/), etc.

### 4. Configure LLM API

```bash
export OPENAI_MODEL=<model_name>              # e.g., glm-5.3-flash
export OPENAI_API_KEY=<your_key>              # API key
export OPENAI_API_BASE=<base_url>             # e.g., http://my_base_url/v1
export OPENAI_CONTEXT_SIZE=<max_context_size> # optional, e.g., 819200 (800k context)
export OPENAI_OUTPUT_SIZE=<max_output_size>   # optional, e.g., 131072 (128k max output)
```

You can also write the above content into `~/.ucagent_env`, and then load it:
```bash
source ~/.ucagent_env
```

With no model connection overrides, the default OpenCode backend uses the client's own model and authentication settings. You can also select an OpenCode model explicitly:

```bash
export UC_ENV_CMD_BACKEND_EX_ARGS="-m opencode/deepseek-v4.1-flash-free"
```

List available free models with `opencode models | grep free`.

### 5. Start Verification

Prepare the repository's Adder example and start ToffeeUT:

```bash
python -m ucagent prepare-workspace --app toffee-ut --workflow ut \
  --source examples/Adder --workspace output/toffee_Adder --dut Adder
python -m ucagent toffee-ut output/toffee_Adder Adder --agent-mode single \
  --backend opencode --no-embed-tools --mcp-server --mcp-server-port -1 --tui --loop
```

The first command prepares the workspace. The second opens the TUI and runs verification with OpenCode.

For supported backends, please refer to the `backend` section in [ucagent/setting.yaml](https://github.com/XS-MLVP/UCAgent/blob/main/ucagent/setting.yaml).

For other ways to launch UCAgent, see the [usage documentation](https://ucagent.open-verify.cc/content/02_usage/01_direct/).

### 6. How to Improve Verification Quality (Optional)

By default, UCAgent only enables the internal `Python Checker` for stage checking, which is heuristic. If you need verification quality improvement, you can enable `LLM stage checking`. If you need to reach "delivery level" quality, you further need to enable `Human stage checking`.

1. [Enable LLM stage checking](https://github.com/XS-MLVP/UCAgent/blob/main/examples/LLMCheck/README.md)

2. [Enable human stage checking](https://ucagent.open-verify.cc/content/02_usage/02_assit/)

Default stage checking order: Python Checker -> LLM -> Human

### 7. Verification Delivery

If the verification results need to be delivered, it is recommended to:
- Generate a high-quality README.md based on the Spec and verification requirements via Vibe coding
- Use the specification and RTL to decide whether verification needs a reference model or mock components
- Run ToffeeUT until no more bugs are found; if a reported bug is a false positive, fix the Spec document
- Run the formal workflow until no more bugs are found (e.g., `make formal_mcp_Adder ARGS="--loop --backend=opencode"`)
- Run the coverage workflow to raise RTL coverage above 99%

---

## Use Multi-Agent Mode

Reuse the OpenCode and model configuration above, then run from the repository root:

```bash
make multi MULTI_BACKEND=opencode \
  MULTI_PLUGIN=toffee-ut MULTI_WORKFLOW=toffee-ut:ut \
  MULTI_OVERRIDES="--override global_agent.root=output"
```

Then enter: “Verify Adder in examples/Adder with ToffeeUT.”
The Global session is saved under `output/default/`; new task workspaces use paths such as `output/task-000001/workspace/`.
Select Super/Sub in the Agent tree to inspect execution, and enter subsequent tasks in Global.
See the [Multi-Agent guide](https://ucagent.open-verify.cc/en/content/02_usage/11_multi_agent/) for more options.

---

## Interact via Web Interface

UCAgent provides Master mode, based on which you can perform centralized Agent management, create tasks, view status, use online terminals, and other operations through the web interface.

### Local Startup

#### 1. Configure Environment Variables

The environment variables are the same as the [Configure LLM API](#4-configure-llm-api) step in Quick Start (`OPENAI_MODEL`, `OPENAI_API_KEY`, `OPENAI_API_BASE`, etc.). If they are persisted in `~/.ucagent_env`, load it before startup:

```bash
source ~/.ucagent_env
```

#### 2. Start UCAgent Master

```bash
make as_master_persist
# Or, if ucagent is installed, you can directly run ucagent to start master mode
ucagent --as-master-persist --as-master
```

Then visit `http://localhost:8800` in your browser.

### Docker Startup

Pass the same LLM API environment variables via `-e` when starting the container:

```bash
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
```

Alternatively, use Docker's `--env-file` to provide the environment variables from a single file instead of multiple `-e` flags:

```bash
docker run -it --rm \
  --env-file ~/.ucagent_docker_env \
  -p 8800:8800 \
  ghcr.io/xs-mlvp/ucagent:latest ucagent --as-master-persist --as-master
```

An example `~/.ucagent_docker_env` is shown below. Unlike `~/.ucagent_env`, do not use `export` here, and `#` comments must be on their own line (an inline `#` becomes part of the value):

```bash
# Model name, e.g., glm-5.3-flash
OPENAI_MODEL=<model_name>
# API key
OPENAI_API_KEY=<your_key>
# API base URL, e.g., http://my_base_url/v1
OPENAI_API_BASE=<base_url>
# Optional: context window size (tokens), e.g., 819200 (800k context)
OPENAI_CONTEXT_SIZE=<max_context_size>
# Optional: max output size per response (tokens), e.g., 131072 (128k max output)
OPENAI_OUTPUT_SIZE=<max_output_size>
```

If ghcr.io is not accessible, you can directly replace it with mirror addresses such as `ghcr.nju.edu.cn`.

After successful startup, visit `http://localhost:8800` in your browser.

### Basic Operations

1. In the web interface, click the `+` button (or launch button) to create a new task.
2. In the Agent list, click the API button to connect to the control page of a specific Agent.
3. In the Agent control page, click the web terminal button to open the online terminal.
4. Start ucagent locally and connect to an existing Master service via the --master parameter.

### More Features

1. Launch page: create workspace, upload/import files, parse modules, compile, and preview launch command.
2. Task page: filter, paginate, inspect task details/logs, and stop/delete managed tasks.
3. Enhanced Agent page: stage multi-select and bulk toggles (HM/Skip/LFail/LPass), plus stage artifact content/diff review.
4. Unified proxy access: Master proxies cmd/terminal/web-console paths for both task and agent entries.
5. Improved Web Terminal: multiple terminal sessions across different URLs.

> 📖 **Detailed Operations:** See [TUI Usage Documentation](https://ucagent.open-verify.cc/content/07_web_master/)

---

## Basic Operations

### TUI Shortcuts

- `ctrl+up/down/left/right`: Adjust layout (Console height / Mission panel width)
- `ctrl+h/j/k/l`: Vim-style layout adjustment (equivalent to ctrl+left/down/up/right)
- `ctrl+c`: Cancel running command; exit TUI if no command is running
- `ctrl+t`: Open theme picker
- `f1`: Show/hide keyboard shortcuts help panel
- `shift+right`: Clear console output
- `shift+left`: Clear input text
- `tab`: Command completion; press Tab repeatedly to cycle through candidates
- `pageup/pagedown`: Page through Console output
- `esc`: Exit scrolling/paging/help panel, or clear input

### Stage Color Indicators

- `White`: Pending execution
- `Red`: Currently executing
- `Green`: Execution passed
- `*`:
  - Blue indicates LLM Fail checking is enabled for this stage, providing modification suggestions when stage check fails more than 3 times
  - Green indicates LLM Pass checking is enabled for this stage, verifying if stage task requirements are met upon completion
  - Red indicates this stage requires mandatory human inspection, AI can continue after entering command `hmcheck_pass [msg]`
- `Yellow`: Stage skipped

### Common Interactive Commands

- `q`: Exit TUI (or exit UCAgent)
- `tui`: Enter TUI
- `tab`: Command completion
- `tool_list`: List all available tools
- `help`: View all command help
- `loop [prompt]`: Continue current task

> 📖 **Detailed Operations:** See [TUI Usage Documentation](https://ucagent.open-verify.cc/content/02_usage/04_tui/)

---

## Frequently Asked Questions (FAQ)

**Q: How to configure different AI models?**

A: Modify the `openai.model_name` field in `config.yaml`, which supports any OpenAI-compatible API. See [Configuration Documentation](https://ucagent.open-verify.cc/content/02_usage/01_direct/).

**Q: What to do when errors occur during verification?**

A: Use `Ctrl+C` to enter interactive mode, check current status with `status`, and use `help` to get debugging commands.

**Q: MCP server cannot connect?**

A: Check if the port is occupied, verify firewall settings, and you can specify a different port with `--mcp-server-port`.

**Q: Why is there information from the last execution?**

A: UCAgent by default looks for the `.ucagent/ucagent_info.json` file in the working directory to load previous execution information and continue. If you don't need history, delete this file or use the `--no-history` parameter to ignore loading history.

**Q: How to run long-duration verification?**

A: Please refer to CodeAgent's custom backend mode [examples/CustomBackend/README.md](https://github.com/XS-MLVP/UCAgent/blob/main/examples/CustomBackend/README.md).

**Q: Can verification stages be customized?**

A: Yes, see [Customization Documentation](https://ucagent.open-verify.cc/content/03_develop/01_customize/).

**Q: How to add custom tools?**

A: Create a new tool class in the `ucagent/core/tools/` directory, inherit from the `UCTool` base class, and load it with the `--ex-tools` parameter. See [Tool List Documentation](https://ucagent.open-verify.cc/content/03_develop/02_tool_list/).

> 🔍 **More Questions:** Check the complete [FAQ Documentation](https://ucagent.open-verify.cc/content/02_usage/05_faq/)

---

## Documentation Build and Preview (MkDocs)

The Makefile provides documentation-related helper targets (MkDocs + Material):

| Target              | Purpose                                                      | Use Case                        |
| ------------------- | ------------------------------------------------------------ | ------------------------------- |
| `make docs-help`    | Show documentation-related target help                       | View available commands         |
| `make docs-install` | Install build dependencies from `docs/requirements-docs.txt` | First use or dependency updates |
| `make docs-serve`   | Local preview (default 127.0.0.1:8030)                       | Develop and preview docs        |
| `make docs-build`   | Build static site to `site`                             | Generate production version     |
| `make docs-clean`   | Delete `site` directory                                 | Clean build artifacts           |

### Usage Flow

**First-time use (install dependencies):**

```bash
make docs-install    # Install mkdocs and material theme dependencies
```

**Daily development (preview documentation):**

```bash
make docs-serve      # Start local server, visit http://127.0.0.1:8030
# Browser will auto-refresh after modifying docs
```

**Local generation and viewing (build production version):**

```bash
make docs-build      # Generate static website to site directory
# Open site/index.html in local browser
make docs-clean      # Clean build artifacts (optional)
```

### Complete Workflow Example

```bash
# 1. Initial setup: Install dependencies
make docs-install

# 2. Development phase: Preview docs (can be repeated)
make docs-serve      # Visit http://127.0.0.1:8030 in browser
# ...edit documentation...
# Press Ctrl+C to stop service

# 3. Local generation: Build production version
make docs-build      # Generate site directory
# Open site/index.html in local browser

# 4. Cleanup (optional)
make docs-clean      # Delete site directory
```

### Notes

- Port and address are currently hardcoded in `docs/Makefile`, can be modified as needed.
- `make docs-serve` is suitable for development use, supports hot reload
- `make docs-build` generates complete static website files, output to site directory, can preview final effect locally (open site/index.html)

---

## PDF Manual Build (Pandoc + XeLaTeX)

For generating high-quality developer PDF manuals:

| Target           | Purpose                                                  |
| ---------------- | -------------------------------------------------------- |
| `make pdf`       | Generate `ucagent-doc.pdf` from ordered Markdown sources |
| `make pdf-one`   | Equivalent to `pdf` (convenient for CI calls)            |
| `make pdf-clean` | Clean generated PDF and LaTeX temporary files            |

### Examples

```bash
make pdf
make MONO="JetBrains Mono" pdf      # Override monospace font
make TWOSIDE=1 pdf                   # Two-sided layout (adds -twoside to filename)
make pdf-clean
```

### Dependencies

- pandoc
- XeLaTeX (TexLive)
- Chinese font "Noto Serif CJK SC"
- Monospace font (default DejaVu Sans Mono)
- Optional filter `pandoc-crossref`

### Custom Variables

- `MONO` Change monospace font
- `TWOSIDE` Enable two-sided mode when non-empty

### Common Issues

- **Missing fonts:** Install CJK font packages (e.g., `fonts-noto-cjk`).
- **LaTeX errors:** Ensure complete XeLaTeX suite is installed (use `texlive-full` if necessary).
- **Missing cross-references:** Confirm `pandoc-crossref` is in PATH.

Output: `ucagent-doc.pdf` can be distributed with version releases.

---

## Get More Help

- 📚 [UCAgent Online Documentation](https://ucagent.open-verify.cc)
- 🚀 [Quick Start Guide](https://ucagent.open-verify.cc/content/02_usage/01_direct/)
- 🔧 [Custom Configuration](https://ucagent.open-verify.cc/content/03_develop/01_customize/)
- 🛠️ [Tool List](https://ucagent.open-verify.cc/content/03_develop/02_tool_list/)
- 💬 [GitHub Issues](https://github.com/XS-MLVP/UCAgent/issues)

### Contributing

Issues and Pull Requests are welcome!

<div align="center">
<img src="https://raw.githubusercontent.com/XS-MLVP/UCAgent/main/.github/group.png"/>
</div>
