+26
-3
@@ -10,6 +10,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
searchagent "aichat/agents/search"
|
||||
"aichat/contextwindow"
|
||||
"aichat/conversation"
|
||||
"aichat/llm"
|
||||
@@ -61,17 +62,39 @@ func (s *Server) switchOpenAIHandler(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Server) searchState() (*searchagent.State, bool) {
|
||||
if s == nil || s.toolManager == nil {
|
||||
return nil, false
|
||||
}
|
||||
raw, ok := s.toolManager.RawState(searchagent.ToolName)
|
||||
if !ok {
|
||||
return nil, false
|
||||
}
|
||||
state, ok := raw.(*searchagent.State)
|
||||
return state, ok && state != nil
|
||||
}
|
||||
|
||||
func (s *Server) listSearchHandler(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, s.searchState.ListProfiles())
|
||||
state, ok := s.searchState()
|
||||
if !ok {
|
||||
c.JSON(http.StatusOK, searchagent.ListResponse{})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, state.ListProfiles())
|
||||
}
|
||||
|
||||
func (s *Server) switchSearchHandler(c *gin.Context) {
|
||||
state, ok := s.searchState()
|
||||
if !ok {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "搜索工具未加载"})
|
||||
return
|
||||
}
|
||||
var req activeProfileRequest
|
||||
if err := c.ShouldBindJSON(&req); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "请求格式错误: " + err.Error()})
|
||||
return
|
||||
}
|
||||
profile, err := s.searchState.SwitchActive(req.Name)
|
||||
profile, err := state.SwitchActive(req.Name)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
||||
return
|
||||
@@ -219,7 +242,7 @@ func (s *Server) chatHandler(c *gin.Context) {
|
||||
contextMessages = chatWindow.ChatMessages
|
||||
|
||||
// 用 Function Calling 工具循环替代旧的路由+隐藏上下文机制
|
||||
messages, err := toolrouter.RunAgentToolLoop(ctx, s.toolRouterState, profile, contextMessages, s.searchState, s.sqlState, emit)
|
||||
messages, err := toolrouter.RunAgentToolLoop(ctx, s.toolRouterState, profile, contextMessages, s.toolManager, emit)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, "Agent 工具循环失败:", err)
|
||||
messages, err = message.BuildArkMessages(contextMessages)
|
||||
|
||||
Reference in New Issue
Block a user