The Wikipedia tool accepts lowercase language codes (including simple,
be-tarask, and zh-min-nan) and a non-empty page title. The configured endpoint
must use HTTPS on the selected language's exact <lang>.wikipedia.org host,
without credentials or a nonstandard port. Page titles are URL-encoded as a
single path segment. HTTP redirects are not followed; a redirected page request
returns an error and may need to be retried with its canonical title.
src.tools.implementations.wikipedia_tool.WikipediaTool
Bases: BaseRESTTool
Source code in src/tools/implementations/wikipedia_tool.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
__init__(config=None)
Initialize the WikipediaTool with configuration options.
Source code in src/tools/implementations/wikipedia_tool.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | |
execute(context=None, **kwargs)
async
Execute the Wikipedia API call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
Optional[ContextModel]
|
Additional context for the request. |
None
|
**kwargs
|
Should include: - query (str): The Wikipedia page title or search query. - lang (str, optional): The language code (default is "en"). |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
ToolResponse |
ToolResponse
|
The tool's response with the Wikipedia summary. |
Source code in src/tools/implementations/wikipedia_tool.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 | |
get_tool_specific_instruction()
Optional instructions to append to the output.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
Additional information. |
Source code in src/tools/implementations/wikipedia_tool.py
161 162 163 164 165 166 167 168 | |
parse_output(output)
Parse and format the Wikipedia API response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output
|
Any
|
Raw API response data. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A formatted string containing the page title, summary, and a link to the full page. |
Source code in src/tools/implementations/wikipedia_tool.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |