wagent-framework 1.4.1__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.
- wagent_framework-1.4.1/LICENSE +21 -0
- wagent_framework-1.4.1/PKG-INFO +319 -0
- wagent_framework-1.4.1/README.md +259 -0
- wagent_framework-1.4.1/setup.cfg +4 -0
- wagent_framework-1.4.1/setup.py +59 -0
- wagent_framework-1.4.1/tests/test.py +8 -0
- wagent_framework-1.4.1/tests/test_aop.py +119 -0
- wagent_framework-1.4.1/tests/test_config.py +107 -0
- wagent_framework-1.4.1/tests/test_container.py +110 -0
- wagent_framework-1.4.1/tests/test_distributed_lock.py +125 -0
- wagent_framework-1.4.1/tests/test_event_bus.py +97 -0
- wagent_framework-1.4.1/tests/test_lifecycle.py +136 -0
- wagent_framework-1.4.1/tests/test_sandbox.py +70 -0
- wagent_framework-1.4.1/tests/test_scanner.py +88 -0
- wagent_framework-1.4.1/w_agent/__init__.py +50 -0
- wagent_framework-1.4.1/w_agent/__main__.py +41 -0
- wagent_framework-1.4.1/w_agent/aop/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/aop/aspects.py +156 -0
- wagent_framework-1.4.1/w_agent/aop/joinpoint.py +38 -0
- wagent_framework-1.4.1/w_agent/aop/pointcut.py +212 -0
- wagent_framework-1.4.1/w_agent/aop/proxy_factory.py +64 -0
- wagent_framework-1.4.1/w_agent/cli.py +108 -0
- wagent_framework-1.4.1/w_agent/config/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/config/dynamic_config.py +50 -0
- wagent_framework-1.4.1/w_agent/container/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/container/bean_factory.py +387 -0
- wagent_framework-1.4.1/w_agent/container/reflection_cache.py +55 -0
- wagent_framework-1.4.1/w_agent/core/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/core/agent.py +7 -0
- wagent_framework-1.4.1/w_agent/core/decorators.py +121 -0
- wagent_framework-1.4.1/w_agent/core/doctor.py +137 -0
- wagent_framework-1.4.1/w_agent/core/event_bus.py +61 -0
- wagent_framework-1.4.1/w_agent/deployment/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/deployment/fastapi_depends.py +99 -0
- wagent_framework-1.4.1/w_agent/distributed/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/distributed/lock.py +63 -0
- wagent_framework-1.4.1/w_agent/distributed/lock_pool.py +45 -0
- wagent_framework-1.4.1/w_agent/exceptions/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/exceptions/framework_errors.py +30 -0
- wagent_framework-1.4.1/w_agent/lifecycle/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/lifecycle/graceful_shutdown.py +45 -0
- wagent_framework-1.4.1/w_agent/lifecycle/manager.py +44 -0
- wagent_framework-1.4.1/w_agent/lifecycle/order.py +10 -0
- wagent_framework-1.4.1/w_agent/migration/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/migration/migrate_previous.py +76 -0
- wagent_framework-1.4.1/w_agent/observability/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/observability/health.py +38 -0
- wagent_framework-1.4.1/w_agent/observability/logging.py +74 -0
- wagent_framework-1.4.1/w_agent/observability/metrics.py +98 -0
- wagent_framework-1.4.1/w_agent/observability/tracing.py +58 -0
- wagent_framework-1.4.1/w_agent/resilience/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/resilience/bulkhead.py +92 -0
- wagent_framework-1.4.1/w_agent/resilience/timeout.py +17 -0
- wagent_framework-1.4.1/w_agent/scanner/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/scanner/cache.py +31 -0
- wagent_framework-1.4.1/w_agent/scanner/parallel_scanner.py +168 -0
- wagent_framework-1.4.1/w_agent/security/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/security/mcp_auth.py +133 -0
- wagent_framework-1.4.1/w_agent/skills/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/skills/sandbox/__init__.py +9 -0
- wagent_framework-1.4.1/w_agent/skills/sandbox/nsjail_sandbox.py +151 -0
- wagent_framework-1.4.1/w_agent/skills/sandbox/wasm_sandbox.py +234 -0
- wagent_framework-1.4.1/w_agent/skills/signature.py +23 -0
- wagent_framework-1.4.1/w_agent/skills/skill.py +187 -0
- wagent_framework-1.4.1/w_agent/testing/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/testing/mock_utils.py +23 -0
- wagent_framework-1.4.1/w_agent/tools/__init__.py +0 -0
- wagent_framework-1.4.1/w_agent/tools/langchain_adapter.py +112 -0
- wagent_framework-1.4.1/wagent_framework.egg-info/PKG-INFO +319 -0
- wagent_framework-1.4.1/wagent_framework.egg-info/SOURCES.txt +72 -0
- wagent_framework-1.4.1/wagent_framework.egg-info/dependency_links.txt +1 -0
- wagent_framework-1.4.1/wagent_framework.egg-info/entry_points.txt +2 -0
- wagent_framework-1.4.1/wagent_framework.egg-info/requires.txt +27 -0
- wagent_framework-1.4.1/wagent_framework.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LuckyStar2456
|
|
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,319 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wagent-framework
|
|
3
|
+
Version: 1.4.1
|
|
4
|
+
Summary: Python enterprise agent framework with AOP, IOC, and sandbox security
|
|
5
|
+
Home-page: https://github.com/LuckyStar2456/W-Agent-FrameWork
|
|
6
|
+
Author: LuckyStar2456
|
|
7
|
+
Author-email: lucky_star_2456@example.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Bug Reports, https://github.com/LuckyStar2456/W-Agent-FrameWork/issues
|
|
10
|
+
Project-URL: Source, https://github.com/LuckyStar2456/W-Agent-FrameWork
|
|
11
|
+
Keywords: agent framework AOP IOC sandbox
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Requires-Dist: pydantic
|
|
25
|
+
Requires-Dist: structlog
|
|
26
|
+
Requires-Dist: cryptography
|
|
27
|
+
Requires-Dist: msgpack
|
|
28
|
+
Requires-Dist: zstandard
|
|
29
|
+
Requires-Dist: pyjwt
|
|
30
|
+
Requires-Dist: asgiref
|
|
31
|
+
Requires-Dist: redis
|
|
32
|
+
Provides-Extra: fastapi
|
|
33
|
+
Requires-Dist: fastapi; extra == "fastapi"
|
|
34
|
+
Requires-Dist: uvicorn; extra == "fastapi"
|
|
35
|
+
Provides-Extra: langchain
|
|
36
|
+
Requires-Dist: langchain; extra == "langchain"
|
|
37
|
+
Provides-Extra: wasm
|
|
38
|
+
Requires-Dist: wasmer; extra == "wasm"
|
|
39
|
+
Provides-Extra: opentelemetry
|
|
40
|
+
Requires-Dist: opentelemetry-api; extra == "opentelemetry"
|
|
41
|
+
Requires-Dist: opentelemetry-sdk; extra == "opentelemetry"
|
|
42
|
+
Requires-Dist: opentelemetry-exporter-otlp; extra == "opentelemetry"
|
|
43
|
+
Provides-Extra: testing
|
|
44
|
+
Requires-Dist: pytest; extra == "testing"
|
|
45
|
+
Requires-Dist: pytest-asyncio; extra == "testing"
|
|
46
|
+
Dynamic: author
|
|
47
|
+
Dynamic: author-email
|
|
48
|
+
Dynamic: classifier
|
|
49
|
+
Dynamic: description
|
|
50
|
+
Dynamic: description-content-type
|
|
51
|
+
Dynamic: home-page
|
|
52
|
+
Dynamic: keywords
|
|
53
|
+
Dynamic: license
|
|
54
|
+
Dynamic: license-file
|
|
55
|
+
Dynamic: project-url
|
|
56
|
+
Dynamic: provides-extra
|
|
57
|
+
Dynamic: requires-dist
|
|
58
|
+
Dynamic: requires-python
|
|
59
|
+
Dynamic: summary
|
|
60
|
+
|
|
61
|
+
# W-Agent v1.4.0
|
|
62
|
+
|
|
63
|
+
[English](./README_EN.md) | 简体中文
|
|
64
|
+
|
|
65
|
+
Python 企业级智能体框架,完整技术架构方案。
|
|
66
|
+
|
|
67
|
+
[](https://www.python.org/)
|
|
68
|
+
[](LICENSE)
|
|
69
|
+
[](https://github.com/LuckyStar2456/W-Agent-FrameWork)
|
|
70
|
+
|
|
71
|
+
## 📚 目录
|
|
72
|
+
|
|
73
|
+
- [功能特性](#-功能特性)
|
|
74
|
+
- [快速开始](#-快速开始)
|
|
75
|
+
- [项目结构](#-项目结构)
|
|
76
|
+
- [核心模块](#-核心模块)
|
|
77
|
+
- [配置指南](#-配置指南)
|
|
78
|
+
- [示例项目](#-示例项目)
|
|
79
|
+
- [文档](#-文档)
|
|
80
|
+
- [贡献指南](#-贡献指南)
|
|
81
|
+
- [许可证](#-许可证)
|
|
82
|
+
|
|
83
|
+
## ✨ 功能特性
|
|
84
|
+
|
|
85
|
+
| 特性 | 描述 |
|
|
86
|
+
|------|------|
|
|
87
|
+
| **AOP 面向切面编程** | 支持 AspectJ 切点表达式(execution、within、@annotation、bean、args) |
|
|
88
|
+
| **IOC 依赖注入** | 三级缓存、构造器/字段/setter 注入、@Autowired/@Qualifier 注解 |
|
|
89
|
+
| **沙箱安全** | Wasm/nsjail 沙箱、seccomp 过滤、资源限制 |
|
|
90
|
+
| **弹性模式** | 重试(带退避)、断路器(CLOSED/OPEN/HALF_OPEN 状态) |
|
|
91
|
+
| **可观测性** | OpenTelemetry 集成、链路追踪、指标监控 |
|
|
92
|
+
| **RAG 集成** | 向量检索(Redis/内存)、相似度搜索 |
|
|
93
|
+
| **配置热更新** | 动态配置管理、配置变更事件 |
|
|
94
|
+
|
|
95
|
+
## 🚀 快速开始
|
|
96
|
+
|
|
97
|
+
### 安装
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
# 从 PyPI 安装
|
|
101
|
+
pip install wagent-framework
|
|
102
|
+
|
|
103
|
+
# 安装可选依赖
|
|
104
|
+
pip install wagent-framework[fastapi,langchain,redis,opentelemetry]
|
|
105
|
+
|
|
106
|
+
# 从源码安装
|
|
107
|
+
pip install -e .
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### 创建你的第一个 Agent
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
import asyncio
|
|
114
|
+
from w_agent.core.agent import BaseAgent
|
|
115
|
+
from w_agent.container.bean_factory import BeanFactory
|
|
116
|
+
from w_agent.core.decorators import AgentComponent
|
|
117
|
+
|
|
118
|
+
@AgentComponent(name="hello_agent")
|
|
119
|
+
class HelloAgent(BaseAgent):
|
|
120
|
+
async def arun(self, prompt: str) -> str:
|
|
121
|
+
return f"Hello, {prompt}!"
|
|
122
|
+
|
|
123
|
+
async def main():
|
|
124
|
+
# 创建 Bean 工厂
|
|
125
|
+
bean_factory = BeanFactory()
|
|
126
|
+
|
|
127
|
+
# 注册 Agent
|
|
128
|
+
agent = HelloAgent()
|
|
129
|
+
bean_factory.register_bean("hello_agent", agent)
|
|
130
|
+
|
|
131
|
+
# 使用 Agent
|
|
132
|
+
agent = await bean_factory.get_bean("hello_agent")
|
|
133
|
+
result = await agent.arun("World")
|
|
134
|
+
print(result) # 输出: Hello, World!
|
|
135
|
+
|
|
136
|
+
asyncio.run(main())
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### 使用配置热更新
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
import asyncio
|
|
143
|
+
from w_agent.config.dynamic_config import DynamicConfigManager
|
|
144
|
+
|
|
145
|
+
async def main():
|
|
146
|
+
config_manager = DynamicConfigManager()
|
|
147
|
+
|
|
148
|
+
# 设置配置
|
|
149
|
+
config_manager.set("api_key", "your-api-key")
|
|
150
|
+
|
|
151
|
+
# 绑定配置到属性
|
|
152
|
+
class MyService:
|
|
153
|
+
def __init__(self):
|
|
154
|
+
self.api_key = None
|
|
155
|
+
config_manager.bind("api_key", self, "api_key")
|
|
156
|
+
|
|
157
|
+
async def on_config_change(self, key, new_value, old_value):
|
|
158
|
+
print(f"Config changed: {key} = {new_value}")
|
|
159
|
+
|
|
160
|
+
service = MyService()
|
|
161
|
+
print(service.api_key) # 输出: your-api-key
|
|
162
|
+
|
|
163
|
+
# 动态更新配置
|
|
164
|
+
await config_manager.update_batch({"api_key": "new-api-key"})
|
|
165
|
+
print(service.api_key) # 输出: new-api-key
|
|
166
|
+
|
|
167
|
+
asyncio.run(main())
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## 📁 项目结构
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
w_agent/
|
|
174
|
+
├── aop/ # 面向切面编程
|
|
175
|
+
│ ├── aspects.py # 切面实现(重试、断路器)
|
|
176
|
+
│ ├── joinpoint.py # 连接点
|
|
177
|
+
│ ├── pointcut.py # 切点表达式解析
|
|
178
|
+
│ └── proxy_factory.py # 代理工厂
|
|
179
|
+
├── config/ # 配置管理
|
|
180
|
+
│ └── dynamic_config.py # 动态配置
|
|
181
|
+
├── container/ # 依赖注入容器
|
|
182
|
+
│ ├── bean_factory.py # Bean 工厂
|
|
183
|
+
│ └── reflection_cache.py # 反射缓存
|
|
184
|
+
├── core/ # 核心功能
|
|
185
|
+
│ ├── agent.py # Agent 基类
|
|
186
|
+
│ ├── event_bus.py # 事件总线
|
|
187
|
+
│ └── decorators.py # 装饰器
|
|
188
|
+
├── observability/ # 可观测性
|
|
189
|
+
│ ├── tracing.py # 链路追踪
|
|
190
|
+
│ ├── metrics.py # 指标监控
|
|
191
|
+
│ └── health.py # 健康检查
|
|
192
|
+
├── skills/ # 技能系统
|
|
193
|
+
│ └── sandbox/ # 沙箱
|
|
194
|
+
│ ├── wasm_sandbox.py
|
|
195
|
+
│ └── nsjail_sandbox.py
|
|
196
|
+
└── ...
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
## 🔧 核心模块
|
|
200
|
+
|
|
201
|
+
### AOP 切面编程
|
|
202
|
+
|
|
203
|
+
```python
|
|
204
|
+
from w_agent.core.decorators import Retry, CircuitBreaker
|
|
205
|
+
from w_agent.aop.pointcut import AspectJPointcut
|
|
206
|
+
|
|
207
|
+
# 使用重试装饰器
|
|
208
|
+
@Retry(max_attempts=3, delay=0.1, backoff=2.0)
|
|
209
|
+
async def unreliable_operation():
|
|
210
|
+
pass
|
|
211
|
+
|
|
212
|
+
# 使用断路器
|
|
213
|
+
@CircuitBreaker(failure_threshold=5, recovery_timeout=30.0)
|
|
214
|
+
async def protected_operation():
|
|
215
|
+
pass
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### 依赖注入
|
|
219
|
+
|
|
220
|
+
```python
|
|
221
|
+
from w_agent.core.decorators import Autowired, Qualifier, ServiceComponent
|
|
222
|
+
|
|
223
|
+
@ServiceComponent(name="user_service")
|
|
224
|
+
class UserService:
|
|
225
|
+
@Qualifier(name="redis_client")
|
|
226
|
+
def set_cache(self, cache_client):
|
|
227
|
+
self.cache = cache_client
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### 事件总线
|
|
231
|
+
|
|
232
|
+
```python
|
|
233
|
+
from w_agent.core.event_bus import EventBus, Event
|
|
234
|
+
|
|
235
|
+
event_bus = EventBus()
|
|
236
|
+
|
|
237
|
+
@event_bus.on("user.created")
|
|
238
|
+
async def on_user_created(event):
|
|
239
|
+
print(f"User created: {event.payload}")
|
|
240
|
+
|
|
241
|
+
await event_bus.emit(Event("user.created", {"user_id": 123}))
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## ⚙️ 配置指南
|
|
245
|
+
|
|
246
|
+
### 可配置项一览
|
|
247
|
+
|
|
248
|
+
| 配置项 | 类型 | 默认值 | 描述 |
|
|
249
|
+
|--------|------|--------|------|
|
|
250
|
+
| `logging.level` | string | "INFO" | 日志级别 |
|
|
251
|
+
| `container.scan_paths` | list | ["."] | 组件扫描路径 |
|
|
252
|
+
| `sandbox.enabled` | bool | true | 是否启用沙箱 |
|
|
253
|
+
| `resilience.retry.max_attempts` | int | 3 | 最大重试次数 |
|
|
254
|
+
| `distributed.lock.redis.url` | string | "redis://localhost:6379" | Redis 连接 URL |
|
|
255
|
+
|
|
256
|
+
### 配置文件
|
|
257
|
+
|
|
258
|
+
创建 `config.json`:
|
|
259
|
+
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"logging": {
|
|
263
|
+
"level": "INFO",
|
|
264
|
+
"format": "json"
|
|
265
|
+
},
|
|
266
|
+
"container": {
|
|
267
|
+
"scan_paths": ["src"],
|
|
268
|
+
"skip_paths": ["__pycache__", ".git"]
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### 环境变量
|
|
274
|
+
|
|
275
|
+
```bash
|
|
276
|
+
export W_AGENT_LOGGING_LEVEL=DEBUG
|
|
277
|
+
export W_AGENT_CONTAINER_SCAN_PATHS=src,components
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## 📖 示例项目
|
|
281
|
+
|
|
282
|
+
查看 [chat-agent](./chat-agent/) 目录获取完整的聊天智能体示例项目,包含:
|
|
283
|
+
|
|
284
|
+
- Agent 实现
|
|
285
|
+
- Skill 系统
|
|
286
|
+
- RAG 检索增强
|
|
287
|
+
- Redis/MySQL 集成
|
|
288
|
+
- OpenTelemetry 可观测性
|
|
289
|
+
|
|
290
|
+
## 📄 文档
|
|
291
|
+
|
|
292
|
+
- [架构设计文档](./docs/architecture.md)
|
|
293
|
+
- [API 文档](./docs/api.md)
|
|
294
|
+
- [使用指南](./docs/guide.md)
|
|
295
|
+
|
|
296
|
+
## 🤝 贡献指南
|
|
297
|
+
|
|
298
|
+
欢迎提交 Issue 和 Pull Request!
|
|
299
|
+
|
|
300
|
+
1. Fork 本仓库
|
|
301
|
+
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
|
|
302
|
+
3. 提交更改 (`git commit -m 'Add amazing feature'`)
|
|
303
|
+
4. 推送分支 (`git push origin feature/amazing-feature`)
|
|
304
|
+
5. 创建 Pull Request
|
|
305
|
+
|
|
306
|
+
## 📄 许可证
|
|
307
|
+
|
|
308
|
+
本项目采用 [MIT 许可证](LICENSE)。
|
|
309
|
+
|
|
310
|
+
---
|
|
311
|
+
|
|
312
|
+
如果这个项目对你有帮助,请给我们一个 ⭐!
|
|
313
|
+
|
|
314
|
+
## 📦 PyPI 包
|
|
315
|
+
|
|
316
|
+
- **包名**: `wagent-framework`
|
|
317
|
+
- **版本**: 1.4.0
|
|
318
|
+
- **安装**: `pip install wagent-framework`
|
|
319
|
+
- **PyPI 地址**: [https://pypi.org/project/wagent-framework/](https://pypi.org/project/wagent-framework/)
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
# W-Agent v1.4.0
|
|
2
|
+
|
|
3
|
+
[English](./README_EN.md) | 简体中文
|
|
4
|
+
|
|
5
|
+
Python 企业级智能体框架,完整技术架构方案。
|
|
6
|
+
|
|
7
|
+
[](https://www.python.org/)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+
[](https://github.com/LuckyStar2456/W-Agent-FrameWork)
|
|
10
|
+
|
|
11
|
+
## 📚 目录
|
|
12
|
+
|
|
13
|
+
- [功能特性](#-功能特性)
|
|
14
|
+
- [快速开始](#-快速开始)
|
|
15
|
+
- [项目结构](#-项目结构)
|
|
16
|
+
- [核心模块](#-核心模块)
|
|
17
|
+
- [配置指南](#-配置指南)
|
|
18
|
+
- [示例项目](#-示例项目)
|
|
19
|
+
- [文档](#-文档)
|
|
20
|
+
- [贡献指南](#-贡献指南)
|
|
21
|
+
- [许可证](#-许可证)
|
|
22
|
+
|
|
23
|
+
## ✨ 功能特性
|
|
24
|
+
|
|
25
|
+
| 特性 | 描述 |
|
|
26
|
+
|------|------|
|
|
27
|
+
| **AOP 面向切面编程** | 支持 AspectJ 切点表达式(execution、within、@annotation、bean、args) |
|
|
28
|
+
| **IOC 依赖注入** | 三级缓存、构造器/字段/setter 注入、@Autowired/@Qualifier 注解 |
|
|
29
|
+
| **沙箱安全** | Wasm/nsjail 沙箱、seccomp 过滤、资源限制 |
|
|
30
|
+
| **弹性模式** | 重试(带退避)、断路器(CLOSED/OPEN/HALF_OPEN 状态) |
|
|
31
|
+
| **可观测性** | OpenTelemetry 集成、链路追踪、指标监控 |
|
|
32
|
+
| **RAG 集成** | 向量检索(Redis/内存)、相似度搜索 |
|
|
33
|
+
| **配置热更新** | 动态配置管理、配置变更事件 |
|
|
34
|
+
|
|
35
|
+
## 🚀 快速开始
|
|
36
|
+
|
|
37
|
+
### 安装
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# 从 PyPI 安装
|
|
41
|
+
pip install wagent-framework
|
|
42
|
+
|
|
43
|
+
# 安装可选依赖
|
|
44
|
+
pip install wagent-framework[fastapi,langchain,redis,opentelemetry]
|
|
45
|
+
|
|
46
|
+
# 从源码安装
|
|
47
|
+
pip install -e .
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### 创建你的第一个 Agent
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio
|
|
54
|
+
from w_agent.core.agent import BaseAgent
|
|
55
|
+
from w_agent.container.bean_factory import BeanFactory
|
|
56
|
+
from w_agent.core.decorators import AgentComponent
|
|
57
|
+
|
|
58
|
+
@AgentComponent(name="hello_agent")
|
|
59
|
+
class HelloAgent(BaseAgent):
|
|
60
|
+
async def arun(self, prompt: str) -> str:
|
|
61
|
+
return f"Hello, {prompt}!"
|
|
62
|
+
|
|
63
|
+
async def main():
|
|
64
|
+
# 创建 Bean 工厂
|
|
65
|
+
bean_factory = BeanFactory()
|
|
66
|
+
|
|
67
|
+
# 注册 Agent
|
|
68
|
+
agent = HelloAgent()
|
|
69
|
+
bean_factory.register_bean("hello_agent", agent)
|
|
70
|
+
|
|
71
|
+
# 使用 Agent
|
|
72
|
+
agent = await bean_factory.get_bean("hello_agent")
|
|
73
|
+
result = await agent.arun("World")
|
|
74
|
+
print(result) # 输出: Hello, World!
|
|
75
|
+
|
|
76
|
+
asyncio.run(main())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 使用配置热更新
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
import asyncio
|
|
83
|
+
from w_agent.config.dynamic_config import DynamicConfigManager
|
|
84
|
+
|
|
85
|
+
async def main():
|
|
86
|
+
config_manager = DynamicConfigManager()
|
|
87
|
+
|
|
88
|
+
# 设置配置
|
|
89
|
+
config_manager.set("api_key", "your-api-key")
|
|
90
|
+
|
|
91
|
+
# 绑定配置到属性
|
|
92
|
+
class MyService:
|
|
93
|
+
def __init__(self):
|
|
94
|
+
self.api_key = None
|
|
95
|
+
config_manager.bind("api_key", self, "api_key")
|
|
96
|
+
|
|
97
|
+
async def on_config_change(self, key, new_value, old_value):
|
|
98
|
+
print(f"Config changed: {key} = {new_value}")
|
|
99
|
+
|
|
100
|
+
service = MyService()
|
|
101
|
+
print(service.api_key) # 输出: your-api-key
|
|
102
|
+
|
|
103
|
+
# 动态更新配置
|
|
104
|
+
await config_manager.update_batch({"api_key": "new-api-key"})
|
|
105
|
+
print(service.api_key) # 输出: new-api-key
|
|
106
|
+
|
|
107
|
+
asyncio.run(main())
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📁 项目结构
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
w_agent/
|
|
114
|
+
├── aop/ # 面向切面编程
|
|
115
|
+
│ ├── aspects.py # 切面实现(重试、断路器)
|
|
116
|
+
│ ├── joinpoint.py # 连接点
|
|
117
|
+
│ ├── pointcut.py # 切点表达式解析
|
|
118
|
+
│ └── proxy_factory.py # 代理工厂
|
|
119
|
+
├── config/ # 配置管理
|
|
120
|
+
│ └── dynamic_config.py # 动态配置
|
|
121
|
+
├── container/ # 依赖注入容器
|
|
122
|
+
│ ├── bean_factory.py # Bean 工厂
|
|
123
|
+
│ └── reflection_cache.py # 反射缓存
|
|
124
|
+
├── core/ # 核心功能
|
|
125
|
+
│ ├── agent.py # Agent 基类
|
|
126
|
+
│ ├── event_bus.py # 事件总线
|
|
127
|
+
│ └── decorators.py # 装饰器
|
|
128
|
+
├── observability/ # 可观测性
|
|
129
|
+
│ ├── tracing.py # 链路追踪
|
|
130
|
+
│ ├── metrics.py # 指标监控
|
|
131
|
+
│ └── health.py # 健康检查
|
|
132
|
+
├── skills/ # 技能系统
|
|
133
|
+
│ └── sandbox/ # 沙箱
|
|
134
|
+
│ ├── wasm_sandbox.py
|
|
135
|
+
│ └── nsjail_sandbox.py
|
|
136
|
+
└── ...
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
## 🔧 核心模块
|
|
140
|
+
|
|
141
|
+
### AOP 切面编程
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from w_agent.core.decorators import Retry, CircuitBreaker
|
|
145
|
+
from w_agent.aop.pointcut import AspectJPointcut
|
|
146
|
+
|
|
147
|
+
# 使用重试装饰器
|
|
148
|
+
@Retry(max_attempts=3, delay=0.1, backoff=2.0)
|
|
149
|
+
async def unreliable_operation():
|
|
150
|
+
pass
|
|
151
|
+
|
|
152
|
+
# 使用断路器
|
|
153
|
+
@CircuitBreaker(failure_threshold=5, recovery_timeout=30.0)
|
|
154
|
+
async def protected_operation():
|
|
155
|
+
pass
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
### 依赖注入
|
|
159
|
+
|
|
160
|
+
```python
|
|
161
|
+
from w_agent.core.decorators import Autowired, Qualifier, ServiceComponent
|
|
162
|
+
|
|
163
|
+
@ServiceComponent(name="user_service")
|
|
164
|
+
class UserService:
|
|
165
|
+
@Qualifier(name="redis_client")
|
|
166
|
+
def set_cache(self, cache_client):
|
|
167
|
+
self.cache = cache_client
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 事件总线
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from w_agent.core.event_bus import EventBus, Event
|
|
174
|
+
|
|
175
|
+
event_bus = EventBus()
|
|
176
|
+
|
|
177
|
+
@event_bus.on("user.created")
|
|
178
|
+
async def on_user_created(event):
|
|
179
|
+
print(f"User created: {event.payload}")
|
|
180
|
+
|
|
181
|
+
await event_bus.emit(Event("user.created", {"user_id": 123}))
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## ⚙️ 配置指南
|
|
185
|
+
|
|
186
|
+
### 可配置项一览
|
|
187
|
+
|
|
188
|
+
| 配置项 | 类型 | 默认值 | 描述 |
|
|
189
|
+
|--------|------|--------|------|
|
|
190
|
+
| `logging.level` | string | "INFO" | 日志级别 |
|
|
191
|
+
| `container.scan_paths` | list | ["."] | 组件扫描路径 |
|
|
192
|
+
| `sandbox.enabled` | bool | true | 是否启用沙箱 |
|
|
193
|
+
| `resilience.retry.max_attempts` | int | 3 | 最大重试次数 |
|
|
194
|
+
| `distributed.lock.redis.url` | string | "redis://localhost:6379" | Redis 连接 URL |
|
|
195
|
+
|
|
196
|
+
### 配置文件
|
|
197
|
+
|
|
198
|
+
创建 `config.json`:
|
|
199
|
+
|
|
200
|
+
```json
|
|
201
|
+
{
|
|
202
|
+
"logging": {
|
|
203
|
+
"level": "INFO",
|
|
204
|
+
"format": "json"
|
|
205
|
+
},
|
|
206
|
+
"container": {
|
|
207
|
+
"scan_paths": ["src"],
|
|
208
|
+
"skip_paths": ["__pycache__", ".git"]
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
### 环境变量
|
|
214
|
+
|
|
215
|
+
```bash
|
|
216
|
+
export W_AGENT_LOGGING_LEVEL=DEBUG
|
|
217
|
+
export W_AGENT_CONTAINER_SCAN_PATHS=src,components
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## 📖 示例项目
|
|
221
|
+
|
|
222
|
+
查看 [chat-agent](./chat-agent/) 目录获取完整的聊天智能体示例项目,包含:
|
|
223
|
+
|
|
224
|
+
- Agent 实现
|
|
225
|
+
- Skill 系统
|
|
226
|
+
- RAG 检索增强
|
|
227
|
+
- Redis/MySQL 集成
|
|
228
|
+
- OpenTelemetry 可观测性
|
|
229
|
+
|
|
230
|
+
## 📄 文档
|
|
231
|
+
|
|
232
|
+
- [架构设计文档](./docs/architecture.md)
|
|
233
|
+
- [API 文档](./docs/api.md)
|
|
234
|
+
- [使用指南](./docs/guide.md)
|
|
235
|
+
|
|
236
|
+
## 🤝 贡献指南
|
|
237
|
+
|
|
238
|
+
欢迎提交 Issue 和 Pull Request!
|
|
239
|
+
|
|
240
|
+
1. Fork 本仓库
|
|
241
|
+
2. 创建特性分支 (`git checkout -b feature/amazing-feature`)
|
|
242
|
+
3. 提交更改 (`git commit -m 'Add amazing feature'`)
|
|
243
|
+
4. 推送分支 (`git push origin feature/amazing-feature`)
|
|
244
|
+
5. 创建 Pull Request
|
|
245
|
+
|
|
246
|
+
## 📄 许可证
|
|
247
|
+
|
|
248
|
+
本项目采用 [MIT 许可证](LICENSE)。
|
|
249
|
+
|
|
250
|
+
---
|
|
251
|
+
|
|
252
|
+
如果这个项目对你有帮助,请给我们一个 ⭐!
|
|
253
|
+
|
|
254
|
+
## 📦 PyPI 包
|
|
255
|
+
|
|
256
|
+
- **包名**: `wagent-framework`
|
|
257
|
+
- **版本**: 1.4.0
|
|
258
|
+
- **安装**: `pip install wagent-framework`
|
|
259
|
+
- **PyPI 地址**: [https://pypi.org/project/wagent-framework/](https://pypi.org/project/wagent-framework/)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
from setuptools import setup, find_packages
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
# 读取README.md作为长描述
|
|
5
|
+
here = os.path.abspath(os.path.dirname(__file__))
|
|
6
|
+
with open(os.path.join(here, 'README.md'), 'r', encoding='utf-8') as f:
|
|
7
|
+
long_description = f.read()
|
|
8
|
+
|
|
9
|
+
setup(
|
|
10
|
+
name="wagent-framework",
|
|
11
|
+
version="1.4.1",
|
|
12
|
+
description="Python enterprise agent framework with AOP, IOC, and sandbox security",
|
|
13
|
+
long_description=long_description,
|
|
14
|
+
long_description_content_type="text/markdown",
|
|
15
|
+
url="https://github.com/LuckyStar2456/W-Agent-FrameWork",
|
|
16
|
+
author="LuckyStar2456",
|
|
17
|
+
author_email="lucky_star_2456@example.com",
|
|
18
|
+
license="MIT",
|
|
19
|
+
packages=find_packages(),
|
|
20
|
+
install_requires=[
|
|
21
|
+
"pydantic",
|
|
22
|
+
"structlog",
|
|
23
|
+
"cryptography",
|
|
24
|
+
"msgpack",
|
|
25
|
+
"zstandard",
|
|
26
|
+
"pyjwt",
|
|
27
|
+
"asgiref",
|
|
28
|
+
"redis"
|
|
29
|
+
],
|
|
30
|
+
extras_require={
|
|
31
|
+
"fastapi": ["fastapi", "uvicorn"],
|
|
32
|
+
"langchain": ["langchain"],
|
|
33
|
+
"wasm": ["wasmer"],
|
|
34
|
+
"opentelemetry": ["opentelemetry-api", "opentelemetry-sdk", "opentelemetry-exporter-otlp"],
|
|
35
|
+
"testing": ["pytest", "pytest-asyncio"]
|
|
36
|
+
},
|
|
37
|
+
entry_points={
|
|
38
|
+
"console_scripts": [
|
|
39
|
+
"w-agent=w_agent.cli:main"
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
classifiers=[
|
|
43
|
+
"Development Status :: 4 - Beta",
|
|
44
|
+
"Intended Audience :: Developers",
|
|
45
|
+
"License :: OSI Approved :: MIT License",
|
|
46
|
+
"Programming Language :: Python :: 3.9",
|
|
47
|
+
"Programming Language :: Python :: 3.10",
|
|
48
|
+
"Programming Language :: Python :: 3.11",
|
|
49
|
+
"Programming Language :: Python :: 3.12",
|
|
50
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
51
|
+
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
52
|
+
],
|
|
53
|
+
python_requires=">=3.9",
|
|
54
|
+
keywords="agent framework AOP IOC sandbox",
|
|
55
|
+
project_urls={
|
|
56
|
+
"Bug Reports": "https://github.com/LuckyStar2456/W-Agent-FrameWork/issues",
|
|
57
|
+
"Source": "https://github.com/LuckyStar2456/W-Agent-FrameWork",
|
|
58
|
+
},
|
|
59
|
+
)
|