
期待的结果查询具体的属性或者分类直接给出ECSQL及查找结果1 elastic search存储用于搜索和语义匹配的元数据索引步骤打开 checkpointSnapshotDb读取 schema / class / property / label / codevalue过滤掉明显不适合检索的内容只保留有用的元数据和少量示例值生成 property / userlabel / codevalue 三类文档再写入 Elasticsearch过滤的规则是考虑抽象类不收空类不收无效/不适合查找的属性不收只保留少量示例值不会把无穷多实例值全存进去重点保留的是“属性定义”和“语义标签”不是整张模型数据表结果npm run index:es -- bim路径 去写入npm run query:es 去验证结果2 Agent通过用户的输入LLM拆解需要的属性从ES中对应的表调用最后的ECSQl的生成器这里比较有意思我按照自己的想法去写agent后面Copilot给我建议说我写的是固定流程而不是真正意义的agent那么我问一个好的agent是怎么样的他给的答案是这样的理解目标→ 选择工具→ 观察结果→ 判断下一步→ 发现错误→ 分析原因→ 修正计划→ 再次执行→ 判断是否完成后面我就让Copilot来写~1 定义决策step这里给了10也就是表示 Agent 最多运行10 轮决策。第 1 步搜索属性第 2 步读取关系第 3 步生成 ECSQL第 4 步执行 ECSQL第 5 步总结结果防止agent无线循环2 Agent Toolssearch_metadata搜索 iModel 中相关的类和属性inspect_relationships 读取 iModel 中的类继承关系和 Relationship 关系generate_ecsql 根据类、属性和条件生成 ECSQLexecute_ecsql 执行已经生成的 ECSQLconst AGENT_TOOLS [ { type: function, function: { name: search_metadata, description: Search grounded iModel classes and properties for the users request., parameters: { type: object, properties: { query: { type: string, description: Terms to search for. } }, required: [query], additionalProperties: false, }, }, }, { type: function, function: { name: inspect_relationships, description: Load the iModel class inheritance and relationship graph., parameters: { type: object, properties: {}, additionalProperties: false }, }, }, { type: function, function: { name: generate_ecsql, description: Validate a grounded query plan and generate ECSQL. Search metadata first., parameters: { type: object, properties: { targetClasses: { type: array, items: { type: object } }, selectProperties: { type: array, items: { type: object } }, predicates: { type: array, items: { type: object } }, logicTree: { type: [object, string, null] }, queryIntent: { type: object }, reasoning: { type: string }, }, required: [targetClasses, selectProperties, predicates, logicTree], additionalProperties: false, }, }, }, { type: function, function: { name: execute_ecsql, description: Execute the ECSQL generated by generate_ecsql and return sample rows., parameters: { type: object, properties: {}, additionalProperties: false }, }, }, ];3 state它用来记录已经完成的步骤和中间结果保证后面的工具可以使用前面工具产生的数据4 回滚try { const args JSON.parse(toolCall.function?.arguments || {}); result { ok: true, result: await runner.run(name, args) }; } catch (error) { result { ok: false, error: error.message }; }这里如果失败是会把错误信息继续返回给Agent让模型自己决定下一步比如生成 ECSQL失败只要没有超过最大的步数就还可以继续→ AI 看到错误→ AI 换一个属性名→ 再次调用 generate_ecsql5 结果我单查询一个唯一属性的时候返回正确查询某个category下的所有属性会发现属性少了并且有个属性值会被修改a0另外还测试的一些别的情况还有不少问题等后面再慢慢摸索3 Agent还缺少的部分状态快照状态恢复每个工具独立重试次数错误分类恢复策略查询计划版本管理真正的 rollback/checkpoint 机制