kaboo_workflows.tools¶
Tool discovery, loading, and node-as-tool adapters.
kaboo_workflows.tools ¶
Tool loading and wrapping utilities.
Provides helpers for:
- Loading @tool-decorated functions from files, modules, and directories.
- Wrapping Agent / MultiAgentBase nodes as AgentTool instances
(node_as_tool, node_as_async_tool) for delegation.
- Serializing multi-agent results with full execution metadata.
ConfiguredReferenceFetcher ¶
ConfiguredReferenceFetcher(
*, base_url=None, authorization=None
)
Fetcher built from attachments.base_url / attachments.authorization.
- Relative URLs (
/attachments/…) resolve againstbase_url. - The authorization token is attached only to URLs under
base_url; any other URL is fetched with the unauthenticated default, so host credentials never leak to third-party origins.
authorization spec formats:
forwarded_props:<key>— read the token from the current run's forwarded props (a run-scoped credential the host sends per invocation).env:<VAR>— read a static token from the environment.
Source code in src/kaboo_workflows/tools/fetching.py
132 133 134 | |
ReferenceFetcher ¶
Bases: Protocol
Strategy for resolving a reference URL to raw bytes.
Implementations return None on any failure (the caller treats the
reference as unresolvable). reference is provided when the fetch is on
behalf of a parsed reference; URL-only call sites (entry-message media
parts) pass None.
serialize_multiagent_result ¶
serialize_multiagent_result(result)
Serialize a MultiAgentResult with execution metadata omitted by to_dict().
Extends result.to_dict() with fields only available on the live object:
last_node_id— id of the truly last executing node, derived fromnode_history/execution_order(not dict insertion order).response— plain-text answer from that node, ready to use directly without any further extraction.swarm.node_history— full ordered execution trace including repeated visits (SwarmResultonly).graph.execution_order,graph.edges,graph.entry_points, and node counts (GraphResultonly).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
MultiAgentResult
|
A live |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A JSON-serializable dict extending |
Source code in src/kaboo_workflows/tools/extractors.py
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 | |
fetch_reference_bytes ¶
fetch_reference_bytes(url, *, reference=None)
Fetch reference bytes via the registered fetcher (default when none).
Source code in src/kaboo_workflows/tools/fetching.py
88 89 90 91 92 | |
get_reference_fetcher ¶
get_reference_fetcher()
Return the registered reference fetcher (None when default).
Source code in src/kaboo_workflows/tools/fetching.py
83 84 85 | |
set_reference_fetcher ¶
set_reference_fetcher(fetcher)
Register the process-wide reference fetcher (None restores default).
Call once at startup, before the app serves requests. Per-run behavior belongs inside the fetcher (read the request context there), not in re-registration.
Source code in src/kaboo_workflows/tools/fetching.py
68 69 70 71 72 73 74 75 76 77 78 79 80 | |
load_tool_function ¶
load_tool_function(spec)
Load a specific tool function from a module.
If the named function is already decorated with @tool it is returned
as-is. If it is a plain callable it is automatically wrapped with
@tool and a warning is logged — users should consider adding the
decorator explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
str
|
Colon-separated string in "module.path:function_name" format. |
required |
Returns:
| Type | Description |
|---|---|
AgentTool
|
An |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the spec format is invalid. |
ImportError
|
If the module cannot be imported. |
AttributeError
|
If the function does not exist in the module. |
TypeError
|
If the named attribute is not callable. |
Source code in src/kaboo_workflows/tools/loaders.py
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 | |
load_tools_from_directory ¶
load_tools_from_directory(path)
Load all @tool functions from .py files in a directory.
Scans all .py files (excluding _-prefixed) and loads their tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Directory path to scan. |
required |
Returns:
| Type | Description |
|---|---|
list[AgentTool]
|
List of AgentTool instances from all files in the directory. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the directory does not exist. |
NotADirectoryError
|
If the path is not a directory. |
Source code in src/kaboo_workflows/tools/loaders.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
load_tools_from_file ¶
load_tools_from_file(path)
Load tools from a Python file.
Imports the file as a module and collects all @tool-decorated objects.
Plain functions without the @tool decorator are silently ignored —
users must decorate their functions explicitly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a .py file containing tool functions. |
required |
Returns:
| Type | Description |
|---|---|
list[AgentTool]
|
List of AgentTool instances found in the file. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the file does not exist. |
ImportError
|
If the file cannot be loaded as a module. |
Source code in src/kaboo_workflows/tools/loaders.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | |
load_tools_from_module ¶
load_tools_from_module(module_path)
Load tools from a Python module.
First scans for @tool-decorated functions. If none are found,
falls back to the strands module-based tool pattern (TOOL_SPEC dict
+ a function named after the module). This ensures compatibility with
tools like strands_tools.http_request that use the legacy pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_path
|
str
|
Dotted import path (e.g., "my_package.tools"). |
required |
Returns:
| Type | Description |
|---|---|
list[AgentTool]
|
List of AgentTool instances found in the module. |
Raises:
| Type | Description |
|---|---|
ImportError
|
If the module cannot be imported. |
AttributeError
|
If the module contains neither |
Source code in src/kaboo_workflows/tools/loaders.py
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 | |
resolve_tool_spec ¶
resolve_tool_spec(spec)
Resolve a tool specification string to tool objects.
Supported formats (checked in order):
"./path/to/file.py:function_name"— single tool from a file"./path/to/dir/"or"./path/to/dir"(is a directory) — all tools in dir"./path/to/file.py"or"path/to/file.py"— all tools from file"module.path:function_name"— single tool from module"module.path"— all tools from module
The heuristic for path vs. module: if the spec contains /, \\, or
ends with .py (before any :) it is treated as a filesystem path.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
str
|
Tool specification string. |
required |
Returns:
| Type | Description |
|---|---|
list[AgentTool]
|
List of tool objects. |
Source code in src/kaboo_workflows/tools/loaders.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 | |
resolve_tool_specs ¶
resolve_tool_specs(specs)
Resolve a list of tool specification strings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
specs
|
list[str]
|
List of tool specification strings. |
required |
Returns:
| Type | Description |
|---|---|
list[AgentTool]
|
Flat list of all resolved tool objects. |
Source code in src/kaboo_workflows/tools/loaders.py
247 248 249 250 251 252 253 254 255 256 257 258 259 | |
fetch_attachment ¶
fetch_attachment(reference_id)
Fetch a file attachment's contents by its id.
Text-like files (txt, md, csv, html, json, xml) are returned as text. Images, PDFs/office docs, and video are placed into the conversation as media the model can see directly — the tool confirms in text and the file appears in context on the next turn. Non-file references (custom entities) are not fetchable here — resolve those with the tool provided for their kind.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reference_id
|
str
|
The reference id from the manifest / |
required |
Source code in src/kaboo_workflows/tools/references.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | |
list_references ¶
list_references()
List the files and items the user attached or referenced this turn.
Returns each reference's kind, name, id, and transport so you can pick which
one to fetch or query. Use the id with fetch_attachment (files) or the
kind's dedicated tool (custom items).
Source code in src/kaboo_workflows/tools/references.py
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 | |
node_as_async_tool ¶
node_as_async_tool(node, *, name=None, description)
Wrap an Agent or MultiAgentBase as an async AgentTool for delegation.
Source code in src/kaboo_workflows/tools/wrappers.py
151 152 153 154 155 156 157 158 | |
node_as_tool ¶
node_as_tool(node, *, name=None, description)
Wrap an Agent or MultiAgentBase as a sync AgentTool for delegation.
Source code in src/kaboo_workflows/tools/wrappers.py
141 142 143 144 145 146 147 148 | |