Skip to content

Async Support

Agently is async-first. Model requests, result access, TriggerFlow orchestration, and runtime streams all provide async variants, which is ideal for web services and high concurrency.

We recommend using the async methods inside your own async runtime (for example, FastAPI) to achieve higher concurrency. In the examples across the docs, any sync method that has a direct async counterpart in the list below can be replaced with its async version.

Async API checklist

Below are the public async-facing methods and async generator entries, grouped by object:

Agent / Request

Agently.create_agent() and Agently.create_request() expose the same async methods.

  • agent.async_start()
  • agent.async_get_text()
  • agent.async_get_data()
  • agent.async_get_data_object()
  • agent.async_get_meta()
  • agent.get_async_generator(...)

ModelResponse / ModelResponseResult

  • response.async_get_text()
  • response.async_get_data()
  • response.async_get_data_object()
  • response.async_get_meta()
  • response.get_async_generator(...)

TriggerFlow (Flow)

  • flow.async_start(...)
  • flow.async_start_execution(...)
  • flow.async_set_flow_data(...)
  • flow.async_append_flow_data(...)
  • flow.async_del_flow_data(...)
  • flow.get_async_runtime_stream(...)

TriggerFlow (Execution)

  • execution.async_start(...)
  • execution.async_get_result(...)
  • execution.async_emit(...)
  • execution.async_set_runtime_data(...)
  • execution.async_append_runtime_data(...)
  • execution.async_del_runtime_data(...)
  • execution.async_put_into_stream(...)
  • execution.async_stop_stream(...)
  • execution.get_async_runtime_stream(...)

TriggerFlowEventData (inside chunks)

  • data.async_emit(...)
  • data.async_set_runtime_data(...)
  • data.async_append_runtime_data(...)
  • data.async_del_runtime_data(...)
  • data.async_set_flow_data(...)
  • data.async_append_flow_data(...)
  • data.async_del_flow_data(...)
  • data.async_put_into_stream(...)
  • data.async_stop_stream(...)

Tools & MCP

  • agent.async_use_mcp(...)

KeyWaiter

  • agent.async_get_key_result(...)
  • agent.async_wait_keys(...)
  • agent.async_start_waiter(...)

Session / Memo

  • session.async_judge_resize(...)
  • session.async_resize(...)

Minimal example

python
import asyncio
from agently import Agently

agent = Agently.create_agent()

async def main():
  response = (
    agent
    .input("Explain observability in one sentence")
    .output({"intro": ("str", "One-line summary")})
    .get_response()
  )
  data = await response.async_get_data()
  print(data)

asyncio.run(main())