Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Building a Real Multi-Step AI Agent with Gemini Function Calling (Not Just a Chatbot)

说明与用途

使用 Gemini 函数调用构建多步 AI 代理,设置步骤上限并支持实时流式传输。

问题

Create an AI agent that can iteratively call tools and decide when to answer, rather than a single-shot chatbot.

结果

A reusable starter kit demonstrates a multi‑step AI agent with tool calling, step limits, and optional streaming.

工作流

  • Define tool schemas (e.g., calculator)
  • Implement runAgentLoop that calls model.generateContent with tools
  • If result has no functionCalls, return final text
  • For each functionCall, execute runTool and append result to messages
  • Repeat until final answer or MAX_STEPS reached
  • Optionally stream each step via Server‑Sent Events

证据

Most "AI chat" tutorials stop at single-shot request/response. You send a message, the model replies, done.

来源

Without a cap, a confused model could theoretically call tools in a loop forever. MAX_STEPS is a safety valve, not an optimization — it guarantees the request always terminates.

来源

Rather than making the user wait for the whole loop to finish, you can stream each step as it happens using Server‑Sent Events — the user sees "calling calculator... got 564... calling get_current_time..." live, instead of a blank spinner.

来源

  • 记录日期: 2026-10-01T21:55:51.682Z