当地代理

概览

什麽 api.agents.create({ runtime: "local" }) 返回:代理循环作为您持有、运行、停止、检查和回放的对象。

8 methodsthe loop is hereread its state as it works
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

方法功能
运行( 选项)交换一个:你的信息,答案。
( 停止)结束当前运行 。
设置 mode( 模式)更改模式, 中跑, 包括子试剂 。
白 字 ()总结了谈话现在。
获取历史()谈话,显示形状。
() (检查站)回到你能够回到的地方
反后(n)回到一条留言。
(销毁)删除会话。
const agent = api.agents.create({ runtime: "local", machine: pc, model, memory: true });

const result = await agent.run({
  message: "Read the notes and list what is unfinished.",
  onEvent: (e) => { if (e.type === "text_delta") process.stdout.write(e.delta); },
});

console.log(agent.usage, agent.context.tokens, result.stopReason);
agent = api.agents.create(runtime="local", machine=pc, model=model, memory=True)

result = agent.run(
    message="Read the notes and list what is unfinished.",
    on_event=lambda e: print(e["text"]) if e["type"] == "text" else None,
)

print(agent.usage, agent.context["tokens"], result["stopReason"])

运行 () 是一次交换, 不是一项任务

它将需要您的信息,循环直到模型停止要求工具,然后返回。再拨它继续同样的对话——对象将保留历史。

对象为可重复使用,而不是同时

一次一个跑

第二次运行( ) , 而在飞行中的人则共享相同的电文列表和相同的使用计数器。 等待第一个, 或者建立第二个代理 。

工作时您可以读取状态

usage, context, todos, mode 和 messages 。一个界面可以对它们进行民意测验或倾听 事件事件事件更便宜更精确