Skip to main content

aaas-service

用 AgentScope 驱动的 AaaS(Agent as a Service)协议 服务端参考实现。

一句话概括它和其它 Agent 服务的区别:

服务端没有内置能力。 调用方声明什么函数,模型就只能伸到什么能力; 而每一次伸手,都伸回调用方自己的进程去执行。

所以模型、凭据、业务数据全在你的进程里,服务端只是一个「会思考但手无寸铁」的壳。


安装

pip install aaas-service
set "DEEPSEEK_API_KEY=sk-..."   # bash: export DEEPSEEK_API_KEY=sk-...
aaas-service                    # 等价于 python -m aaas_service,默认监听 127.0.0.1:8888
aaas-service --print-config     # 不起服务、不联网、不要 key,只告诉你每个配置值来自哪
aaas-service --max-iters 40     # 一轮最多几步(默认 200;也可用 AAAS_MAX_ITERS 给)

只需要 Python ≥ 3.11(下限由 agentscope 决定)。源码与议题在 github.com/YY-Yifei/openagent-aaas。

它做了什么

能力 说明
单轮 ReAct 闭环 handler(ctx) 一个函数里跑完「模型 → 工具 → 模型 → 收尾」
反向 function calling 工具调用经协议回到调用方执行,服务端不持有任何实现与凭据
流式回复 文本 / 思考块 / 工具事件分段推送,block_id 直接映射 message_id
stateless 会话 每轮由调用方重放 history,服务端零记忆(可切 session 模式)
用量上报 token / 工具次数;拿不到就不填,绝不写 0
模型配置 提供方 / 模型名 / 地址 / 凭据四件事,一律从命令行 + 环境变量来

仓库结构

aaas_service/          服务端实现(**只有这个包进 wheel**)
  app.py               装配 + 命令行入口(--print-config / --host / --port …)
  handler.py           唯一的接缝:async def handler(ctx)
  providers.py         提供方表 + 四个旋钮的解析(命令行 > AAAS_* > 约定变量 > 默认)
  events.py            AgentScope 事件 → AaaS 协议的桥
  tools.py             协议里的 JSON Schema → 可直接调用的工具
  usage.py             token / 调用计数(未知 ≠ 0)
  history.py           历史重放与裁剪
  validate.py          入参校验
pyproject.toml         打包元数据(PEP 621;版本真源 = aaas_service.__version__)
scripts/
  chat.py              交互式调用方(工具在你自己进程里执行)
  service_ctl.py       起停 / 状态(真握手探活,不是裸端口探测)
tests/                 单元 + 端到端(默认全离线,不联网不花钱)
srcpath.py             定位 aaas SDK 源码(仅仓库开发用)
conftest.py            让 tests/ 能在仓库布局下找到 aaas

scripts/、tests/、srcpath.py 都依赖仓库布局,所以不进 wheel: pip install aaas-service 只会装 aaas_service 一个包(tests/test_packaging.py 守着这条)。

依赖

  • Python ≥ 3.11 —— 这是 agentscope 的要求;本仓库在 3.12 上实测
  • 一次装齐(agentscope + aaas + pytest):pip install -e ".[test]"
  • aaas 0.2.1 起已在 PyPI 上,pip install 会一并装上

快速开始

# 1) 起服务(需要真实凭据;默认监听 127.0.0.1:8888)
set "DEEPSEEK_API_KEY=sk-..."
python -m aaas_service

# 2) 只想确认「这套环境最终会用什么」—— 不起服务、不联网、不要 key
python -m aaas_service --print-config

# 3) 交互式调用方(另开一个终端)
python scripts/chat.py

变量清单见 .env.example(只有变量名,没有任何真实值)。 --print-config 的输出会把每个值的来源一起印出来(--model / AAAS_MODEL / 内置默认 …),凭据只报变量名与长度、永不报值:

配置   provider=deepseek(--provider) model=deepseek-flash(内置默认)
       base_url=https://api.deepseek.com(内置默认) api_key=DEEPSEEK_API_KEY(len=35)

python scripts/service_ctl.py start|status|stop|config 是同一套装配的进程管理入口, status 做的是一次真正的协议握手(端口开着只证明有人 listen,握手成功才证明 对端是 aaas 且宣告的能力都在)。

模型配置从哪来

四个旋钮在进程启动时解析一次,调用方永远影响不了它们。顺序是一条规则,没有例外:

命令行参数(--provider / --model / --base-url / --api-key)
  > AAAS_PROVIDER / AAAS_MODEL / AAAS_BASE_URL / AAAS_API_KEY
    > 提供方约定变量(OPENAI_API_KEY、OPENAI_BASE_URL、DEEPSEEK_API_KEY …)
      > 内置默认
提供方 内置默认模型 默认地址
deepseek(默认) deepseek-flash https://api.deepseek.com
openai gpt-4o-mini SDK 默认
dashscope qwen-max dashscope 兼容端点
anthropic claude-sonnet-4-5 SDK 默认

--provider 与 AAAS_PROVIDER 都没给时用 deepseek。

空值就是没设:set "VAR=" 留下的空变量不会顶掉默认值;路径类变量还会顺手剥掉 误包的引号(set VAR="C:\x" 会把引号一起存进值里)。

AAAS_MODEL 是跨提供方全局生效的:设了它,换 provider 前要先清掉,或用 --model 显式压过 —— 模型名在不同提供方之间通常不通用。

跑测试

pip install -e ".[test]"              # 含 agentscope / aaas / pytest / pytest-asyncio
python -m pytest tests -q             # 全离线
set "AAAS_LIVE=1" && python -m pytest tests -q   # 加上真调用的 live 用例(花钱)

pytest-asyncio 不是可选项:pytest.ini 里的 asyncio_mode = auto 只有它认。 少了它,所有 async def test_* 只会得到一条 warning 然后被跳过 —— 一片绿色里 十几个用例其实一次都没执行。

单元与端到端都不联网:模型用脚本化的假模型替身,协议层跑真 WebSocket。 要针对本地 aaas 源码跑(而不是 site-packages 里那份),设 AAAS_SRC 指向它的 src, 或在仓库根写一行 .aaas-src;两者都没有时 conftest.py 会明确说缺什么,不会去猜路径。

License

Apache-2.0

Metadata

Release files for aaas-service 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aaas-service 0.2.1
File Size Uploaded Provenance Actions
aaas_service-0.2.1.tar.gz 85.7 kB Without provenance Details for aaas_service-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aaas-service 0.2.1
File Interpreter ABI Platform Actions
aaas_service-0.2.1-py3-none-any.whl Python 3 none any Details for aaas_service-0.2.1-py3-none-any.whl

Total release size: 140.1 kB

Release files / aaas_service-0.2.1.tar.gz

Download URL aaas_service-0.2.1.tar.gz
Size 85.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c9801ea669dc7d127de3042528f7b2830c0fd57c33b22a4f403644e015773b01
BLAKE2b-256 checksum
How to use checksums
65cebfd11820d705c607490563925bbd99aed2b0d76c3bf4313172dc4bc0846d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Release files / aaas_service-0.2.1-py3-none-any.whl

Download URL aaas_service-0.2.1-py3-none-any.whl
Size 54.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5252f79e0695b913bd35871108a6be673a5313749fbe84689b87700f6d5fe1f9
BLAKE2b-256 checksum
How to use checksums
420d23bb7efccdfcac6340d97683a8685e8627ed3a0061ec3ddd8f7480b7afe9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.9

Security for aaas-service 0.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page