Skip to content

Commit dcc3272

Browse files
authored
feat(agent): remind model to confirm metric caliber before writing SQL (#139)
Append METRIC_CALIBER_REMINDER to get_tables / get_table_schema output: the model reads table structure right before composing SQL, so prompting there beats the system prompt. If the datasource defines no metrics, get_metric_caliber simply reports none and the model moves on.
1 parent d9e3ea3 commit dcc3272

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎data-agent-backend/src/main/java/io/github/malonetalk/agent/tools/GetTableSchemaTool.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public ToolResultBlock getTableSchema(
5959
columnSemanticService.getMergedTableSchema(
6060
datasource.getId(), tableName);
6161
return ToolResultBlock.text(
62-
SemanticUtils.formatTableSchema(tableName, columns));
62+
SemanticUtils.formatTableSchema(tableName, columns)
63+
+ ToolCallConstants.METRIC_CALIBER_REMINDER);
6364
});
6465
}
6566
}

‎data-agent-backend/src/main/java/io/github/malonetalk/agent/tools/GetTablesTool.java‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ public ToolResultBlock getTables(
6363
dataSourceService.getDatasourceForSession(ctx.sessionId());
6464
return ToolResultBlock.text(
6565
JsonUtils.getJsonCodec()
66-
.toJson(
67-
tableSemanticService.listMergedTablesByDomains(
68-
dataSource.getId(), domains)));
66+
.toJson(
67+
tableSemanticService.listMergedTablesByDomains(
68+
dataSource.getId(), domains))
69+
+ ToolCallConstants.METRIC_CALIBER_REMINDER);
6970
});
7071
}
7172
}

‎data-agent-backend/src/main/java/io/github/malonetalk/agent/tools/ToolCallConstants.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ private ToolCallConstants() {
2929

3030
public static final String SUCCESS = "SUCCESS";
3131

32+
/**
33+
* 追加在 get_tables / get_table_schema 的返回结果末尾。模型写 SQL 前基本必看表结构,
34+
* 在那个时机提醒「先确认指标口径」比在 system prompt 里说更准——此时它正准备动笔。
35+
* 数据源没定义任何指标时,get_metric_caliber 会回「未定义」,模型自然跳过。
36+
*/
37+
public static final String METRIC_CALIBER_REMINDER =
38+
"""
39+
40+
If the question involves a business metric, call get_metric_caliber to confirm its \
41+
caliber before writing SQL.\
42+
""";
43+
3244
public static final String SEPARATOR = ": ";
3345

3446
public static final String SUCCESS_PREFIX = SUCCESS + SEPARATOR;

0 commit comments

Comments
 (0)