air-agent 0.1.0__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.
- air_agent-0.1.0/.claude/settings.local.json +11 -0
- air_agent-0.1.0/.gitignore +26 -0
- air_agent-0.1.0/LICENSE +21 -0
- air_agent-0.1.0/PKG-INFO +9 -0
- air_agent-0.1.0/README.md +205 -0
- air_agent-0.1.0/docs/superpowers/plans/2026-04-29-vibe-agent-implementation.md +1432 -0
- air_agent-0.1.0/docs/superpowers/specs/2026-04-29-vibe-agent-design.md +186 -0
- air_agent-0.1.0/pyproject.toml +25 -0
- air_agent-0.1.0/src/air_agent/__init__.py +16 -0
- air_agent-0.1.0/src/air_agent/agent.py +267 -0
- air_agent-0.1.0/src/air_agent/config.py +98 -0
- air_agent-0.1.0/src/air_agent/mcp/__init__.py +1 -0
- air_agent-0.1.0/src/air_agent/mcp/client.py +81 -0
- air_agent-0.1.0/src/air_agent/mcp/tool_adapter.py +14 -0
- air_agent-0.1.0/src/air_agent/subagent.py +42 -0
- air_agent-0.1.0/src/air_agent/tools/__init__.py +1 -0
- air_agent-0.1.0/src/air_agent/tools/base.py +13 -0
- air_agent-0.1.0/src/air_agent/tools/registry.py +106 -0
- air_agent-0.1.0/src/air_agent/types.py +46 -0
- air_agent-0.1.0/tests/conftest.py +1 -0
- air_agent-0.1.0/tests/test_agent.py +134 -0
- air_agent-0.1.0/tests/test_config.py +159 -0
- air_agent-0.1.0/tests/test_mcp_adapter.py +28 -0
- air_agent-0.1.0/tests/test_streaming.py +64 -0
- air_agent-0.1.0/tests/test_subagent.py +55 -0
- air_agent-0.1.0/tests/test_tools.py +95 -0
- air_agent-0.1.0/tests/test_types.py +36 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.egg-info/
|
|
5
|
+
*.egg
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.eggs/
|
|
9
|
+
*.whl
|
|
10
|
+
|
|
11
|
+
.venv/
|
|
12
|
+
venv/
|
|
13
|
+
env/
|
|
14
|
+
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.coverage
|
|
17
|
+
htmlcov/
|
|
18
|
+
.mypy_cache/
|
|
19
|
+
.ruff_cache/
|
|
20
|
+
|
|
21
|
+
.uv/
|
|
22
|
+
uv.lock
|
|
23
|
+
|
|
24
|
+
*.log
|
|
25
|
+
.DS_Store
|
|
26
|
+
.env
|
air_agent-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 chldu2000
|
|
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.
|
air_agent-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: air-agent
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Lightweight Python AI agent with OpenAI tool calling, MCP support, and parallel subagents
|
|
5
|
+
License-File: LICENSE
|
|
6
|
+
Requires-Python: >=3.11
|
|
7
|
+
Requires-Dist: mcp>=1.0
|
|
8
|
+
Requires-Dist: openai>=1.30
|
|
9
|
+
Requires-Dist: pydantic>=2.0
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
# vibe-agent
|
|
2
|
+
|
|
3
|
+
轻量级 Python AI Agent 库。基于 OpenAI Chat Completions API,支持工具调用循环、MCP Server 连接、并行 Subagent 和流式输出。设计为可被其他 Python 项目直接引用。
|
|
4
|
+
|
|
5
|
+
## 安装
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv add vibe-agent
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
或开发模式:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
git clone https://github.com/chldu2000/vibe-agent.git
|
|
15
|
+
cd vibe-agent
|
|
16
|
+
uv sync --group dev
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## 快速开始
|
|
20
|
+
|
|
21
|
+
### 基础对话
|
|
22
|
+
|
|
23
|
+
```python
|
|
24
|
+
import asyncio
|
|
25
|
+
from vibe_agent import Agent, AgentConfig
|
|
26
|
+
|
|
27
|
+
async def main():
|
|
28
|
+
agent = Agent(AgentConfig(model="gpt-4o"))
|
|
29
|
+
response = await agent.run("用一句话解释量子计算")
|
|
30
|
+
print(response.content)
|
|
31
|
+
|
|
32
|
+
asyncio.run(main())
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### 注册本地工具
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
agent = Agent(AgentConfig(model="gpt-4o", api_key="sk-xxx"))
|
|
39
|
+
|
|
40
|
+
@agent.tool(name="add", description="计算两个数的和")
|
|
41
|
+
async def add(a: int, b: int) -> int:
|
|
42
|
+
return a + b
|
|
43
|
+
|
|
44
|
+
response = await agent.run("3 加 5 等于多少?")
|
|
45
|
+
# Agent 会自动调用 add 工具并返回结果
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
参数类型从函数签名自动推导,生成 OpenAI tool calling 所需的 JSON Schema。
|
|
49
|
+
|
|
50
|
+
### 流式输出
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
async for event in await agent.run("写一首关于编程的诗", stream=True):
|
|
54
|
+
if event.type == "text":
|
|
55
|
+
print(event.content, end="", flush=True)
|
|
56
|
+
elif event.type == "tool_call":
|
|
57
|
+
print(f"\n[调用工具: {event.name}]")
|
|
58
|
+
elif event.type == "tool_result":
|
|
59
|
+
print(f"[工具结果: {event.content}]")
|
|
60
|
+
elif event.type == "done":
|
|
61
|
+
print(f"\n完成,token 用量: {event.usage}")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 多轮对话
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
response = await agent.run("你好", conversation_id="session-1")
|
|
68
|
+
response = await agent.run("我刚才说了什么?", conversation_id="session-1")
|
|
69
|
+
# 第二轮会带上第一轮的上下文
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 从 JSON 文件加载配置
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"model": "gpt-4o",
|
|
77
|
+
"system_prompt": "你是一个编程助手",
|
|
78
|
+
"mcp_servers": [
|
|
79
|
+
{"command": "npx", "args": ["-y", "@anthropic/mcp-server-filesystem", "/tmp"]},
|
|
80
|
+
{"url": "http://localhost:8080/sse"}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
config = AgentConfig.from_json("agent-config.json")
|
|
87
|
+
agent = Agent(config)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
JSON 中 `mcp_servers` 根据 `command`(stdio)或 `url`(SSE)自动识别类型。
|
|
91
|
+
|
|
92
|
+
### 从环境变量加载配置
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
export VIBE_MODEL=gpt-4o
|
|
96
|
+
export VIBE_SYSTEM_PROMPT="你是一个助手"
|
|
97
|
+
export VIBE_MAX_ITERATIONS=30
|
|
98
|
+
export VIBE_MCP_SERVERS='[{"command":"npx","args":["server"]}]'
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
config = AgentConfig.from_env() # 默认 VIBE_ 前缀
|
|
103
|
+
config = AgentConfig.from_env(prefix="MYAPP_") # 自定义前缀
|
|
104
|
+
agent = Agent(config)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
支持的环境变量:
|
|
108
|
+
|
|
109
|
+
| 变量 | 类型 | 说明 |
|
|
110
|
+
| ---- | ---- | ---- |
|
|
111
|
+
| `VIBE_MODEL` | str | 模型名称 |
|
|
112
|
+
| `VIBE_API_KEY` | str | API 密钥(优先级高于 `OPENAI_API_KEY`) |
|
|
113
|
+
| `VIBE_BASE_URL` | str | 自定义 API endpoint |
|
|
114
|
+
| `VIBE_SYSTEM_PROMPT` | str | 系统提示词 |
|
|
115
|
+
| `VIBE_MAX_ITERATIONS` | int | 最大工具调用轮次 |
|
|
116
|
+
| `VIBE_TOOL_TIMEOUT` | float | 工具调用超时(秒) |
|
|
117
|
+
| `VIBE_MCP_SERVERS` | JSON | MCP server 列表 |
|
|
118
|
+
| `VIBE_DEFAULT_HEADERS` | JSON | 自定义请求头 |
|
|
119
|
+
|
|
120
|
+
### 连接 MCP Server
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from vibe_agent import MCPServerStdio, MCPServerSSE
|
|
124
|
+
|
|
125
|
+
agent = Agent(AgentConfig(
|
|
126
|
+
model="gpt-4o",
|
|
127
|
+
mcp_servers=[
|
|
128
|
+
MCPServerStdio(command="npx", args=["-y", "@anthropic/mcp-server-filesystem", "/tmp"]),
|
|
129
|
+
MCPServerSSE(url="http://localhost:8080/mcp"),
|
|
130
|
+
],
|
|
131
|
+
))
|
|
132
|
+
|
|
133
|
+
async with agent: # 自动连接/断开 MCP server
|
|
134
|
+
response = await agent.run("列出 /tmp 下的文件")
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
支持 stdio 和 StreamableHTTP 两种 MCP transport。连接 MCP 后,server 暴露的工具会自动注册到 Agent 的工具列表中。
|
|
138
|
+
|
|
139
|
+
### 并行 Subagent
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from vibe_agent import SubagentConfig
|
|
143
|
+
|
|
144
|
+
results = await agent.delegate(
|
|
145
|
+
tasks=[
|
|
146
|
+
"分析 src/ 目录的代码结构",
|
|
147
|
+
"检查 tests/ 的测试覆盖率",
|
|
148
|
+
"生成 CHANGELOG",
|
|
149
|
+
],
|
|
150
|
+
config=SubagentConfig(max_parallel=3, timeout=60),
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
for r in results:
|
|
154
|
+
print(f"[{r.status}] {r.content[:100]}")
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
每个 task 在独立的 Agent 实例中运行,互不干扰。
|
|
158
|
+
|
|
159
|
+
## 配置
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
AgentConfig(
|
|
163
|
+
model="gpt-4o", # 模型名称
|
|
164
|
+
api_key="sk-xxx", # 或设置 OPENAI_API_KEY 环境变量
|
|
165
|
+
base_url=None, # 自定义 API endpoint
|
|
166
|
+
system_prompt="你是一个助手", # 系统提示词
|
|
167
|
+
max_iterations=20, # 工具调用最大轮次
|
|
168
|
+
tool_timeout=30.0, # 单次工具调用超时(秒)
|
|
169
|
+
mcp_servers=[], # MCP server 列表
|
|
170
|
+
)
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## 项目结构
|
|
174
|
+
|
|
175
|
+
```text
|
|
176
|
+
src/vibe_agent/
|
|
177
|
+
├── __init__.py # 公开 API 导出
|
|
178
|
+
├── agent.py # 核心 Agent(ReAct 循环 + 流式输出)
|
|
179
|
+
├── config.py # 配置数据类
|
|
180
|
+
├── types.py # Response, StreamEvent, SubagentResult
|
|
181
|
+
├── tools/
|
|
182
|
+
│ ├── base.py # Tool 数据类
|
|
183
|
+
│ └── registry.py # 工具注册中心
|
|
184
|
+
├── mcp/
|
|
185
|
+
│ ├── client.py # MCP 客户端(stdio + streamable_http)
|
|
186
|
+
│ └── tool_adapter.py # MCP tool → OpenAI 格式转换
|
|
187
|
+
└── subagent.py # 并行 subagent 管理器
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## 依赖
|
|
191
|
+
|
|
192
|
+
- `openai` — LLM 调用与 tool calling
|
|
193
|
+
- `mcp` — MCP 协议客户端
|
|
194
|
+
- `pydantic` — 数据校验
|
|
195
|
+
|
|
196
|
+
## 开发
|
|
197
|
+
|
|
198
|
+
```bash
|
|
199
|
+
uv sync --group dev
|
|
200
|
+
uv run pytest tests/ -v
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
## License
|
|
204
|
+
|
|
205
|
+
MIT
|