Skip to main content

Daphnis

Daphnis 是一个基于 Python asyncio 的 Agent 库,提供异步模型调用、流式事件、会话历史和上下文管理等能力。

面向需要在 Python 应用中集成 AI Agent 能力的开发者,可用于命令行工具、桌面应用或其他异步服务。Daphnis 提供会话与模型接入接口,界面和业务逻辑由宿主应用实现。

安装

需要 Python 3.13 或更高版本。在项目的虚拟环境中,从 PyPI 安装:

python -m pip install daphnis

开始一次对话

以 DeepSeek 为例 安装 Daphnis 后,在运行环境中设置 DEEPSEEK_API_KEY,再将下面代码保存为 Python 文件并运行。示例使用库内目录登记的模型,实际可用性取决于远端服务与账户权限。

import asyncio
import os

from daphnis.providers import create_agent


async def main() -> None:
    async with await create_agent(
        provider="deepseek",
        model="deepseek-flash",
        api_key=os.environ["DEEPSEEK_API_KEY"],
    ) as agent:
        result = await agent.run("你好,请简单介绍一下你自己。")
        print(result.text)
        print("结束原因:", result.stop_reason)


if __name__ == "__main__":
    asyncio.run(main())

create_agent() 按传入配置创建会话,本身不读取环境变量、配置文件或钥匙串;上例由调用方读取环境变量并传入凭据。创建过程执行本地校验,首次 run() 才请求模型。会话应通过 async with 或 await agent.aclose() 关闭。

同一会话中顺序调用 await agent.run(...) 可以继续对话,后续调用会使用已提交的历史。已有 asyncio 事件循环的应用可直接 await main();asyncio.run(main()) 用于独立脚本入口。

需要逐片段展示回答时,可向 create_agent() 传入 EventBus,监听 MessageUpdate 中的 TextDelta。完整示例见流式事件。

模型接入

内置适配器的厂商说明、已登记模型、连接配置及参数限制见已支持的模型服务。

模型目录是本库维护的离线声明,不会访问远端,也不是完整的远端模型清单。可通过以下接口查询:

from daphnis.providers import available_providers, list_models, model_info

print(available_providers())
for item in list_models("deepseek"):
    print(item.model, item.capabilities.thinking_mode)

info = model_info("deepseek", "deepseek-flash")
print(info.known, info.capabilities.reasoning_levels)

文档

  • 使用指南:模型配置、连续对话、流式事件、历史保存、上下文与预算、本地配置、工具定义,以及停止、切换和关闭流程。
  • 已支持的模型服务:按厂商介绍适配器、模型目录、参数限制和环境变量入口。
  • 架构与运行约定:模块职责、消息结构、状态提交、模型切换与资源所有权。
  • 变更记录:已发布版本与下一版本的变化。
  • 问题反馈:报告缺陷或提出功能建议。

当前范围

  • 基础会话核心不管理文件、凭据或界面,模型绑定由外层注入。
  • 提供工具接口和调用机制,具体工具由宿主应用实现并注册。
  • 不提供默认模型服务商、自动重试、自动摘要或自动历史保存。
  • 默认凭据后端正式支持 macOS,通过显式的 keyring macOS 后端访问钥匙串。

开发检查

从源码开发时,在仓库根目录安装项目及开发依赖后运行检查:

python -m pip install --upgrade pip
python -m pip install . --group dev
python -m ruff check .
python -m mypy
python -m pytest -q

GitHub Actions 会在推送到 main、向 main 提交 PR 或手动触发时执行 CI:检查代码与类型,在 Linux、macOS、Windows 上测试 Python 3.13–3.15,并验证源码包、wheel、安装后的公开接口与使用方类型检查。

许可证

本项目采用 MIT 许可证。

Metadata

Release files for daphnis 0.1.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 daphnis 0.1.1
File Size Uploaded Provenance Actions
daphnis-0.1.1.tar.gz 94.8 kB Without provenance Details for daphnis-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for daphnis 0.1.1
File Interpreter ABI Platform Actions
daphnis-0.1.1-py3-none-any.whl Python 3 none any Details for daphnis-0.1.1-py3-none-any.whl

Total release size: 176.5 kB

Release files / daphnis-0.1.1.tar.gz

Download URL daphnis-0.1.1.tar.gz
Size 94.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e08311d4b5abbcf4cd310f32c8c00082df58fa9f0e57748f6579ba86513d5ac3
BLAKE2b-256 checksum
How to use checksums
465aeef1cb0d0d925f660e097f78c5fdde5208c0cdd481b0aad5ace9b8c7bd89
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Release files / daphnis-0.1.1-py3-none-any.whl

Download URL daphnis-0.1.1-py3-none-any.whl
Size 81.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
653bb6f0b31a738d79b1d56a2ea76d02f4a42ac092bdae45ca4e6bbef98c0434
BLAKE2b-256 checksum
How to use checksums
8d877b7dda528b6ec9297268b62e63c7bb52ebbab346726031c5c8b38afcf663
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.7

Security for daphnis 0.1.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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No 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