tools
Class info¶
Classes¶
Name | Children | Inherits |
---|---|---|
ToolContext llmling_agent.tools.base Context for tool execution confirmation. |
||
ToolInfo llmling_agent.tools.base Information about a registered tool. |
||
ToolManager llmling_agent.tools.manager Manages tool registration, enabling/disabling and access. |
🛈 DocStrings¶
Tool implementations and related classes / functions.
ToolContext
dataclass
¶
Context for tool execution confirmation.
Source code in src/llmling_agent/tools/base.py
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 |
|
__str__
¶
__str__() -> str
Format tool context for logging/display.
Source code in src/llmling_agent/tools/base.py
56 57 58 59 60 61 62 |
|
ToolInfo
dataclass
¶
Information about a registered tool.
Source code in src/llmling_agent/tools/base.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
agent_name
class-attribute
instance-attribute
¶
agent_name: str | None = None
The agent name as an identifier for agent-as-a-tool.
cache_enabled
class-attribute
instance-attribute
¶
cache_enabled: bool = False
Whether to enable caching for this tool.
enabled
class-attribute
instance-attribute
¶
enabled: bool = True
Whether the tool is currently enabled
metadata
class-attribute
instance-attribute
¶
Additional tool metadata
priority
class-attribute
instance-attribute
¶
priority: int = 100
Priority for tool execution (lower = higher priority)
requires_capability
class-attribute
instance-attribute
¶
requires_capability: str | None = None
Optional capability required to use this tool
requires_confirmation
class-attribute
instance-attribute
¶
requires_confirmation: bool = False
Whether tool execution needs explicit confirmation
source
class-attribute
instance-attribute
¶
source: ToolSource = 'runtime'
Where the tool came from.
execute
async
¶
Execute tool, handling both sync and async cases.
Source code in src/llmling_agent/tools/base.py
151 152 153 154 |
|
format_info
¶
Format complete tool information.
Source code in src/llmling_agent/tools/base.py
138 139 140 141 142 143 144 145 146 147 148 149 |
|
from_autogen_tool
classmethod
¶
from_autogen_tool(
tool: Any,
*,
name_override: str | None = None,
description_override: str | None = None,
schema_override: OpenAIFunctionDefinition | None = None,
**kwargs: Any,
) -> Self
Create a tool from a AutoGen tool.
Source code in src/llmling_agent/tools/base.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
|
from_code
classmethod
¶
Create a tool from a code string.
Source code in src/llmling_agent/tools/base.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
|
from_crewai_tool
classmethod
¶
from_crewai_tool(
tool: Any,
*,
name_override: str | None = None,
description_override: str | None = None,
schema_override: OpenAIFunctionDefinition | None = None,
**kwargs: Any,
) -> Self
Allows importing crewai tools.
Source code in src/llmling_agent/tools/base.py
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 |
|
from_langchain_tool
classmethod
¶
from_langchain_tool(
tool: Any,
*,
name_override: str | None = None,
description_override: str | None = None,
schema_override: OpenAIFunctionDefinition | None = None,
**kwargs: Any,
) -> Self
Create a tool from a LangChain tool.
Source code in src/llmling_agent/tools/base.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
|
matches_filter
¶
Check if tool matches state filter.
Source code in src/llmling_agent/tools/base.py
111 112 113 114 115 116 117 118 119 |
|
ToolManager
¶
Bases: BaseRegistry[str, ToolInfo]
Manages tool registration, enabling/disabling and access.
Inherits from BaseRegistry providing: - Dict-like access: manager["tool_name"] -> ToolInfo - Async startup/shutdown: await manager.startup() - Event observation: manager.add_observer(observer) - Registration: manager.register("tool_name", tool) - Listing: manager.list_items() - State check: manager.is_empty, manager.has_item() - Async iteration: async for name, tool in manager: ...
Source code in src/llmling_agent/tools/manager.py
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 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 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|
ToolStateReset
dataclass
¶
Emitted when tool states are reset.
Source code in src/llmling_agent/tools/manager.py
52 53 54 55 56 57 58 |
|
__init__
¶
Initialize tool manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools
|
Sequence[ToolInfo | ToolType | dict[str, Any]] | None
|
Initial tools to register |
None
|
Source code in src/llmling_agent/tools/manager.py
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
_validate_item
¶
Validate and convert items before registration.
Source code in src/llmling_agent/tools/manager.py
146 147 148 149 150 151 152 153 154 155 156 157 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 |
|
add_provider
¶
add_provider(provider: ResourceProvider | ResourceCallable, owner: str | None = None)
Add a resource provider or tool callable.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
provider
|
ResourceProvider | ResourceCallable
|
Either a ResourceProvider instance or a callable returning tools. Callables are automatically wrapped. |
required |
owner
|
str | None
|
Optional owner for the provider |
None
|
Source code in src/llmling_agent/tools/manager.py
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 |
|
disable_tool
¶
disable_tool(tool_name: str)
Disable a tool.
Source code in src/llmling_agent/tools/manager.py
194 195 196 197 198 199 200 201 202 |
|
enable_tool
¶
enable_tool(tool_name: str)
Enable a previously disabled tool.
Source code in src/llmling_agent/tools/manager.py
184 185 186 187 188 189 190 191 192 |
|
get_tool_names
async
¶
Get tool names based on state.
Source code in src/llmling_agent/tools/manager.py
236 237 238 |
|
get_tools
async
¶
Get tool objects based on filters.
Source code in src/llmling_agent/tools/manager.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
|
is_tool_enabled
¶
Check if a tool is currently enabled.
Source code in src/llmling_agent/tools/manager.py
204 205 206 |
|
list_tools
async
¶
Get a mapping of all tools and their enabled status.
Source code in src/llmling_agent/tools/manager.py
208 209 210 |
|
register_tool
¶
register_tool(
tool: ToolType | ToolInfo,
*,
name_override: str | None = None,
description_override: str | None = None,
enabled: bool = True,
source: ToolSource = "runtime",
priority: int = 100,
requires_confirmation: bool = False,
requires_capability: str | None = None,
metadata: dict[str, str] | None = None,
) -> ToolInfo
Register a new tool with custom settings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tool
|
ToolType | ToolInfo
|
Tool to register (callable, LLMCallableTool, or import path) |
required |
enabled
|
bool
|
Whether tool is initially enabled |
True
|
name_override
|
str | None
|
Optional name override for the tool |
None
|
description_override
|
str | None
|
Optional description override for the tool |
None
|
source
|
ToolSource
|
Tool source (runtime/agent/builtin/dynamic) |
'runtime'
|
priority
|
int
|
Execution priority (lower = higher priority) |
100
|
requires_confirmation
|
bool
|
Whether tool needs confirmation |
False
|
requires_capability
|
str | None
|
Optional capability needed to use tool |
None
|
metadata
|
dict[str, str] | None
|
Additional tool metadata |
None
|
Returns:
Type | Description |
---|---|
ToolInfo
|
Created ToolInfo instance |
Source code in src/llmling_agent/tools/manager.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
register_worker
¶
register_worker(
worker: AnyAgent[Any, Any],
*,
name: str | None = None,
reset_history_on_run: bool = True,
pass_message_history: bool = False,
share_context: bool = False,
parent: AnyAgent[Any, Any] | None = None,
) -> ToolInfo
Register an agent as a worker tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
worker
|
AnyAgent[Any, Any]
|
Agent to register as worker |
required |
name
|
str | None
|
Optional name override for the worker tool |
None
|
reset_history_on_run
|
bool
|
Whether to clear history before each run |
True
|
pass_message_history
|
bool
|
Whether to pass parent's message history |
False
|
share_context
|
bool
|
Whether to pass parent's context/deps |
False
|
parent
|
AnyAgent[Any, Any] | None
|
Optional parent agent for history/context sharing |
None
|
Source code in src/llmling_agent/tools/manager.py
302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
remove_provider
¶
remove_provider(provider: ResourceProvider | ResourceCallable | ProviderName)
Remove a resource provider.
Source code in src/llmling_agent/tools/manager.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
|
reset
¶
reset()
Reset tool states.
Source code in src/llmling_agent/tools/manager.py
333 334 335 336 337 338 339 340 |
|
reset_states
¶
reset_states()
Reset all tools to their default enabled states.
Source code in src/llmling_agent/tools/manager.py
136 137 138 139 |
|
temporary_tools
¶
temporary_tools(
tools: ToolType | ToolInfo | Sequence[ToolType | ToolInfo], *, exclusive: bool = False
) -> Iterator[list[ToolInfo]]
Temporarily register tools.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tools
|
ToolType | ToolInfo | Sequence[ToolType | ToolInfo]
|
Tool(s) to register |
required |
exclusive
|
bool
|
Whether to temporarily disable all other tools |
False
|
Yields:
Type | Description |
---|---|
list[ToolInfo]
|
List of registered tool infos |
Example
with tool_manager.temporary_tools([tool1, tool2], exclusive=True) as tools:
# Only tool1 and tool2 are available
await agent.run(prompt)
# Original tool states are restored
Source code in src/llmling_agent/tools/manager.py
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
tool
¶
tool(
name: str | None = None,
*,
description: str | None = None,
enabled: bool = True,
source: ToolSource = "runtime",
priority: int = 100,
requires_confirmation: bool = False,
requires_capability: str | None = None,
metadata: dict[str, str] | None = None,
) -> Callable[[AnyCallable], AnyCallable]
Decorator to register a function as a tool.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str | None
|
Optional override for tool name (defaults to function name) |
None
|
description
|
str | None
|
Optional description override |
None
|
enabled
|
bool
|
Whether tool is initially enabled |
True
|
source
|
ToolSource
|
Tool source type |
'runtime'
|
priority
|
int
|
Execution priority (lower = higher) |
100
|
requires_confirmation
|
bool
|
Whether tool needs confirmation |
False
|
requires_capability
|
str | None
|
Optional required capability |
None
|
metadata
|
dict[str, str] | None
|
Additional tool metadata |
None
|
Returns:
Type | Description |
---|---|
Callable[[AnyCallable], AnyCallable]
|
Decorator function that registers the tool |
Example
@tool_manager.register( name="search_docs", description="Search documentation", requires_confirmation=True ) async def search(query: str) -> str: '''Search the docs.''' return "Results..."
Source code in src/llmling_agent/tools/manager.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
|