buildToolDefinitions converts AgentTool definitions into the fantasy.Tool slice expected by fantasy.Call. When activeTools is non-empty, only function tools whose name appears in the list are included. Provider tool definitions are always appended unconditionally.
(tools []fantasy.AgentTool, activeTools []string, providerTools []ProviderTool)
| 1871 | // list are included. Provider tool definitions are always |
| 1872 | // appended unconditionally. |
| 1873 | func buildToolDefinitions(tools []fantasy.AgentTool, activeTools []string, providerTools []ProviderTool) []fantasy.Tool { |
| 1874 | prepared := make([]fantasy.Tool, 0, len(tools)+len(providerTools)) |
| 1875 | for _, tool := range tools { |
| 1876 | info := tool.Info() |
| 1877 | if !isToolActive(info.Name, activeTools) { |
| 1878 | continue |
| 1879 | } |
| 1880 | |
| 1881 | inputSchema := map[string]any{ |
| 1882 | "type": "object", |
| 1883 | "properties": info.Parameters, |
| 1884 | } |
| 1885 | // Only include "required" when non-empty so that a nil slice |
| 1886 | // never serializes to null, which OpenAI rejects. |
| 1887 | if len(info.Required) > 0 { |
| 1888 | inputSchema["required"] = info.Required |
| 1889 | } |
| 1890 | schema.Normalize(inputSchema) |
| 1891 | prepared = append(prepared, fantasy.FunctionTool{ |
| 1892 | Name: info.Name, |
| 1893 | Description: info.Description, |
| 1894 | InputSchema: inputSchema, |
| 1895 | ProviderOptions: tool.ProviderOptions(), |
| 1896 | }) |
| 1897 | } |
| 1898 | for _, pt := range providerTools { |
| 1899 | prepared = append(prepared, pt.Definition) |
| 1900 | } |
| 1901 | return prepared |
| 1902 | } |
| 1903 | |
| 1904 | // shouldStopAfterTools returns true if any tool result in the |
| 1905 | // slice matches a name in stopTools and produced a successful |
no test coverage detected