智能体引擎

预算

信贷上限,在每一步骤之前和在每一支付工具之前进行检查,这是值得设定的上限——步骤是离家出走的警卫,信贷是账单。

budget: null by defaultchecked before the stepshared with subagents
Using Python?

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

设置它

const agent = api.agents.create({
  runtime: "local",
  machine: pc,
  model: "gemini-3.5-flash",
  budget: 200,          // credits for this run
  maxSteps: 40,         // and a step ceiling, lower than the default 100
});
agent = api.agents.create(
    runtime="local",
    machine=pc,
    model="gemini-3.5-flash",
    budget=200,          # credits for this run
    max_steps=40,        # and a step ceiling, lower than the default 100
)

检查时

暂停比较比较
每步的顶部迄今的信贷支出 budget。相等或以上 stopReason: "budget".
支付工具之前工具的申报成本 相对于剩下的。

两者都是 之前之后检查的预算只会告诉你你已经花的钱

罪过的,是罪它所加的;

  • 每一个跑步的转弯模型
  • 内容提要转转 缩压 运行。
  • 每个付费工具——搜索、网页捕捉、转换、生成图像、语义搜索。
  • 每一个转弯和每个分剂的每支工具的每支支支取
子代理商花父母的预算,而不是用自己的预算

其结果是,三个平行工作的分剂被捆绑在一起。 预算只约束父母自己的转手,几乎不会约束任何分剂。

可以通过一个电话传递

检查发生在一步前,所以允许的一步仍然可能花费比剩下的一步——一个长转,或一个实际成本超过申报成本的工具——的成本还要高。 停止停止而不是准确的总数

const result = await agent.run({ inputs: "…", });

if (result.stopReason === "budget") {
  console.log(result.usage.credits, "spent of a", 200, "budget");
  // Slightly above is normal: the last step was allowed before it cost anything.
}
result = agent.run(inputs="…")

if result["stopReason"] == "budget":
    print(result["usage"]["credits"], "spent of a", 200, "budget")
    # Slightly above is normal: the last step was allowed before it cost anything.

媒体是预算赚取其经费的媒体

文字翻转是几小小分数;制作的视频是几十个。媒体工具宣布了故意高估成本,因此警卫可以拒绝。 之前 电话,见 视频视频.

看着它走动

await agent.run({
  inputs: "…",
  onEvent: (e) => {
    if (e.type === "turn") {
      console.log(`${e.totalCredits} credits so far`);
    }
  },
});
def on_event(event):
    if event["type"] == "tool_end":
        print(f"{agent.usage['credits']} credits so far")

agent.run(inputs="…", on_event=on_event)
总额负债已经包括工具

转转事件的运行总数计为运行中已付工具以及转转。添加工具本身 meta.credits 账户工具所读取的余额根本不是成本。

无预算

budget: null 默认值是默认值,运行时只受 maxSteps 并且模型愿意停止。 这对互动代理人员来说是合理的;对于无人看管的任何事物来说都是不合理的。