jdcloud-agentgrid 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.
- jdcloud_agentgrid-0.1.3/.gitignore +46 -0
- jdcloud_agentgrid-0.1.3/PKG-INFO +177 -0
- jdcloud_agentgrid-0.1.3/README.md +157 -0
- jdcloud_agentgrid-0.1.3/pyproject.toml +53 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/__init__.py +11 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/apps/__init__.py +5 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/apps/base_app.py +13 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/apps/simple_app/__init__.py +5 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/apps/simple_app/simple_app.py +63 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/apps/simple_app/simple_app_handlers.py +252 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/auth/__init__.py +36 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/auth/credential_chain.py +129 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/auth/providers.py +122 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/config.py +504 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/errors.py +145 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/extensions/__init__.py +4 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/extensions/observability/__init__.py +52 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/extensions/tools/__init__.py +81 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/extensions/tools/browser_client.py +457 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/extensions/tools/code_interpreter_client.py +1233 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/extensions/tools/code_interpreter_models.py +124 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/profile.py +353 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/runtime/__init__.py +12 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/runtime/client.py +518 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/runtime/models.py +52 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/session.py +215 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/transport/__init__.py +19 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/transport/runtime_adapter.py +184 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/transport/runtime_data_client.py +228 -0
- jdcloud_agentgrid-0.1.3/src/agentgrid/version.py +6 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
.opencode
|
|
2
|
+
|
|
3
|
+
# OS / 文件管理器
|
|
4
|
+
.DS_Store
|
|
5
|
+
Thumbs.db
|
|
6
|
+
|
|
7
|
+
# Python 缓存与字节码
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*$py.class
|
|
11
|
+
|
|
12
|
+
# 虚拟环境
|
|
13
|
+
.venv/
|
|
14
|
+
venv/
|
|
15
|
+
env/
|
|
16
|
+
ENV/
|
|
17
|
+
|
|
18
|
+
# 构建与打包产物
|
|
19
|
+
build/
|
|
20
|
+
dist/
|
|
21
|
+
.eggs/
|
|
22
|
+
*.egg-info/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
|
|
25
|
+
# 测试、覆盖率与静态检查缓存
|
|
26
|
+
.pytest_cache/
|
|
27
|
+
.coverage
|
|
28
|
+
.coverage.*
|
|
29
|
+
htmlcov/
|
|
30
|
+
.mypy_cache/
|
|
31
|
+
.ruff_cache/
|
|
32
|
+
.pyre/
|
|
33
|
+
.hypothesis/
|
|
34
|
+
|
|
35
|
+
# Notebook
|
|
36
|
+
.ipynb_checkpoints/
|
|
37
|
+
|
|
38
|
+
# IDE
|
|
39
|
+
.vscode/
|
|
40
|
+
.idea/
|
|
41
|
+
|
|
42
|
+
# 日志
|
|
43
|
+
*.log
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
agentgrid.yaml
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: jdcloud_agentgrid
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: AgentGrid Python SDK for JDCloud AgentGrid Runtime
|
|
5
|
+
Project-URL: Homepage, https://github.com/agentgrid/agentgrid-python
|
|
6
|
+
Project-URL: Repository, https://github.com/agentgrid/agentgrid-python
|
|
7
|
+
Author: AgentGrid SDK Team
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: jdcloud-sdk>=1.6.314
|
|
10
|
+
Requires-Dist: pyyaml>=6.0.2
|
|
11
|
+
Requires-Dist: starlette>=0.37.2
|
|
12
|
+
Requires-Dist: uvicorn>=0.30.0
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: build>=1.2.2; extra == 'dev'
|
|
15
|
+
Requires-Dist: httpx>=0.27.0; extra == 'dev'
|
|
16
|
+
Requires-Dist: langchain-openrouter>=0.2.1; extra == 'dev'
|
|
17
|
+
Requires-Dist: langchain>=0.3.28; extra == 'dev'
|
|
18
|
+
Requires-Dist: pytest>=8.2.0; extra == 'dev'
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
|
|
21
|
+
# AgentGrid Python SDK
|
|
22
|
+
|
|
23
|
+
AgentGrid Python SDK v1 提供面向 Runtime 的高层调用接口,主路径围绕以下 API:
|
|
24
|
+
|
|
25
|
+
- `from agentgrid import AgentGridProfile`
|
|
26
|
+
- `runtime.invoke()`
|
|
27
|
+
- `runtime.create_runtime()/update_runtime()/delete_runtime()/get_runtime()/list_runtimes()`
|
|
28
|
+
- `runtime_session()`
|
|
29
|
+
|
|
30
|
+
## Python 版本要求
|
|
31
|
+
|
|
32
|
+
- Python `>=3.10`
|
|
33
|
+
|
|
34
|
+
## 安装
|
|
35
|
+
|
|
36
|
+
### pip
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install jdcloud-agentgrid
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### uv(下游项目)
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
uv add jdcloud-agentgrid
|
|
46
|
+
uv sync
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## SDK 默认配置文件(agentgrid.yaml)
|
|
50
|
+
|
|
51
|
+
`get_sdk_default_config()` 会自动尝试读取入口脚本同级的 `agentgrid.yaml`。
|
|
52
|
+
|
|
53
|
+
- 查找规则固定为:`Path(sys.argv[0]).resolve().parent / "agentgrid.yaml"`
|
|
54
|
+
- 文件不存在:忽略并回退到 SDK 内置默认配置
|
|
55
|
+
- 仅识别 `basic` 节点,且字段必须是 `AgentGridConfig` 已定义字段
|
|
56
|
+
|
|
57
|
+
最小示例:
|
|
58
|
+
|
|
59
|
+
```yaml
|
|
60
|
+
basic:
|
|
61
|
+
region: cn-north-1
|
|
62
|
+
endpoint: https://agentgrid.jdcloud-api.com
|
|
63
|
+
data_endpoint: https://agentgrid-runtime.jdcloud-api.com
|
|
64
|
+
timeout: 30
|
|
65
|
+
connect_timeout: 5
|
|
66
|
+
read_timeout: 30
|
|
67
|
+
max_retries: 2
|
|
68
|
+
user_agent_extra: demo-app/1.0
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
例如入口脚本位于 `./examples/run.py`,则配置文件应放在 `./examples/agentgrid.yaml`。
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## 最小示例(Quick Start)
|
|
75
|
+
|
|
76
|
+
显式 `auth`(兼容旧用法):
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from agentgrid import AgentGridProfile, runtime_session
|
|
80
|
+
|
|
81
|
+
profile = AgentGridProfile(
|
|
82
|
+
region="cn-north-1",
|
|
83
|
+
data_endpoint="https://agentgrid-runtime.jdcloud-api.com", # 可选:默认就是该地址
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
with runtime_session("cn-north-1", "your-runtime-id", profile=profile) as runtime:
|
|
87
|
+
resp = runtime.invoke(
|
|
88
|
+
{"text": "你好,AgentGrid"},
|
|
89
|
+
api_key="your-runtime-api-key",
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
print(resp.get("output_text"))
|
|
93
|
+
print(resp.get("request_id"), resp.get("trace_id"))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
默认 AK/SK 凭证链(无需显式 `auth`):
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
from agentgrid import AgentGridProfile
|
|
100
|
+
|
|
101
|
+
profile = AgentGridProfile(region="cn-north-1")
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
当未显式传入 `auth` 时,AK/SK 优先级固定为:
|
|
105
|
+
|
|
106
|
+
1. `access_key`/`secret_key` 构造参数
|
|
107
|
+
2. `JDCLOUD_ACCESS_KEY`/`JDCLOUD_SECRET_KEY`
|
|
108
|
+
3. `~/.jdcloud/credentials` 的 `[default]`(`access_key_id`/`secret_access_key`)
|
|
109
|
+
|
|
110
|
+
任一来源出现半配置(仅 AK 或仅 SK)会立即报错并终止降级。
|
|
111
|
+
|
|
112
|
+
## 支持的认证方式(v1)
|
|
113
|
+
|
|
114
|
+
- `ApiKeyAuthProvider`
|
|
115
|
+
- `JdcloudAkskAuthProvider`
|
|
116
|
+
|
|
117
|
+
v1 仅支持以上两种认证方式。
|
|
118
|
+
|
|
119
|
+
## Runtime 与会话示例
|
|
120
|
+
|
|
121
|
+
统一调用(自动 JSON/SSE 分流):
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
with runtime_session("cn-north-1", "rt-template-001", profile=profile) as runtime:
|
|
125
|
+
result = runtime.invoke(
|
|
126
|
+
{"text": "请总结这段文本"},
|
|
127
|
+
api_key="your-runtime-api-key",
|
|
128
|
+
metadata={"scene": "demo"},
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
if isinstance(result, dict):
|
|
132
|
+
print(result.get("output_text"))
|
|
133
|
+
else:
|
|
134
|
+
for event in result:
|
|
135
|
+
if event.type == "text_delta" and event.text:
|
|
136
|
+
print(event.text, end="", flush=True)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
使用 `runtime_session()`:
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
from agentgrid import runtime_session
|
|
143
|
+
|
|
144
|
+
with runtime_session("cn-north-1", "chat-001", profile=profile) as runtime:
|
|
145
|
+
resp = runtime.invoke("会话内调用", api_key="your-runtime-api-key")
|
|
146
|
+
print(resp.get("session_id"))
|
|
147
|
+
|
|
148
|
+
# 退出上下文时仅记录 end_session 日志,不执行显式网络清理
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## 类型模型(v1)
|
|
152
|
+
|
|
153
|
+
- `runtime.invoke()` 按响应 `Content-Type` 自动返回:
|
|
154
|
+
- JSON:`dict`
|
|
155
|
+
- SSE:可同步迭代 `StreamResponse`
|
|
156
|
+
- `StreamEvent` 统一字段:`type`、`text`、`data`、`raw`
|
|
157
|
+
|
|
158
|
+
## 异常与排障
|
|
159
|
+
|
|
160
|
+
统一异常基类:`AgentGridError`。
|
|
161
|
+
|
|
162
|
+
主要子类:
|
|
163
|
+
|
|
164
|
+
- `AgentGridAuthenticationError`
|
|
165
|
+
- `AgentGridAuthorizationError`
|
|
166
|
+
- `AgentGridRateLimitError`
|
|
167
|
+
- `AgentGridTimeoutError`
|
|
168
|
+
- `AgentGridTransportError`
|
|
169
|
+
- `AgentGridStreamError`
|
|
170
|
+
- `AgentGridServerError`
|
|
171
|
+
|
|
172
|
+
异常对象稳定暴露诊断字段:`code`、`request_id`、`retryable`。
|
|
173
|
+
|
|
174
|
+
控制口与数据口边界(务必注意):
|
|
175
|
+
|
|
176
|
+
- 控制口接口(`create/update/delete/get/list`)仅支持 AK/SK,使用 API Key 会抛出 `AgentGridAuthenticationError(code="AUTHENTICATION_REQUIRED")`
|
|
177
|
+
- 数据口接口(`invoke`)本期强制 API Key;优先级:请求级 `api_key` > `agentgrid.yaml` 的 `runtime.api_key`
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# AgentGrid Python SDK
|
|
2
|
+
|
|
3
|
+
AgentGrid Python SDK v1 提供面向 Runtime 的高层调用接口,主路径围绕以下 API:
|
|
4
|
+
|
|
5
|
+
- `from agentgrid import AgentGridProfile`
|
|
6
|
+
- `runtime.invoke()`
|
|
7
|
+
- `runtime.create_runtime()/update_runtime()/delete_runtime()/get_runtime()/list_runtimes()`
|
|
8
|
+
- `runtime_session()`
|
|
9
|
+
|
|
10
|
+
## Python 版本要求
|
|
11
|
+
|
|
12
|
+
- Python `>=3.10`
|
|
13
|
+
|
|
14
|
+
## 安装
|
|
15
|
+
|
|
16
|
+
### pip
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install jdcloud-agentgrid
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
### uv(下游项目)
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
uv add jdcloud-agentgrid
|
|
26
|
+
uv sync
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## SDK 默认配置文件(agentgrid.yaml)
|
|
30
|
+
|
|
31
|
+
`get_sdk_default_config()` 会自动尝试读取入口脚本同级的 `agentgrid.yaml`。
|
|
32
|
+
|
|
33
|
+
- 查找规则固定为:`Path(sys.argv[0]).resolve().parent / "agentgrid.yaml"`
|
|
34
|
+
- 文件不存在:忽略并回退到 SDK 内置默认配置
|
|
35
|
+
- 仅识别 `basic` 节点,且字段必须是 `AgentGridConfig` 已定义字段
|
|
36
|
+
|
|
37
|
+
最小示例:
|
|
38
|
+
|
|
39
|
+
```yaml
|
|
40
|
+
basic:
|
|
41
|
+
region: cn-north-1
|
|
42
|
+
endpoint: https://agentgrid.jdcloud-api.com
|
|
43
|
+
data_endpoint: https://agentgrid-runtime.jdcloud-api.com
|
|
44
|
+
timeout: 30
|
|
45
|
+
connect_timeout: 5
|
|
46
|
+
read_timeout: 30
|
|
47
|
+
max_retries: 2
|
|
48
|
+
user_agent_extra: demo-app/1.0
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
例如入口脚本位于 `./examples/run.py`,则配置文件应放在 `./examples/agentgrid.yaml`。
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## 最小示例(Quick Start)
|
|
55
|
+
|
|
56
|
+
显式 `auth`(兼容旧用法):
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from agentgrid import AgentGridProfile, runtime_session
|
|
60
|
+
|
|
61
|
+
profile = AgentGridProfile(
|
|
62
|
+
region="cn-north-1",
|
|
63
|
+
data_endpoint="https://agentgrid-runtime.jdcloud-api.com", # 可选:默认就是该地址
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
with runtime_session("cn-north-1", "your-runtime-id", profile=profile) as runtime:
|
|
67
|
+
resp = runtime.invoke(
|
|
68
|
+
{"text": "你好,AgentGrid"},
|
|
69
|
+
api_key="your-runtime-api-key",
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
print(resp.get("output_text"))
|
|
73
|
+
print(resp.get("request_id"), resp.get("trace_id"))
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
默认 AK/SK 凭证链(无需显式 `auth`):
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
from agentgrid import AgentGridProfile
|
|
80
|
+
|
|
81
|
+
profile = AgentGridProfile(region="cn-north-1")
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
当未显式传入 `auth` 时,AK/SK 优先级固定为:
|
|
85
|
+
|
|
86
|
+
1. `access_key`/`secret_key` 构造参数
|
|
87
|
+
2. `JDCLOUD_ACCESS_KEY`/`JDCLOUD_SECRET_KEY`
|
|
88
|
+
3. `~/.jdcloud/credentials` 的 `[default]`(`access_key_id`/`secret_access_key`)
|
|
89
|
+
|
|
90
|
+
任一来源出现半配置(仅 AK 或仅 SK)会立即报错并终止降级。
|
|
91
|
+
|
|
92
|
+
## 支持的认证方式(v1)
|
|
93
|
+
|
|
94
|
+
- `ApiKeyAuthProvider`
|
|
95
|
+
- `JdcloudAkskAuthProvider`
|
|
96
|
+
|
|
97
|
+
v1 仅支持以上两种认证方式。
|
|
98
|
+
|
|
99
|
+
## Runtime 与会话示例
|
|
100
|
+
|
|
101
|
+
统一调用(自动 JSON/SSE 分流):
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
with runtime_session("cn-north-1", "rt-template-001", profile=profile) as runtime:
|
|
105
|
+
result = runtime.invoke(
|
|
106
|
+
{"text": "请总结这段文本"},
|
|
107
|
+
api_key="your-runtime-api-key",
|
|
108
|
+
metadata={"scene": "demo"},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
if isinstance(result, dict):
|
|
112
|
+
print(result.get("output_text"))
|
|
113
|
+
else:
|
|
114
|
+
for event in result:
|
|
115
|
+
if event.type == "text_delta" and event.text:
|
|
116
|
+
print(event.text, end="", flush=True)
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
使用 `runtime_session()`:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from agentgrid import runtime_session
|
|
123
|
+
|
|
124
|
+
with runtime_session("cn-north-1", "chat-001", profile=profile) as runtime:
|
|
125
|
+
resp = runtime.invoke("会话内调用", api_key="your-runtime-api-key")
|
|
126
|
+
print(resp.get("session_id"))
|
|
127
|
+
|
|
128
|
+
# 退出上下文时仅记录 end_session 日志,不执行显式网络清理
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## 类型模型(v1)
|
|
132
|
+
|
|
133
|
+
- `runtime.invoke()` 按响应 `Content-Type` 自动返回:
|
|
134
|
+
- JSON:`dict`
|
|
135
|
+
- SSE:可同步迭代 `StreamResponse`
|
|
136
|
+
- `StreamEvent` 统一字段:`type`、`text`、`data`、`raw`
|
|
137
|
+
|
|
138
|
+
## 异常与排障
|
|
139
|
+
|
|
140
|
+
统一异常基类:`AgentGridError`。
|
|
141
|
+
|
|
142
|
+
主要子类:
|
|
143
|
+
|
|
144
|
+
- `AgentGridAuthenticationError`
|
|
145
|
+
- `AgentGridAuthorizationError`
|
|
146
|
+
- `AgentGridRateLimitError`
|
|
147
|
+
- `AgentGridTimeoutError`
|
|
148
|
+
- `AgentGridTransportError`
|
|
149
|
+
- `AgentGridStreamError`
|
|
150
|
+
- `AgentGridServerError`
|
|
151
|
+
|
|
152
|
+
异常对象稳定暴露诊断字段:`code`、`request_id`、`retryable`。
|
|
153
|
+
|
|
154
|
+
控制口与数据口边界(务必注意):
|
|
155
|
+
|
|
156
|
+
- 控制口接口(`create/update/delete/get/list`)仅支持 AK/SK,使用 API Key 会抛出 `AgentGridAuthenticationError(code="AUTHENTICATION_REQUIRED")`
|
|
157
|
+
- 数据口接口(`invoke`)本期强制 API Key;优先级:请求级 `api_key` > `agentgrid.yaml` 的 `runtime.api_key`
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "jdcloud_agentgrid"
|
|
7
|
+
version = "0.1.3"
|
|
8
|
+
description = "AgentGrid Python SDK for JDCloud AgentGrid Runtime"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{ name = "AgentGrid SDK Team" },
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"jdcloud_sdk>=1.6.314",
|
|
16
|
+
"PyYAML>=6.0.2",
|
|
17
|
+
"starlette>=0.37.2",
|
|
18
|
+
"uvicorn>=0.30.0",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
dev = [
|
|
23
|
+
"build>=1.2.2",
|
|
24
|
+
"httpx>=0.27.0",
|
|
25
|
+
"langchain>=0.3.28",
|
|
26
|
+
"langchain-openrouter>=0.2.1",
|
|
27
|
+
"pytest>=8.2.0",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://github.com/agentgrid/agentgrid-python"
|
|
32
|
+
Repository = "https://github.com/agentgrid/agentgrid-python"
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/agentgrid"]
|
|
36
|
+
|
|
37
|
+
[tool.hatch.build.targets.sdist]
|
|
38
|
+
include = [
|
|
39
|
+
"/src",
|
|
40
|
+
"/README.md",
|
|
41
|
+
"/pyproject.toml",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
[tool.agentgrid.versioning]
|
|
45
|
+
# 版本策略:遵循语义化版本(SemVer)。
|
|
46
|
+
# 只要公共 API 存在破坏性变更,必须提升主版本号。
|
|
47
|
+
strategy = "semver"
|
|
48
|
+
breaking_change_requires_major_bump = true
|
|
49
|
+
|
|
50
|
+
[dependency-groups]
|
|
51
|
+
dev = [
|
|
52
|
+
"twine>=6.2.0",
|
|
53
|
+
]
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""AgentGrid Python SDK 顶层导出。
|
|
2
|
+
|
|
3
|
+
根据 OpenSpec `sdk-packaging-and-entrypoint` 能力约束,v1 必须稳定支持:
|
|
4
|
+
`from agentgrid import AgentGridProfile`。
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from .profile import AgentGridProfile
|
|
8
|
+
from .session import code_session, runtime_session
|
|
9
|
+
from .version import __version__
|
|
10
|
+
|
|
11
|
+
__all__ = ["AgentGridProfile", "runtime_session", "code_session", "__version__"]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""AgentGrid 应用抽象基类。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from abc import ABC, abstractmethod
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class BaseAgentGridApp(ABC):
|
|
9
|
+
"""应用层统一运行接口。"""
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def run(self, host: str | None = None, port: int = 8000) -> None:
|
|
13
|
+
"""启动应用服务。"""
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""AgentGrid simple app 实现。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import inspect
|
|
6
|
+
from typing import Any, Callable
|
|
7
|
+
|
|
8
|
+
import uvicorn
|
|
9
|
+
from starlette.applications import Starlette
|
|
10
|
+
from starlette.routing import Route
|
|
11
|
+
|
|
12
|
+
from agentgrid.apps.base_app import BaseAgentGridApp
|
|
13
|
+
from agentgrid.apps.simple_app.simple_app_handlers import (
|
|
14
|
+
AsyncTaskHandler,
|
|
15
|
+
InvokeHandler,
|
|
16
|
+
PingHandler,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class AgentGridSimpleApp(BaseAgentGridApp, Starlette):
|
|
21
|
+
"""AgentGrid simple app。"""
|
|
22
|
+
|
|
23
|
+
def __init__(self) -> None:
|
|
24
|
+
self.ping_handler = PingHandler()
|
|
25
|
+
self.invoke_handler = InvokeHandler()
|
|
26
|
+
self.async_task_handler = AsyncTaskHandler()
|
|
27
|
+
|
|
28
|
+
routes = [
|
|
29
|
+
Route("/ping", self.ping_handler.handle, methods=["GET"]),
|
|
30
|
+
Route("/health", self.ping_handler.health_check, methods=["GET"]),
|
|
31
|
+
Route("/readiness", self.ping_handler.readiness, methods=["GET"]),
|
|
32
|
+
Route("/liveness", self.ping_handler.liveness, methods=["GET"]),
|
|
33
|
+
Route("/invoke", self.invoke_handler.handle, methods=["POST"]),
|
|
34
|
+
Route("/invocations", self.invoke_handler.handle, methods=["POST"]),
|
|
35
|
+
Route(
|
|
36
|
+
"/v1/regions/{region}/runtimes/{runtime_id}:invoke",
|
|
37
|
+
self.invoke_handler.handle,
|
|
38
|
+
methods=["POST"],
|
|
39
|
+
),
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
super().__init__(routes=routes)
|
|
43
|
+
|
|
44
|
+
def entrypoint(self, func: Callable[..., Any]) -> Callable[..., Any]:
|
|
45
|
+
"""注册 `/invoke` 处理函数。"""
|
|
46
|
+
|
|
47
|
+
self.invoke_handler.func = func
|
|
48
|
+
return func
|
|
49
|
+
|
|
50
|
+
def ping(self, func: Callable[..., Any]) -> Callable[..., Any]:
|
|
51
|
+
"""注册 `/ping` 检查函数。"""
|
|
52
|
+
|
|
53
|
+
assert len(list(inspect.signature(func).parameters.keys())) == 0, (
|
|
54
|
+
f"Health check function `{func.__name__}` should not receive any arguments."
|
|
55
|
+
)
|
|
56
|
+
self.ping_handler.func = func
|
|
57
|
+
return func
|
|
58
|
+
|
|
59
|
+
def run(self, host: str | None = None, port: int = 8080) -> None:
|
|
60
|
+
"""启动 Web 应用。"""
|
|
61
|
+
|
|
62
|
+
resolved_host = host if host else "0.0.0.0"
|
|
63
|
+
uvicorn.run(self, host=resolved_host, port=port)
|