mergeNewToolNames returns activeTools augmented with any tool names from newTools that are not present in oldTools and not already in activeTools. This keeps newly injected tools (e.g. via PrepareTools) callable even when activeTools is non-empty. When activeTools is empty, all tools are already ac
(activeTools []string, oldTools, newTools []fantasy.AgentTool)
| 1840 | // When activeTools is empty, all tools are already active and the slice |
| 1841 | // is returned unchanged. |
| 1842 | func mergeNewToolNames(activeTools []string, oldTools, newTools []fantasy.AgentTool) []string { |
| 1843 | if len(activeTools) == 0 { |
| 1844 | return activeTools |
| 1845 | } |
| 1846 | old := make(map[string]struct{}, len(oldTools)) |
| 1847 | for _, t := range oldTools { |
| 1848 | old[t.Info().Name] = struct{}{} |
| 1849 | } |
| 1850 | active := make(map[string]struct{}, len(activeTools)) |
| 1851 | for _, name := range activeTools { |
| 1852 | active[name] = struct{}{} |
| 1853 | } |
| 1854 | for _, t := range newTools { |
| 1855 | name := t.Info().Name |
| 1856 | if _, alreadyActive := active[name]; alreadyActive { |
| 1857 | continue |
| 1858 | } |
| 1859 | if _, existedBefore := old[name]; existedBefore { |
| 1860 | continue |
| 1861 | } |
| 1862 | activeTools = append(activeTools, name) |
| 1863 | active[name] = struct{}{} |
| 1864 | } |
| 1865 | return activeTools |
| 1866 | } |
| 1867 | |
| 1868 | // buildToolDefinitions converts AgentTool definitions into the |
| 1869 | // fantasy.Tool slice expected by fantasy.Call. When activeTools |