工具全生命周期:注解→注册→schema→装配→执行

工具全生命周期:注解→注册→schema→装配→执行 由 Archify 生成的工作流图。 01 / 定义与注册 02 / 请求装配 03 / 执行归一 定义扫描 schema 与装配 调用执行 注解类+扫描 · @FunctionCall→Reflections · 定义与注册 › 定义扫描 注解类+扫描 @FunctionCall→Reflections 工具注册表 · toolEntityMap 三表 · 定义与注册 › 定义扫描 工具注册表 toolEntityMap 三表 JsonSchemaGen · 类→JSON Schema · 请求装配 › 定义扫描 JsonSchemaGen 类→JSON Schema getAllTools · 显式工具集 · 请求装配 › schema 与装配 getAllTools 显式工具集 ChatCompletion · tools 入请求 · 请求装配 › schema 与装配 ChatCompletion tools 入请求 tool_calls · 模型裁决 · 执行归一 › schema 与装配 tool_calls 模型裁决 invoke→tool 回填 · 三路分发 · 执行归一 › 调用执行 invoke→tool 回填 三路分发 注册三张 map Tool+请求类 parameters 装入 tools 模型返回 invoke 执行 图例 Agent 逻辑 策略 上下文 / 追踪 外部系统

扫描与懒初始化

  • • ensureInitialized 双检锁懒触发:scanFunctionTools 按注解入 toolEntityMap/toolClassMap/toolRequestMap
  • • scanMcpTools 反射调 McpGateway.getAvailableTools——未初始化网关时安全跳过

schema 生成

  • • JsonSchemaGenerator.generate(Class) 纯反射产 JSON Schema,无外部依赖;responseFormat 同样由其生成
  • • @FunctionCall.strict=true 时参数标 strict——与 provider 结构化输出对齐

显式工具面

  • • getAllTools(functionList, mcpServerIds) 只装声明过的工具;空列表即无工具调用能力
  • • invoke 三路分发:内置→BuiltInToolExecutor · MCP→callTool · 函数→newInstance+method.invoke