Agently Docs

Agently documentation for building AI applications with stable outputs, observable actions, and durable workflows.

View the Project on GitHub AgentEra/Agently

Async First

语言:English · 中文

Agently 在运行时层是 async-native。Sync 方法是通过 FunctionShifter.syncify() 从 async 方法生成的便捷封装。一旦做真实服务,async 应该是默认路径。

什么时候 sync 也行

什么时候 async 是默认

推荐组合

最值得先掌握的组合:

instant 事件是字段级的:每条都在该叶子完整解析之后才到,下游永远拿不到半截字符串。

API 对照

Sync Async 等价
agent.start() / request.start() agent.async_start() / request.async_start()
response.get_data() response.async_get_data()
response.get_text() response.async_get_text()
response.get_meta() response.async_get_meta()
response.get_generator(type=...) response.get_async_generator(type=...)
flow.start() flow.async_start()
execution.start() / execution.close() execution.async_start() / execution.async_close()
data.set_state(...) / data.emit(...) data.async_set_state(...) / data.async_emit(...)

最小 async 示例

import asyncio
from agently import Agently

agent = Agently.create_agent()


async def main():
    response = (
        agent
        .input("给我一个标题和两条要点。")
        .output({
            "title": (str, "标题", True),
            "items": [(str, "要点", True)],
        })
        .get_response()
    )

    async for item in response.get_async_generator(type="instant"):
        if item.is_complete:
            print(item.path, item.value)

    final = await response.async_get_data()
    print(final)


asyncio.run(main())

get_response() 返回一个可复用的 ModelResponse。你可以从同一个 response 拿 text、结构化 data 和 metadata,不会重发请求——见 模型响应

Async + TriggerFlow

事件驱动编排时优先用:

详见 TriggerFlow Lifecycle

不要过度宣传 async

Async First 改善的是并发性、服务组合质量和渐进式 UX。它不会让单次请求的模型延迟变低——单次请求的墙钟时延由模型决定,与 sync/async 无关。