AgentKnowledgeAgentKnowledgeAgentKnowledge
知识文档AI热点经典好文
AgentKnowledgeAgentKnowledgeAgentKnowledge

深入 Agent,构建你的专属。致力于打造体系化的 AI Agent 开发者学习平台。

学习路径

DocsAI BasicsAgent 工具Agent 实战

社区

GitHub

账号

User CenterLogin

© 2026 AgentKnowledge.cn. 保留所有权利。

  • Agent
  • System Prompt
  • Prompt
  • Prompt Engineering
  • Zero-shot / Few-shot
  • Chain of Thought(CoT)
  • ReAct
  • SKILL(Agent技能)
  • Memory(Agent记忆)
  • RAG
  • Retrieval
  • Embedding
  • Embedding Model
  • Vector Database
  • Cosine Similarity
  • MCP(Model Context Protocol)
  • Tool Calling
  • Function Schema
  • Structured Output
  • OpenClaw
  • Harness Engineering(驾驭工程)
  • Token
  • Context Window
  • Temperature
  • Top-p
  • Transformer 架构
  • 向量数据库
  • Embedding 模型
  • 数据源接入
  • Web Search
  • Memory 系统
  • Function Calling
  • 实战沙箱
  • Function Schema

    为什么需要 Function Schema

    让 Agent 调用工具,不是"写一段代码给模型",而是"告诉模型这个工具是干什么的、该怎么用"。

    模型不会直接读你的代码,它是通过你提供的描述来判断:

    • 这个工具什么时候该用
    • 该传什么参数
    • 参数格式应该是怎样的

    Function Schema 就是这份"使用说明书"——它的质量直接决定了 Tool Calling 是否正确。


    什么是 Function Schema

    一句话定义:Function Schema 是对工具能力的结构化描述,是模型调用工具时的"参数契约"。

    一个典型的 Schema 长这样:

    {
      "name": "get_weather",
      "description": "查询指定城市的当前天气",
      "parameters": {
        "type": "object",
        "properties": {
          "city": {
            "type": "string",
            "description": "城市名称,如北京、上海"
          },
          "unit": {
            "type": "string",
            "enum": ["celsius", "fahrenheit"],
            "description": "温度单位"
          }
        },
        "required": ["city"]
      }
    }
    

    模型看到这个 Schema 后,就知道:

    • 工具叫 get_weather,是查天气的
    • 必填参数是 city
    • unit 只能填 celsius 或 fahrenheit

    怎么做:怎么写好 Schema

    description 要说清使用场景:不要只写"获取数据",要写清楚什么时候该用它。

    参数名要具体:city 比 input 更好,invoice_id 比 id 更好。

    只把真正必要的字段设为 required:否则模型更容易因为缺参而失败。

    能枚举就枚举:对有限选项用 enum 明确约束。

    层级不要太深:嵌套结构越复杂,模型越容易出错。


    记住这一句:Function Schema 首先是给模型看的,不是给程序看的——它的核心价值是让模型准确理解"什么时候用、怎么用"。

    相关词条:Tool Calling

    相关词条

    Tool CallingStructured OutputMCP(Model Context Protocol)

    标签

    函数模式函数签名tool schemafunction definitionJSON schema

    目录

    为什么需要 Function Schema什么是 Function Schema怎么做:怎么写好 Schema