Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 0.3.4 instead.
Reason given by maintainers: Broken build, do not use. Please upgrade to newer version.

agentquay-sdk — AgentQuay Python SDK

让 AI Agent 通过标准 MCP 协议发现并调用你的桌面应用方法。加个装饰器,其余全部由框架处理。

pip install agentquay-sdk        # 依赖:websockets(keyring/pydantic 可选)

用法

import asyncio
from agentquay import AgentQuayClient, agent_tool

class MusicController:
    @agent_tool("search", description="搜索音乐库中的歌曲")
    def search(self, keyword: str, limit: int = 10) -> list[dict]:
        """搜索音乐库。"""
        ...

    @agent_tool("play", description="播放指定歌曲")
    async def play(self, song_id: str) -> dict:
        """异步方法同样支持。"""
        ...

    @agent_tool("delete", description="删除歌曲", requires_confirmation=True)
    def delete(self, song_id: str) -> dict:
        """危险操作:Bridge 会先向应用弹确认框,用户确认后才执行。"""
        ...

async def main():
    client = AgentQuayClient(
        app_id="music-app",        # [a-z0-9-]{1,48},禁止 _ 和 .
        app_name="Music Player",
        port=0,                    # 0 = 从 ~/.agentquay/port 自动读取
        auto_spawn_bridge=True,    # 未检测到 Bridge 时自动拉起内嵌二进制
    )
    client.register_tools(MusicController())
    await client.connect()         # 保持连接:心跳 + 断线指数退避重连

asyncio.run(main())

特性

  • @agent_tool 装饰器:name 缺省回退函数名;描述缺省回退 docstring 首行; 同步函数经 asyncio.to_thread 执行,async 函数直接 await
  • 类型注解 → JSON Schema:str/int/float/bool、list[T]、dict[str, T]、 Optional[T]、Literal、enum.Enum 自动生成;Pydantic v2 模型可选增强
  • 确认弹窗:tkinter OS 原生对话框(三平台标准库);无显示环境回退控制台; 可用 on_confirm 回调自定义
  • token 持久化:keyring(Windows Credential Manager / Keychain / libsecret), 不可用时回退 ~/.agentquay/tokens.json(0600)
  • 心跳 + 重连:30s 应用层 ping/pong;断线指数退避重连(1s → 30s),自动携带 token; 同 appId 新实例注册时旧连接收到 disconnect(replaced) 并停止重连
  • auto-spawn:本地无 Bridge 时自动拉起内嵌二进制(serve --embedded, 日志写应用缓存目录),SDK 退出时自动终止;拉取失败给出明确出路提示

确认流程

requires_confirmation=True 的 tool 被调用时,Bridge 向应用发送 confirm 消息:

client = AgentQuayClient(..., on_confirm=my_confirm_cb)

async def my_confirm_cb(message: str, arguments: dict | None) -> bool:
    """返回 True=确认 / False=取消。支持同步与异步回调。"""
    print(f"⚠️ {message} {arguments}")
    return input("确认执行?[y/N] ").strip().lower() == "y"

自定义确认弹窗示例(tkinter)

def tk_confirm(message: str, arguments: dict | None) -> bool:
    import tkinter as tk
    from tkinter import messagebox
    root = tk.Tk(); root.withdraw()
    return messagebox.askyesno("AgentQuay 确认", f"{message}\n{arguments}")

开发

pip install websockets
python -m unittest discover -s tests        # 18 项单测
python tests/e2e_test.py                    # 26 项端到端联调(需先构建 Bridge)
python examples/music_app.py                # 示例应用

协议

  • 注册:register(含 protocolVersion、authToken、tools 元数据)
  • 调用:Bridge → invoke → 应用执行 → result
  • 确认:Bridge → confirm → 应用弹窗 → confirm_result
  • 心跳:ping / pong(30s)

详见 README.md §2.1(Bridge↔应用协议)与 sdk-tutorial.md §5.1(Python SDK 用法)。

Metadata

Release files for agentquay-sdk 0.3.2

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

Source distribution (sdist)

Source distribution for agentquay-sdk 0.3.2
File Size Uploaded Provenance Actions
agentquay_sdk-0.3.2.tar.gz 15.0 MB With provenance Details for agentquay_sdk-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for agentquay-sdk 0.3.2
File Interpreter ABI Platform Actions
agentquay_sdk-0.3.2-py3-none-any.whl Python 3 none any Details for agentquay_sdk-0.3.2-py3-none-any.whl

Total release size: 30.0 MB

Release files / agentquay_sdk-0.3.2.tar.gz

Download URL agentquay_sdk-0.3.2.tar.gz
Size 15.0 MB
Tags Source
SHA-256 checksum
How to use checksums
3c58fd7f6713ac20cd8d05528794da652998c19fbb396e9123dc8c70653c7e71
BLAKE2b-256 checksum
How to use checksums
46a5d656fba94418e17066b9dd14254d47a6d297e0464a60fd6f152db99d51bf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / agentquay_sdk-0.3.2-py3-none-any.whl

Download URL agentquay_sdk-0.3.2-py3-none-any.whl
Size 15.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
3fd6132b2e2365ec563d3c789bc55eb5c6b1181084a93615722c2e1b1a347e06
BLAKE2b-256 checksum
How to use checksums
97b21c3ce0b54515cc9bc35bf476361acca2a9632853339cadce2c54fb7177e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Security for agentquay-sdk 0.3.2

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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for agentquay_sdk-0.3.2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

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.

Release history Release notifications | RSS feed

This release

0.3.2 This release

2 release files Full provenance

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