Agently Docs

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

View the Project on GitHub AgentEra/Agently

Talk to Control

语言:English · 中文

问题

用户用自然语言控制某物 —— 文档、dashboard、记录集。每轮模型:

  1. 理解用户意图。
  2. 从固定集合选一个 action。
  3. 在当前域对象上执行该 action。
  4. 回复做了什么以及现在状态。

形态

用户输入  →  Agent(带 action)→ action 调用 → 更新 state → 回复
                       ▲
                       │
                  Session(多轮历史)

本质上是带 action 的对话 agent。除非每轮内有多步过程,否则不需要 TriggerFlow。

走读

from agently import Agently

agent = (
    Agently.create_agent()
    .role("你控制一个购物车。用可用 action 修改它。", always=True)
    .info({"format": "每个 action 后简短确认改了什么。"}, always=True)
)

# demo 用的内存购物车
cart = {"items": [], "total": 0.0}


@agent.action_func
def add_item(name: str, price: float, quantity: int = 1):
    """加一个商品到购物车。"""
    cart["items"].append({"name": name, "price": price, "quantity": quantity})
    cart["total"] += price * quantity
    return cart


@agent.action_func
def remove_item(name: str):
    """从购物车移除一个商品。"""
    cart["items"] = [i for i in cart["items"] if i["name"] != name]
    cart["total"] = sum(i["price"] * i["quantity"] for i in cart["items"])
    return cart


@agent.action_func
def show_cart():
    """返回当前购物车。"""
    return cart


agent.use_actions([add_item, remove_item, show_cart])

# 启用 session,让多轮上下文受限
agent.activate_session(session_id="cart-demo")

# 对话循环
while True:
    user_text = input("> ")
    if not user_text.strip():
        break
    reply = agent.input(user_text).start()
    print(reply)

为什么这么选

变体

流式回复

UI 用流式让用户在生成时就看到:

gen = agent.input(user_text).get_generator(type="delta")
for delta in gen:
    print(delta, end="", flush=True)

流式选项见 模型响应

加结构化旁路

UI 需要知道哪个 action 跑了(高亮某行、动画等),每轮后读 agent.get_action_result()

records = agent.get_action_result()
for r in records:
    notify_ui(action=r.name, args=r.input, result=r.output)

单轮多步

单条用户消息触发多步过程(lookup → confirm → apply)时,把每轮处理升到 TriggerFlow。对话层仍在 agent;flow 在一轮内跑。见 TriggerFlow 编排 Playbook

交叉链接