circuit-agent-client 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- circuit_agent_client-0.1.3/LICENSE +21 -0
- circuit_agent_client-0.1.3/PKG-INFO +266 -0
- circuit_agent_client-0.1.3/README.md +242 -0
- circuit_agent_client-0.1.3/circuit_agent_client.egg-info/PKG-INFO +266 -0
- circuit_agent_client-0.1.3/circuit_agent_client.egg-info/SOURCES.txt +18 -0
- circuit_agent_client-0.1.3/circuit_agent_client.egg-info/dependency_links.txt +1 -0
- circuit_agent_client-0.1.3/circuit_agent_client.egg-info/entry_points.txt +2 -0
- circuit_agent_client-0.1.3/circuit_agent_client.egg-info/requires.txt +3 -0
- circuit_agent_client-0.1.3/circuit_agent_client.egg-info/top_level.txt +1 -0
- circuit_agent_client-0.1.3/client/__init__.py +39 -0
- circuit_agent_client-0.1.3/client/circuit_blocks.py +323 -0
- circuit_agent_client-0.1.3/client/lcsc_client.py +196 -0
- circuit_agent_client-0.1.3/client/mcp_server.py +815 -0
- circuit_agent_client-0.1.3/client/synthesizer.py +188 -0
- circuit_agent_client-0.1.3/pyproject.toml +41 -0
- circuit_agent_client-0.1.3/setup.cfg +4 -0
- circuit_agent_client-0.1.3/tests/test_circuit_blocks.py +199 -0
- circuit_agent_client-0.1.3/tests/test_examples_schema.py +67 -0
- circuit_agent_client-0.1.3/tests/test_lcsc_client.py +138 -0
- circuit_agent_client-0.1.3/tests/test_mcp_server.py +331 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 sora (mo9652962-ai)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: circuit-agent-client
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: CircuitAgent Community Edition: hardware DSL, LCSC live-selection client, and netlist contracts
|
|
5
|
+
Author: sora
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mo9652962-ai/circuit-agent
|
|
8
|
+
Project-URL: Issues, https://github.com/mo9652962-ai/circuit-agent/issues
|
|
9
|
+
Keywords: eda,pcb,hardware,llm,kicad,jlcpcb,mcp
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Provides-Extra: dev
|
|
22
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
23
|
+
Dynamic: license-file
|
|
24
|
+
|
|
25
|
+
<p align="center">
|
|
26
|
+
<img src="docs/images/banner-1200x640.png" alt="CircuitAgent Banner" width="100%">
|
|
27
|
+
</p>
|
|
28
|
+
|
|
29
|
+
# CircuitAgent · Community Edition
|
|
30
|
+
|
|
31
|
+
**Prompt → Schematic → Layout → 3D Enclosure → Fabrication Bundle**
|
|
32
|
+
|
|
33
|
+
<p align="center">
|
|
34
|
+
<a href="https://github.com/mo9652962-ai/circuit-agent/actions/workflows/ci.yml"><img src="https://github.com/mo9652962-ai/circuit-agent/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
35
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
36
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.10%2B-blue.svg" alt="Python 3.10+"></a>
|
|
37
|
+
<a href="tests/"><img src="https://img.shields.io/badge/tests-120%20passing-brightgreen.svg" alt="Tests"></a>
|
|
38
|
+
<a href="https://github.com/mo9652962-ai/circuit-agent/releases"><img src="https://img.shields.io/badge/release-v0.1.0-blueviolet.svg" alt="Release"></a>
|
|
39
|
+
</p>
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<a href="README.md"><b>中文说明</b></a> | <a href="README_EN.md"><b>English</b></a>
|
|
43
|
+
</p>
|
|
44
|
+
|
|
45
|
+
> **Status: alpha.** This repository is the open community layer of CircuitAgent: the
|
|
46
|
+
> hardware DSL, the LCSC live-selection client, and the data contracts that the
|
|
47
|
+
> full compiler consumes. The block set is deliberately small and every block is
|
|
48
|
+
> unit-tested — correctness over coverage.
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 为什么需要这一层 (Why this layer exists)
|
|
53
|
+
|
|
54
|
+
让大语言模型直接生成底层走线、焊盘与封装,几乎必然产出非法几何或引脚短路。
|
|
55
|
+
CircuitAgent 的做法是把 LLM 的输出**约束在预验证的电路积木上**,再用 Pydantic
|
|
56
|
+
契约把它变成确定性网表 —— 模型只负责"选积木",不负责"画线"。
|
|
57
|
+
|
|
58
|
+
<p align="center">
|
|
59
|
+
<img src="docs/images/demo.gif" alt="CircuitAgent Pro 工作台演示" width="85%">
|
|
60
|
+
</p>
|
|
61
|
+
|
|
62
|
+
```text
|
|
63
|
+
Natural language prompt
|
|
64
|
+
│
|
|
65
|
+
▼
|
|
66
|
+
┌────────────────────────┐
|
|
67
|
+
│ CircuitBlocks DSL │ keyword → audited sub-circuits (deterministic)
|
|
68
|
+
└────────────────────────┘
|
|
69
|
+
│
|
|
70
|
+
▼
|
|
71
|
+
┌────────────────────────┐
|
|
72
|
+
│ Netlist contract │ Pydantic / JSON Schema (SSOT)
|
|
73
|
+
└────────────────────────┘
|
|
74
|
+
│
|
|
75
|
+
┌────┴─────┐
|
|
76
|
+
▼ ▼
|
|
77
|
+
┌────────┐ ┌──────────────────┐
|
|
78
|
+
│ LCSC │ │ REST / MCP APIs │
|
|
79
|
+
│ client │ │ (community layer)│
|
|
80
|
+
└────────┘ └──────────────────┘
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## 快速上手 (Quick Start)
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
git clone https://github.com/mo9652962-ai/circuit-agent.git
|
|
89
|
+
cd circuit-agent
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
零运行时依赖 —— 纯标准库实现,无需 `pip install` 即可直接使用。
|
|
93
|
+
跑测试才需要装 dev extra:`pip install -e ".[dev]"`
|
|
94
|
+
|
|
95
|
+
### 1 · 一句话生成硬件网表
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from client.synthesizer import synthesize_from_prompt
|
|
99
|
+
|
|
100
|
+
spec = synthesize_from_prompt(
|
|
101
|
+
"基于 ESP32-C3 的环境监测节点,带 Type-C 供电、I2C 传感器插座、指示灯和2个按键"
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
print(spec["chip_id"]) # ESP32-C3
|
|
105
|
+
print(len(spec["modules"])) # 元器件数
|
|
106
|
+
print(spec["netlist"]["connections"][0]) # 第一条网络连接
|
|
107
|
+
print(spec["unmatched"]) # 未识别的意图(不会被静默丢弃)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
映射是**确定性的**:同一句话永远产出逐字节相同的结果(CI 中有对应断言)。
|
|
111
|
+
|
|
112
|
+
### 2 · 查询立创商城实时库存与单价
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from client.lcsc_client import search_lcsc_parts
|
|
116
|
+
|
|
117
|
+
for part in search_lcsc_parts("CH340N", limit=3):
|
|
118
|
+
print(f"[{part['lcsc_part']}] {part['part_number']} | {part['package']} | "
|
|
119
|
+
f"库存 {part['stock']} | ${part['price_usd']} | {part['part_class']}")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```text
|
|
123
|
+
[C506813] CH340N | SOP-8_L5.0-W4.0-P1.27-LS6.0-BL | 库存 196 | $0.5537 | Extended Part
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
客户端自带**重试退避 + 硬超时 + 24 小时磁盘缓存 + 防御式解析**:上游改结构不会
|
|
127
|
+
抛异常,断网时回落到缓存(缓存也没有则返回空列表,调用方永远不必处理传输层异常)。
|
|
128
|
+
|
|
129
|
+
### 3 · 直接用积木搭电路
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
from client.circuit_blocks import block_usb_c_power, block_power_ldo_3v3
|
|
133
|
+
|
|
134
|
+
blk = block_power_ldo_3v3()
|
|
135
|
+
for comp in blk.components:
|
|
136
|
+
print(comp.ref, comp.value, comp.package, comp.lcsc)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
## 积木清单 (Block Catalogue)
|
|
142
|
+
|
|
143
|
+
| Block | 说明 | 关键设计点 |
|
|
144
|
+
|:---|:---|:---|
|
|
145
|
+
| `block_usb_c_power` | Type-C 供电输入 | 双 5.1k CC 下拉(sink 角色,非 56k 上拉) |
|
|
146
|
+
| `block_power_ldo_3v3` | AMS1117-3.3V 稳压 | 10µF 输入/输出储能电容 |
|
|
147
|
+
| `block_crystal_clock` | 无源晶振 + 负载电容 | 标记 `guard_ring` 属性供后端加地屏蔽环 |
|
|
148
|
+
| `block_button` | 消抖按键 | 10k 上拉 + 100nF RC,位号可参数化 |
|
|
149
|
+
| `block_led` | 状态指示灯 | 限流电阻 + 颜色/阻值可参数化 |
|
|
150
|
+
| `block_buzzer` | 蜂鸣器驱动 | S8050 NPN + 1N4148W 反向续流二极管 |
|
|
151
|
+
| `block_i2c_header` | I2C 扩展排针 | SCL/SDA 各 4.7k 上拉 |
|
|
152
|
+
| `block_rs485_transceiver` | SP3485 半双工差分串口 | 120Ω 终端电阻 + 100nF 去耦 + 3P 排针引出 |
|
|
153
|
+
| `block_can_transceiver` | SN65HVD230 3.3V CAN 节点 | 120Ω 终端匹配 + 10k 斜率控制 (高速模式) |
|
|
154
|
+
| `block_battery_tp4056` | TP4056 1A 线性锂电充电 | 1.2k 限流 + 充/满双色指示灯 + 2P 电池端子 |
|
|
155
|
+
|
|
156
|
+
每个积木的引脚号、LCSC 料号、封装名在冻结前均对照数据手册与立创商城列表核验过。
|
|
157
|
+
`tests/test_circuit_blocks.py` 会强制校验:位号唯一、每个元件都有封装与料号、
|
|
158
|
+
网络端点必须指向已声明的元件、每个积木都必须接 `/GND`。
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## MCP Server (AI Agent 工具服务)
|
|
163
|
+
|
|
164
|
+
CircuitAgent 内置标准 JSON-RPC 2.0 stdio MCP Server,基于纯 Python 标准库构建(无需任何第三方 pip 库),可无缝接入 **Claude Desktop**、**Cursor** 或 **Windsurf**。
|
|
165
|
+
|
|
166
|
+
### 运行方式
|
|
167
|
+
```bash
|
|
168
|
+
python -m client.mcp_server
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Claude Desktop 配置 (`claude_desktop_config.json`)
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"mcpServers": {
|
|
175
|
+
"circuit-agent": {
|
|
176
|
+
"command": "python",
|
|
177
|
+
"args": ["-m", "client.mcp_server"],
|
|
178
|
+
"cwd": "/path/to/circuit-agent"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### 暴露的工具 (Tools)
|
|
185
|
+
1. `synthesize_circuit`: 输入自然语言,输出确定性硬件网表与积木清单。
|
|
186
|
+
2. `search_lcsc_parts`: 免 Key 实时查询立创商城的元器件库存、封装、阶梯单价与基础库/扩展库属性。
|
|
187
|
+
3. `list_circuit_blocks`: 列出 DSL 中全部可用的 10 大已审计电路积木规格。
|
|
188
|
+
4. `validate_netlist`: 根据正式 JSON Schema 校验网表数据结构合法性。
|
|
189
|
+
5. `calculate_trace_impedance`: 基于 IPC-2141 解析公式计算微带线与差分对走线阻抗(50Ω RF / 90Ω USB / 120Ω CAN/485)。
|
|
190
|
+
6. `calculate_bom_cost`: PCBA 成本核算器,自动精算元器件裸成本与嘉立创扩展库换料费(¥20/种)。
|
|
191
|
+
|
|
192
|
+
### 暴露的资源 (Resources)
|
|
193
|
+
支持通过 `circuit://` URI 直接将规范加载到大模型上下文,无需执行额外工具:
|
|
194
|
+
- `circuit://specs/netlist-schema`: 完整的网表 Draft-07 JSON Schema。
|
|
195
|
+
- `circuit://specs/cpl-standard`: 嘉立创 SMT 坐标规范与封装偏角补偿表。
|
|
196
|
+
- `circuit://blocks/catalog`: 10 大电路积木的元器件、引脚与网络全量清单。
|
|
197
|
+
- `circuit://rules/jlc-smt`: 嘉立创四层板叠层 (JLC04161H) 与生产物理规则。
|
|
198
|
+
- `circuit://examples/esp32c3-minimal`: ESP32-C3 极简温湿度节点参考网表。
|
|
199
|
+
- `circuit://examples/stm32f103-controller`: STM32F103 工业控制板参考网表。
|
|
200
|
+
- `circuit://examples/rp2040-dualcore`: RP2040 双核传感器扩展板参考网表。
|
|
201
|
+
|
|
202
|
+
### 快捷工程 Prompt (Slash-Commands)
|
|
203
|
+
- `/design_hardware_project`: 全流程硬件设计指令(积木匹配 → 阻抗计算 → BOM核算 → 网表校验)。
|
|
204
|
+
- `/audit_schematic_netlist`: Senior EE 硬件体检审查指令(去耦电容亲和性、差分对等长、Type-C 下拉阻抗)。
|
|
205
|
+
- `/optimize_bom_cost`: PCBA 降本优化指令(分析扩展库物料并推荐免换料费的基础库替代料)。
|
|
206
|
+
|
|
207
|
+
---
|
|
208
|
+
|
|
209
|
+
## 数据契约 (Contracts)
|
|
210
|
+
|
|
211
|
+
- [`specs/netlist_schema.json`](specs/netlist_schema.json) — 网表 JSON Schema
|
|
212
|
+
- [`specs/cpl_standard.md`](specs/cpl_standard.md) — 嘉立创 SMT 坐标规范与封装偏角补偿表
|
|
213
|
+
- [`examples/`](examples/) — STM32F103 / ESP32-C3 / RP2040 参考网表,CI 强制校验其符合 Schema
|
|
214
|
+
|
|
215
|
+
---
|
|
216
|
+
|
|
217
|
+
## 测试与 CI
|
|
218
|
+
|
|
219
|
+
```bash
|
|
220
|
+
pytest tests/ -q # 120 passed
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
CI 在 `ubuntu-latest` + `windows-latest` × Python 3.10/3.11/3.12 上跑全量测试,
|
|
224
|
+
并额外做两件事:校验 `examples/` 全部符合 Schema、离线跑通 README 里的快速上手命令。
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## 范围与路线图 (Scope & Roadmap)
|
|
229
|
+
|
|
230
|
+
**本仓库包含**:硬件 DSL 与积木库、立创实时选型客户端、网表/CPL 数据契约、标准 MCP Server、REST 交互接口。
|
|
231
|
+
|
|
232
|
+
**暂不包含**:多层板物理布局与布线求解、参数化 3D 壳体布尔几何、Senior EE 物理规则门禁。
|
|
233
|
+
这些是上游编译器的高级能力,仍在开发中;本仓库通过稳定的数据契约与客户端接口与其对接,
|
|
234
|
+
契约本身是公开且版本化的。
|
|
235
|
+
|
|
236
|
+
路线图:
|
|
237
|
+
|
|
238
|
+
- [x] 积木库 + 确定性映射 + 单元测试
|
|
239
|
+
- [x] 立创实时选型客户端(重试/缓存/降级)
|
|
240
|
+
- [x] JSON Schema + 三份参考样例 + CI
|
|
241
|
+
- [x] 工业级实用积木(RS485 / CAN / TP4056 锂电)
|
|
242
|
+
- [x] 标准 MCP Server 实现(纯标准库,4 大工具)
|
|
243
|
+
- [x] 中英双语文档与官方门面 (Banner + Demo GIF)
|
|
244
|
+
- [ ] 更多传感器积木(AHT20 温湿度 / MPU6050 六轴)
|
|
245
|
+
- [ ] 支持自定义第三方芯片引脚分配映射规则
|
|
246
|
+
|
|
247
|
+
---
|
|
248
|
+
|
|
249
|
+
## 参与贡献 (Contributing)
|
|
250
|
+
|
|
251
|
+
最欢迎的贡献是**新增经过核验的电路积木**:带上数据手册依据的引脚定义与立创料号,
|
|
252
|
+
并补上对应单测即可提 PR。Issue 里也欢迎贴出你希望支持的芯片型号。
|
|
253
|
+
|
|
254
|
+
---
|
|
255
|
+
|
|
256
|
+
## 名称说明 (Naming)
|
|
257
|
+
|
|
258
|
+
"CircuitAgent" 是一个较通用的名字,社区中已有若干同名或近名的项目(例如
|
|
259
|
+
`singularguy/CircuitManus` 内部的 `CircuitAgent` 类、`Circuit-LLM/circuit-sdk`
|
|
260
|
+
的 `CircuitAgent` 基类、以及高能物理领域的 PhEDEx `CircuitAgent`)。
|
|
261
|
+
本项目与它们**没有任何关系**,也不主张该名称的独占权。如果你的项目或商标与此冲突,
|
|
262
|
+
欢迎开 Issue 告知,我们可以协商改名。
|
|
263
|
+
|
|
264
|
+
## 许可证 (License)
|
|
265
|
+
|
|
266
|
+
[MIT](LICENSE) © 2026 sora
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="docs/images/banner-1200x640.png" alt="CircuitAgent Banner" width="100%">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
5
|
+
# CircuitAgent · Community Edition
|
|
6
|
+
|
|
7
|
+
**Prompt → Schematic → Layout → 3D Enclosure → Fabrication Bundle**
|
|
8
|
+
|
|
9
|
+
<p align="center">
|
|
10
|
+
<a href="https://github.com/mo9652962-ai/circuit-agent/actions/workflows/ci.yml"><img src="https://github.com/mo9652962-ai/circuit-agent/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
11
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="License: MIT"></a>
|
|
12
|
+
<a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.10%2B-blue.svg" alt="Python 3.10+"></a>
|
|
13
|
+
<a href="tests/"><img src="https://img.shields.io/badge/tests-120%20passing-brightgreen.svg" alt="Tests"></a>
|
|
14
|
+
<a href="https://github.com/mo9652962-ai/circuit-agent/releases"><img src="https://img.shields.io/badge/release-v0.1.0-blueviolet.svg" alt="Release"></a>
|
|
15
|
+
</p>
|
|
16
|
+
|
|
17
|
+
<p align="center">
|
|
18
|
+
<a href="README.md"><b>中文说明</b></a> | <a href="README_EN.md"><b>English</b></a>
|
|
19
|
+
</p>
|
|
20
|
+
|
|
21
|
+
> **Status: alpha.** This repository is the open community layer of CircuitAgent: the
|
|
22
|
+
> hardware DSL, the LCSC live-selection client, and the data contracts that the
|
|
23
|
+
> full compiler consumes. The block set is deliberately small and every block is
|
|
24
|
+
> unit-tested — correctness over coverage.
|
|
25
|
+
|
|
26
|
+
---
|
|
27
|
+
|
|
28
|
+
## 为什么需要这一层 (Why this layer exists)
|
|
29
|
+
|
|
30
|
+
让大语言模型直接生成底层走线、焊盘与封装,几乎必然产出非法几何或引脚短路。
|
|
31
|
+
CircuitAgent 的做法是把 LLM 的输出**约束在预验证的电路积木上**,再用 Pydantic
|
|
32
|
+
契约把它变成确定性网表 —— 模型只负责"选积木",不负责"画线"。
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<img src="docs/images/demo.gif" alt="CircuitAgent Pro 工作台演示" width="85%">
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
Natural language prompt
|
|
40
|
+
│
|
|
41
|
+
▼
|
|
42
|
+
┌────────────────────────┐
|
|
43
|
+
│ CircuitBlocks DSL │ keyword → audited sub-circuits (deterministic)
|
|
44
|
+
└────────────────────────┘
|
|
45
|
+
│
|
|
46
|
+
▼
|
|
47
|
+
┌────────────────────────┐
|
|
48
|
+
│ Netlist contract │ Pydantic / JSON Schema (SSOT)
|
|
49
|
+
└────────────────────────┘
|
|
50
|
+
│
|
|
51
|
+
┌────┴─────┐
|
|
52
|
+
▼ ▼
|
|
53
|
+
┌────────┐ ┌──────────────────┐
|
|
54
|
+
│ LCSC │ │ REST / MCP APIs │
|
|
55
|
+
│ client │ │ (community layer)│
|
|
56
|
+
└────────┘ └──────────────────┘
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 快速上手 (Quick Start)
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
git clone https://github.com/mo9652962-ai/circuit-agent.git
|
|
65
|
+
cd circuit-agent
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
零运行时依赖 —— 纯标准库实现,无需 `pip install` 即可直接使用。
|
|
69
|
+
跑测试才需要装 dev extra:`pip install -e ".[dev]"`
|
|
70
|
+
|
|
71
|
+
### 1 · 一句话生成硬件网表
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from client.synthesizer import synthesize_from_prompt
|
|
75
|
+
|
|
76
|
+
spec = synthesize_from_prompt(
|
|
77
|
+
"基于 ESP32-C3 的环境监测节点,带 Type-C 供电、I2C 传感器插座、指示灯和2个按键"
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
print(spec["chip_id"]) # ESP32-C3
|
|
81
|
+
print(len(spec["modules"])) # 元器件数
|
|
82
|
+
print(spec["netlist"]["connections"][0]) # 第一条网络连接
|
|
83
|
+
print(spec["unmatched"]) # 未识别的意图(不会被静默丢弃)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
映射是**确定性的**:同一句话永远产出逐字节相同的结果(CI 中有对应断言)。
|
|
87
|
+
|
|
88
|
+
### 2 · 查询立创商城实时库存与单价
|
|
89
|
+
|
|
90
|
+
```python
|
|
91
|
+
from client.lcsc_client import search_lcsc_parts
|
|
92
|
+
|
|
93
|
+
for part in search_lcsc_parts("CH340N", limit=3):
|
|
94
|
+
print(f"[{part['lcsc_part']}] {part['part_number']} | {part['package']} | "
|
|
95
|
+
f"库存 {part['stock']} | ${part['price_usd']} | {part['part_class']}")
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
```text
|
|
99
|
+
[C506813] CH340N | SOP-8_L5.0-W4.0-P1.27-LS6.0-BL | 库存 196 | $0.5537 | Extended Part
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
客户端自带**重试退避 + 硬超时 + 24 小时磁盘缓存 + 防御式解析**:上游改结构不会
|
|
103
|
+
抛异常,断网时回落到缓存(缓存也没有则返回空列表,调用方永远不必处理传输层异常)。
|
|
104
|
+
|
|
105
|
+
### 3 · 直接用积木搭电路
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from client.circuit_blocks import block_usb_c_power, block_power_ldo_3v3
|
|
109
|
+
|
|
110
|
+
blk = block_power_ldo_3v3()
|
|
111
|
+
for comp in blk.components:
|
|
112
|
+
print(comp.ref, comp.value, comp.package, comp.lcsc)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## 积木清单 (Block Catalogue)
|
|
118
|
+
|
|
119
|
+
| Block | 说明 | 关键设计点 |
|
|
120
|
+
|:---|:---|:---|
|
|
121
|
+
| `block_usb_c_power` | Type-C 供电输入 | 双 5.1k CC 下拉(sink 角色,非 56k 上拉) |
|
|
122
|
+
| `block_power_ldo_3v3` | AMS1117-3.3V 稳压 | 10µF 输入/输出储能电容 |
|
|
123
|
+
| `block_crystal_clock` | 无源晶振 + 负载电容 | 标记 `guard_ring` 属性供后端加地屏蔽环 |
|
|
124
|
+
| `block_button` | 消抖按键 | 10k 上拉 + 100nF RC,位号可参数化 |
|
|
125
|
+
| `block_led` | 状态指示灯 | 限流电阻 + 颜色/阻值可参数化 |
|
|
126
|
+
| `block_buzzer` | 蜂鸣器驱动 | S8050 NPN + 1N4148W 反向续流二极管 |
|
|
127
|
+
| `block_i2c_header` | I2C 扩展排针 | SCL/SDA 各 4.7k 上拉 |
|
|
128
|
+
| `block_rs485_transceiver` | SP3485 半双工差分串口 | 120Ω 终端电阻 + 100nF 去耦 + 3P 排针引出 |
|
|
129
|
+
| `block_can_transceiver` | SN65HVD230 3.3V CAN 节点 | 120Ω 终端匹配 + 10k 斜率控制 (高速模式) |
|
|
130
|
+
| `block_battery_tp4056` | TP4056 1A 线性锂电充电 | 1.2k 限流 + 充/满双色指示灯 + 2P 电池端子 |
|
|
131
|
+
|
|
132
|
+
每个积木的引脚号、LCSC 料号、封装名在冻结前均对照数据手册与立创商城列表核验过。
|
|
133
|
+
`tests/test_circuit_blocks.py` 会强制校验:位号唯一、每个元件都有封装与料号、
|
|
134
|
+
网络端点必须指向已声明的元件、每个积木都必须接 `/GND`。
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
## MCP Server (AI Agent 工具服务)
|
|
139
|
+
|
|
140
|
+
CircuitAgent 内置标准 JSON-RPC 2.0 stdio MCP Server,基于纯 Python 标准库构建(无需任何第三方 pip 库),可无缝接入 **Claude Desktop**、**Cursor** 或 **Windsurf**。
|
|
141
|
+
|
|
142
|
+
### 运行方式
|
|
143
|
+
```bash
|
|
144
|
+
python -m client.mcp_server
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Claude Desktop 配置 (`claude_desktop_config.json`)
|
|
148
|
+
```json
|
|
149
|
+
{
|
|
150
|
+
"mcpServers": {
|
|
151
|
+
"circuit-agent": {
|
|
152
|
+
"command": "python",
|
|
153
|
+
"args": ["-m", "client.mcp_server"],
|
|
154
|
+
"cwd": "/path/to/circuit-agent"
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### 暴露的工具 (Tools)
|
|
161
|
+
1. `synthesize_circuit`: 输入自然语言,输出确定性硬件网表与积木清单。
|
|
162
|
+
2. `search_lcsc_parts`: 免 Key 实时查询立创商城的元器件库存、封装、阶梯单价与基础库/扩展库属性。
|
|
163
|
+
3. `list_circuit_blocks`: 列出 DSL 中全部可用的 10 大已审计电路积木规格。
|
|
164
|
+
4. `validate_netlist`: 根据正式 JSON Schema 校验网表数据结构合法性。
|
|
165
|
+
5. `calculate_trace_impedance`: 基于 IPC-2141 解析公式计算微带线与差分对走线阻抗(50Ω RF / 90Ω USB / 120Ω CAN/485)。
|
|
166
|
+
6. `calculate_bom_cost`: PCBA 成本核算器,自动精算元器件裸成本与嘉立创扩展库换料费(¥20/种)。
|
|
167
|
+
|
|
168
|
+
### 暴露的资源 (Resources)
|
|
169
|
+
支持通过 `circuit://` URI 直接将规范加载到大模型上下文,无需执行额外工具:
|
|
170
|
+
- `circuit://specs/netlist-schema`: 完整的网表 Draft-07 JSON Schema。
|
|
171
|
+
- `circuit://specs/cpl-standard`: 嘉立创 SMT 坐标规范与封装偏角补偿表。
|
|
172
|
+
- `circuit://blocks/catalog`: 10 大电路积木的元器件、引脚与网络全量清单。
|
|
173
|
+
- `circuit://rules/jlc-smt`: 嘉立创四层板叠层 (JLC04161H) 与生产物理规则。
|
|
174
|
+
- `circuit://examples/esp32c3-minimal`: ESP32-C3 极简温湿度节点参考网表。
|
|
175
|
+
- `circuit://examples/stm32f103-controller`: STM32F103 工业控制板参考网表。
|
|
176
|
+
- `circuit://examples/rp2040-dualcore`: RP2040 双核传感器扩展板参考网表。
|
|
177
|
+
|
|
178
|
+
### 快捷工程 Prompt (Slash-Commands)
|
|
179
|
+
- `/design_hardware_project`: 全流程硬件设计指令(积木匹配 → 阻抗计算 → BOM核算 → 网表校验)。
|
|
180
|
+
- `/audit_schematic_netlist`: Senior EE 硬件体检审查指令(去耦电容亲和性、差分对等长、Type-C 下拉阻抗)。
|
|
181
|
+
- `/optimize_bom_cost`: PCBA 降本优化指令(分析扩展库物料并推荐免换料费的基础库替代料)。
|
|
182
|
+
|
|
183
|
+
---
|
|
184
|
+
|
|
185
|
+
## 数据契约 (Contracts)
|
|
186
|
+
|
|
187
|
+
- [`specs/netlist_schema.json`](specs/netlist_schema.json) — 网表 JSON Schema
|
|
188
|
+
- [`specs/cpl_standard.md`](specs/cpl_standard.md) — 嘉立创 SMT 坐标规范与封装偏角补偿表
|
|
189
|
+
- [`examples/`](examples/) — STM32F103 / ESP32-C3 / RP2040 参考网表,CI 强制校验其符合 Schema
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 测试与 CI
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
pytest tests/ -q # 120 passed
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
CI 在 `ubuntu-latest` + `windows-latest` × Python 3.10/3.11/3.12 上跑全量测试,
|
|
200
|
+
并额外做两件事:校验 `examples/` 全部符合 Schema、离线跑通 README 里的快速上手命令。
|
|
201
|
+
|
|
202
|
+
---
|
|
203
|
+
|
|
204
|
+
## 范围与路线图 (Scope & Roadmap)
|
|
205
|
+
|
|
206
|
+
**本仓库包含**:硬件 DSL 与积木库、立创实时选型客户端、网表/CPL 数据契约、标准 MCP Server、REST 交互接口。
|
|
207
|
+
|
|
208
|
+
**暂不包含**:多层板物理布局与布线求解、参数化 3D 壳体布尔几何、Senior EE 物理规则门禁。
|
|
209
|
+
这些是上游编译器的高级能力,仍在开发中;本仓库通过稳定的数据契约与客户端接口与其对接,
|
|
210
|
+
契约本身是公开且版本化的。
|
|
211
|
+
|
|
212
|
+
路线图:
|
|
213
|
+
|
|
214
|
+
- [x] 积木库 + 确定性映射 + 单元测试
|
|
215
|
+
- [x] 立创实时选型客户端(重试/缓存/降级)
|
|
216
|
+
- [x] JSON Schema + 三份参考样例 + CI
|
|
217
|
+
- [x] 工业级实用积木(RS485 / CAN / TP4056 锂电)
|
|
218
|
+
- [x] 标准 MCP Server 实现(纯标准库,4 大工具)
|
|
219
|
+
- [x] 中英双语文档与官方门面 (Banner + Demo GIF)
|
|
220
|
+
- [ ] 更多传感器积木(AHT20 温湿度 / MPU6050 六轴)
|
|
221
|
+
- [ ] 支持自定义第三方芯片引脚分配映射规则
|
|
222
|
+
|
|
223
|
+
---
|
|
224
|
+
|
|
225
|
+
## 参与贡献 (Contributing)
|
|
226
|
+
|
|
227
|
+
最欢迎的贡献是**新增经过核验的电路积木**:带上数据手册依据的引脚定义与立创料号,
|
|
228
|
+
并补上对应单测即可提 PR。Issue 里也欢迎贴出你希望支持的芯片型号。
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 名称说明 (Naming)
|
|
233
|
+
|
|
234
|
+
"CircuitAgent" 是一个较通用的名字,社区中已有若干同名或近名的项目(例如
|
|
235
|
+
`singularguy/CircuitManus` 内部的 `CircuitAgent` 类、`Circuit-LLM/circuit-sdk`
|
|
236
|
+
的 `CircuitAgent` 基类、以及高能物理领域的 PhEDEx `CircuitAgent`)。
|
|
237
|
+
本项目与它们**没有任何关系**,也不主张该名称的独占权。如果你的项目或商标与此冲突,
|
|
238
|
+
欢迎开 Issue 告知,我们可以协商改名。
|
|
239
|
+
|
|
240
|
+
## 许可证 (License)
|
|
241
|
+
|
|
242
|
+
[MIT](LICENSE) © 2026 sora
|