refactor(agent): Pi 会话运行时 - 接入原生 Agent 与 Skills 工具链
This commit is contained in:
1 parent
f9b8c5a43e
commit
387d3562ad
69 files changed
+11460
-207
No files matched your search
@@ -84,6 +84,8 @@ func expandCanonicalAgentRequest(source *canonicalAgentRequest, config providerC
|
||||
}
|
||||
request := *source
|
||||
request.Messages = messages
|
||||
// 同名工具会被多数供应商直接拒绝(400)。按名称去重,保留第一次出现的定义。
|
||||
request.Tools = dedupeCanonicalAgentTools(source.Tools)
|
||||
result := &agentToolRequests{}
|
||||
if declarative {
|
||||
result.ChatCompletion = canonicalAgentChatBody(&request, false)
|
||||
@@ -423,3 +425,18 @@ func canonicalAgentText(content interface{}) string {
|
||||
}
|
||||
return strings.Join(texts, "\n")
|
||||
}
|
||||
|
||||
func dedupeCanonicalAgentTools(tools []map[string]interface{}) []map[string]interface{} {
|
||||
seen := make(map[string]bool, len(tools))
|
||||
result := make([]map[string]interface{}, 0, len(tools))
|
||||
for _, tool := range tools {
|
||||
function, _ := tool["function"].(map[string]interface{})
|
||||
name := stringField(function, "name")
|
||||
if seen[name] {
|
||||
continue
|
||||
}
|
||||
seen[name] = true
|
||||
result = append(result, tool)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in new issue
Block a user