diff options
| author | Grail Finder <wohilas@gmail.com> | 2025-12-19 15:39:55 +0300 |
|---|---|---|
| committer | Grail Finder <wohilas@gmail.com> | 2025-12-19 15:39:55 +0300 |
| commit | f779f039745f97f08f25967214d07716ce213326 (patch) | |
| tree | 9868dfe5e77845e27d4fe8b36f993a5fade2ea7b /tools.go | |
| parent | a875abcf198dd2f85c518f8bf2c599db66d3e69f (diff) | |
Enha: agent request builder
Diffstat (limited to 'tools.go')
| -rw-r--r-- | tools.go | 52 |
1 files changed, 40 insertions, 12 deletions
@@ -13,6 +13,7 @@ import ( "regexp" "strconv" "strings" + "sync" "time" ) @@ -126,7 +127,9 @@ under the topic: Adam's number is stored: </example_response> After that you are free to respond to the user. ` - basicCard = &models.CharCard{ + webSearchSysPrompt = `Summarize the web search results, extracting key information and presenting a concise answer. Provide sources and URLs where relevant.` + readURLSysPrompt = `Extract and summarize the content from the webpage. Provide key information, main points, and any relevant details.` + basicCard = &models.CharCard{ SysPrompt: basicSysMsg, FirstMsg: defaultFirstMsg, Role: "", @@ -141,8 +144,43 @@ After that you are free to respond to the user. // sysMap = map[string]string{"basic_sys": basicSysMsg, "tool_sys": toolSysMsg} sysMap = map[string]*models.CharCard{"basic_sys": basicCard} sysLabels = []string{"basic_sys"} + + webAgentClient *agent.AgentClient + webAgentClientOnce sync.Once + webAgentsOnce sync.Once ) +// getWebAgentClient returns a singleton AgentClient for web agents. +func getWebAgentClient() *agent.AgentClient { + webAgentClientOnce.Do(func() { + if cfg == nil { + panic("cfg not initialized") + } + if logger == nil { + panic("logger not initialized") + } + getToken := func() string { + if chunkParser == nil { + return "" + } + return chunkParser.GetToken() + } + webAgentClient = agent.NewAgentClient(cfg, *logger, getToken) + }) + return webAgentClient +} + +// registerWebAgents registers WebAgentB instances for websearch and read_url tools. +func registerWebAgents() { + webAgentsOnce.Do(func() { + client := getWebAgentClient() + // Register websearch agent + agent.Register("websearch", agent.NewWebAgentB(client, webSearchSysPrompt)) + // Register read_url agent + agent.Register("read_url", agent.NewWebAgentB(client, readURLSysPrompt)) + }) +} + // web search (depends on extra server) func websearch(args map[string]string) []byte { // make http request return bytes @@ -597,7 +635,6 @@ var globalTodoList = TodoList{ Items: []TodoItem{}, } - // Todo Management Tools func todoCreate(args map[string]string) []byte { task, ok := args["task"] @@ -851,6 +888,7 @@ var fnMap = map[string]fnSig{ // callToolWithAgent calls the tool and applies any registered agent. func callToolWithAgent(name string, args map[string]string) []byte { + registerWebAgents() f, ok := fnMap[name] if !ok { return []byte(fmt.Sprintf("tool %s not found", name)) @@ -862,16 +900,6 @@ func callToolWithAgent(name string, args map[string]string) []byte { return raw } -// registerDefaultAgents registers default agents for formatting. -func registerDefaultAgents() { - agent.Register("websearch", agent.DefaultFormatter("websearch")) - agent.Register("read_url", agent.DefaultFormatter("read_url")) -} - -func init() { - registerDefaultAgents() -} - // openai style def var baseTools = []models.Tool{ // websearch |
