工具与技能¶
工具是通过 @tool 装饰器注册的普通 Python 函数;注册表向模型提供其
Schema,并在执行时强制权限级别。Skill 是 Agent 可按需加载的 Markdown
操作手册;App 与 Expert 将技能与配置打包在一起。
演练参见工具、技能与专家。
注册表¶
tool
¶
tool(
name: str,
description: str,
permission: PermissionLevel = PermissionLevel.AUTO,
)
Source code in src/dashscope_agenticx/tools/registry.py
579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 | |
ToolRegistry
¶
ToolRegistry()
Source code in src/dashscope_agenticx/tools/registry.py
348 349 350 351 352 | |
register
¶
register(tool_def: ToolDefinition)
Register a tool. When used as a decorator with a ToolDefinition, returns a decorator.
Source code in src/dashscope_agenticx/tools/registry.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
register_mcp_tool
¶
register_mcp_tool(
name: str,
description: str,
parameters: dict,
call_fn: Callable,
)
Source code in src/dashscope_agenticx/tools/registry.py
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | |
unregister
¶
unregister(name: str)
Source code in src/dashscope_agenticx/tools/registry.py
395 396 397 398 | |
get
¶
get(name: str) -> ToolDefinition | None
Source code in src/dashscope_agenticx/tools/registry.py
400 401 | |
list_tools
¶
list_tools() -> list[ToolDefinition]
Source code in src/dashscope_agenticx/tools/registry.py
403 404 | |
clone
¶
clone() -> 'ToolRegistry'
Return an isolated registry with the same tool definitions.
Tool callables are intentionally shared: built-in functions are immutable registration targets. Definitions and parameter schemas are copied so runtime-local registration, renaming, or unregistration does not mutate another runtime.
Source code in src/dashscope_agenticx/tools/registry.py
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
to_schema_list
¶
to_schema_list(user_input: str = '') -> list[dict]
Convert registered tools to JSON schema format.
If user_input is provided, prioritize tools relevant to the input. Core tools (filesystem, shell) are always included. Specialized tools (platform, MCP) are included if keywords match.
Source code in src/dashscope_agenticx/tools/registry.py
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 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 | |
ToolDefinition
dataclass
¶
ToolDefinition(
name: str,
description: str,
permission: PermissionLevel = PermissionLevel.AUTO,
func: Callable = None,
parameters: dict = dict(),
)
PermissionLevel
¶
RuntimeToolRegistry
¶
RuntimeToolRegistry()
Bases: ToolRegistry
Backward-compatible registry facade with runtime-local binding.
Static @tool imports populate the default registry. A Runtime clones
that baseline and binds the clone through a ContextVar while wiring and
executing an Agent. Existing modules that import the global registry
therefore resolve to the correct runtime without a process-wide parent
pointer, while legacy callers continue to see a ToolRegistry instance.
Source code in src/dashscope_agenticx/tools/registry.py
508 509 510 511 512 | |
current
¶
current() -> ToolRegistry
Source code in src/dashscope_agenticx/tools/registry.py
514 515 | |
bind
¶
bind(target: ToolRegistry)
Source code in src/dashscope_agenticx/tools/registry.py
517 518 519 520 521 522 523 | |
register
¶
register(tool_def: ToolDefinition)
Source code in src/dashscope_agenticx/tools/registry.py
537 538 | |
register_mcp_tool
¶
register_mcp_tool(
name: str,
description: str,
parameters: dict,
call_fn: Callable,
)
Source code in src/dashscope_agenticx/tools/registry.py
540 541 542 543 544 545 546 547 548 549 550 551 552 | |
unregister
¶
unregister(name: str)
Source code in src/dashscope_agenticx/tools/registry.py
554 555 | |
get
¶
get(name: str) -> ToolDefinition | None
Source code in src/dashscope_agenticx/tools/registry.py
557 558 | |
list_tools
¶
list_tools() -> list[ToolDefinition]
Source code in src/dashscope_agenticx/tools/registry.py
560 561 | |
clone
¶
clone() -> ToolRegistry
Source code in src/dashscope_agenticx/tools/registry.py
563 564 | |
to_schema_list
¶
to_schema_list(user_input: str = '') -> list[dict]
Source code in src/dashscope_agenticx/tools/registry.py
566 567 | |
bind_tool_registry
¶
bind_tool_registry(target: ToolRegistry)
Bind the compatibility facade to target for the current context.
Source code in src/dashscope_agenticx/tools/registry.py
574 575 576 | |
内置工具¶
核心工具随基础安装一起提供:
filesystem
¶
read_file
¶
read_file(
path: str,
offset: int | None = None,
limit: int | None = None,
) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
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 | |
write_file
¶
write_file(path: str, content: str) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
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 | |
list_directory
¶
list_directory(path: str) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | |
create_directory
¶
create_directory(path: str) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
282 283 284 285 286 287 288 289 290 291 292 293 | |
delete_file
¶
delete_file(path: str) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 | |
delete_directory
¶
delete_directory(path: str) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
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 | |
search_files
¶
search_files(pattern: str, path: str | None = None) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
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 | |
move_file
¶
move_file(src: str, dst: str) -> str
Source code in src/dashscope_agenticx/tools/filesystem.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 | |
shell
¶
BLOCKED_PATTERNS
module-attribute
¶
BLOCKED_PATTERNS = [
"mkfs",
"dd if=",
"> /dev/sd",
"chmod -R 777 /",
"shred",
"wipefs",
"--no-preserve-root",
"rd /s /q",
"del /f /q /s",
"> \\\\.\\PhysicalDrive",
]
default_timeout
¶
default_timeout() -> int
Seconds a run_command call gets before it is killed.
Resolved per call rather than at import, so exporting
AGENTICX_COMMAND_TIMEOUT takes effect without a restart.
Source code in src/dashscope_agenticx/tools/shell.py
183 184 185 186 187 188 189 190 191 192 193 | |
shell_label
¶
shell_label() -> str
How run_command executes a command, for the system prompt.
Lives next to _spawn so the prompt cannot drift from what the tool
really runs. Nothing used to say which shell this is: a model that assumes
POSIX spends a turn on ls -la ... 2>/dev/null || find / before a
PowerShell ParserError tells it otherwise.
Source code in src/dashscope_agenticx/tools/shell.py
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 | |
is_safe_readonly
¶
is_safe_readonly(cmd: str) -> bool
True if cmd is a pure inspection command that's safe to run
without asking. Conservative: any unrecognized binary, any chained
write op, or any unsafe token returns False so the confirm prompt
stays in place.
Source code in src/dashscope_agenticx/tools/shell.py
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 | |
run_command
async
¶
run_command(
command: str, timeout: int | None = None
) -> str
Source code in src/dashscope_agenticx/tools/shell.py
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 | |
session
¶
Session/config tools — let the agent switch models, manage capabilities, and connect MCP services on behalf of the user.
register_session_tools
¶
register_session_tools(
config: Config,
*,
get_agent: Callable,
get_provider_fn: Callable,
connect_mcp_fn: Callable,
disconnect_mcp_fn: Callable,
list_mcp_services_fn: Callable,
get_mcp_clients_fn: Callable
)
Register tools that let the LLM manage session state.
Called once after agent construction. Uses closures over runtime objects.
Source code in src/dashscope_agenticx/tools/session.py
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 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 | |
register_plan_tools
¶
register_plan_tools(*, get_agent: Callable)
Bind plan operations to the executing Agent's session tier.
Source code in src/dashscope_agenticx/tools/session.py
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 | |
checkpoint
¶
File checkpoint/undo support for mutating file tools.
Backups live under <workspace>/.agenticx/checkpoints/ next to a JSONL
index. snapshot() records the pre-mutation state of a file and
undo() reverses the most recent recorded mutation.
snapshot
¶
snapshot(path: str, action: str) -> None
Record a pre-mutation checkpoint for path.
action is one of "overwrite", "create" or "delete".
Never raises: a checkpoint failure must not break the write tool.
Source code in src/dashscope_agenticx/tools/checkpoint.py
102 103 104 105 106 107 108 109 110 111 112 | |
undo
¶
undo() -> str
Undo the most recent checkpointed file mutation.
Returns a human-readable result string; never raises.
Source code in src/dashscope_agenticx/tools/checkpoint.py
153 154 155 156 157 158 159 160 161 | |
handle_undo_command
¶
handle_undo_command() -> None
CLI-facing wrapper: undo the last change and print the result.
Source code in src/dashscope_agenticx/tools/checkpoint.py
218 219 220 | |
skills
¶
Model-invocable skill tool: expand a .md skill template into instructions.
register_skill_tools
¶
register_skill_tools(get_agent: Callable) -> None
Register use_skill for .agenticx/skills/*.md templates.
Called once after agent construction, alongside register_evolution_tools.
Source code in src/dashscope_agenticx/tools/skills.py
12 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 | |
platform
¶
current_capability_tools
¶
current_capability_tools() -> dict[str, set[str]]
Return capability registrations for the current Runtime context.
Source code in src/dashscope_agenticx/tools/platform.py
29 30 31 32 | |
bind_capability_tools
¶
bind_capability_tools(tracker: dict[str, set[str]])
Bind capability registration bookkeeping to one Runtime.
Source code in src/dashscope_agenticx/tools/platform.py
35 36 37 38 39 40 41 42 | |
disabled_capabilities_hint
¶
disabled_capabilities_hint(config: Config) -> str
Build the system-prompt section that lists explicitly-disabled capabilities. None or empty = no disabled hints.
Source code in src/dashscope_agenticx/tools/platform.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 | |
all_capability_keys
¶
all_capability_keys() -> list[str]
Built-in capability keys plus anything declared in custom-extensions.toml. Used by register_platform_tools and surfaced to /capability.
Source code in src/dashscope_agenticx/tools/platform.py
118 119 120 121 122 123 124 | |
register_platform_tools
¶
register_platform_tools(
config: Config, connect_mcp_fn: Callable | None = None
)
Source code in src/dashscope_agenticx/tools/platform.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
register_one_capability
¶
register_one_capability(
config: Config,
cap_key: str,
connect_mcp_fn: Callable | None = None,
) -> int
Register a single capability's tools, tracking new names for later unregister. Returns the count of tools added (0 when creds are missing or the capability key is unknown — silent so the caller can treat it as best-effort).
Source code in src/dashscope_agenticx/tools/platform.py
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 | |
unregister_capability_tools
¶
unregister_capability_tools(cap_key: str) -> int
Drop all tools previously registered under cap_key. Returns the count of tools removed.
Note: for bailian.mcp this removes the mcp_connect dispatcher and any
mcp_
Source code in src/dashscope_agenticx/tools/platform.py
356 357 358 359 360 361 362 363 364 365 366 367 368 | |
capability_tool_names
¶
capability_tool_names() -> set[str]
All tool names currently registered under any capability. Consumed by ToolRegistry.to_schema_list: registration is the capability gate, so any tool present here must be exposed to the model (extension HTTP/vision tools and bailian_* wrappers would otherwise be invisible).
Source code in src/dashscope_agenticx/tools/platform.py
371 372 373 374 375 376 377 378 379 | |
unregister_cloud_capability_tools
¶
unregister_cloud_capability_tools() -> int
Privacy mode on: drop every registered cloud capability tool (bailian.*, extension HTTP/vision tools). Returns total tools removed.
Source code in src/dashscope_agenticx/tools/platform.py
388 389 390 391 392 393 394 395 396 | |
refresh_extension_capability_tools
¶
refresh_extension_capability_tools(config: Config) -> int
Re-register all enabled extension capabilities so their tool closures rebind to the latest custom-extensions.toml definitions (endpoint, auth, token). Called by /capability reload and /dev hot reload — without it, edited configs keep running through stale closures until restart. Returns total tools re-registered.
Source code in src/dashscope_agenticx/tools/platform.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
可选工具需要安装扩展;其模块采用惰性导入,因此在核心安装下浏览下方 参考也是安全的:
| 模块 | 扩展 |
|---|---|
tools.web_search |
dashscope-agenticx[web] |
tools.browser |
dashscope-agenticx[browser] |
tools.camera, tools.vision |
dashscope-agenticx[media] |
web_search
¶
Web search tool — DuckDuckGo-based web search.
Uses the duckduckgo-search package (DDGS) as a free, keyless search backend.
Complements the browser tools (scrape_web, scrape_web_html) which handle
page content extraction. Together they form a complete web acquisition
pipeline:
web_search → find relevant URLs
scrape_web → extract content from those URLs
Security: - Query length limits to prevent abuse - Result count limits to avoid overwhelming context windows - Lazy import of duckduckgo_search to keep startup fast
web_search
async
¶
web_search(
query: str, max_results: int = 10, region: str = "wt-wt"
) -> str
Search the web using DuckDuckGo and return structured results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
search keywords, e.g. 'Python asyncio tutorial' or 'Rust ownership explained' |
required |
max_results
|
int
|
number of results to return, default 10, max 30 |
10
|
region
|
str
|
region code, e.g. 'cn-zh' (Chinese), 'us-en' (English), 'wt-wt' (global, default) |
'wt-wt'
|
Source code in src/dashscope_agenticx/tools/web_search.py
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 | |
browser
¶
Browser tools — Playwright-based web scraping for JS-rendered pages.
Security hardening: - URL scheme validation (http/https only) - SSRF protection against private/internal IPs (DNS-level + route-level anti-rebinding interception) - Screenshot path traversal prevention - CSS selector sanitisation - Output bounded by text truncation in each tool
Performance hardening: - Browser instance reuse within a session (thread-safe) - atexit cleanup to avoid zombie chromium processes
scrape_web
async
¶
scrape_web(
url: str, wait_selector: str = "", timeout: int = 30000
) -> str
Scrape a web page using Playwright headless browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to scrape (http/https only). |
required |
wait_selector
|
str
|
Optional CSS selector to wait for before extracting content. |
''
|
timeout
|
int
|
Max wait time in milliseconds (default 30s, max 120s). |
30000
|
Source code in src/dashscope_agenticx/tools/browser.py
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 | |
scrape_web_html
async
¶
scrape_web_html(
url: str, wait_selector: str = "", timeout: int = 30000
) -> str
Scrape a web page and return the rendered HTML source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to scrape (http/https only). |
required |
wait_selector
|
str
|
Optional CSS selector to wait for before extracting HTML. |
''
|
timeout
|
int
|
Max wait time in milliseconds (default 30s, max 120s). |
30000
|
Source code in src/dashscope_agenticx/tools/browser.py
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 | |
scrape_web_screenshot
async
¶
scrape_web_screenshot(
url: str,
output_path: str = "screenshot.png",
full_page: bool = True,
wait_selector: str = "",
timeout: int = 30000,
) -> str
Take a screenshot of a web page using Playwright headless browser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
The URL to screenshot (http/https only). |
required |
output_path
|
str
|
Where to save the screenshot image (must be within current directory). |
'screenshot.png'
|
full_page
|
bool
|
If True, capture the full scrollable page. |
True
|
wait_selector
|
str
|
Optional CSS selector to wait for before capturing. |
''
|
timeout
|
int
|
Max wait time in milliseconds (default 30s, max 120s). |
30000
|
Source code in src/dashscope_agenticx/tools/browser.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 | |
camera
¶
Camera tools — allows the LLM to capture photos and record video from the webcam.
camera_capture
¶
camera_capture(path: str = 'camera_capture.jpg') -> str
Source code in src/dashscope_agenticx/tools/camera.py
10 11 12 13 14 15 16 17 18 19 20 21 22 | |
camera_record
¶
camera_record(
path: str = "camera_record.mp4", duration: float = 5.0
) -> str
Source code in src/dashscope_agenticx/tools/camera.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | |
vision
¶
Built-in vision tool — let the agent analyze local images itself.
Previously the only multimodal entry point was user-input @path
expansion, so after scrape_web_screenshot / camera_capture the
model could not see the saved image and sometimes echoed the
user-facing @path hint verbatim, ending the turn prematurely.
view_image closes that gap by routing the image to a
vision-capable model on the active provider.
Very tall/wide images (e.g. a long announcement table) get downscaled
or truncated by vision-model backends until text is illegible, so
view_image auto-slices them with Pillow (when installed) and runs
one vision call per slice. Without Pillow it falls back to sending the
whole image as-is.
auto_perceive is the read_file hook: nine bench runs (071c–071i)
showed the model reads an image as text exactly once, receives the
"call view_image / tesseract" redirect, and goes back to pixel
scripting within seconds — advice is ignorable, delivered perception
is not. When read_file hits a binary image it calls auto_perceive,
which runs the same vision pipeline inline and injects the result,
falling back to the text redirect whenever perception is unavailable.
view_image_call_count
¶
view_image_call_count() -> int
Source code in src/dashscope_agenticx/tools/vision.py
109 110 | |
auto_perceive_count
¶
auto_perceive_count() -> int
Source code in src/dashscope_agenticx/tools/vision.py
131 132 | |
pick_vision_model
¶
pick_vision_model(config: Config) -> str
Choose a vision-capable model on the active provider.
Preference: the active model when it accepts images, then the first vision model declared on the provider's extension block, then a per-provider built-in fallback.
Source code in src/dashscope_agenticx/tools/vision.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
plan_slices
¶
plan_slices(width: int, height: int)
Return crop boxes for an oversized image, or None if it fits.
Slices run along the long axis with a small overlap so rows cut at a box boundary still appear complete in one of the two neighbors.
Source code in src/dashscope_agenticx/tools/vision.py
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 | |
parse_region
¶
parse_region(region: str, width: int, height: int) -> tuple
Parse x0,y0,x1,y1 fractions into a pixel crop box.
Fractions keep the parameter resolution-independent: the model can ask for "the top-left ninth" as 0,0,0.333,0.333 without knowing the image size. Pixels would invite off-by-one hallucinations.
Source code in src/dashscope_agenticx/tools/vision.py
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 | |
perception_available
¶
perception_available() -> bool
Whether an agent has registered a perception context.
Source code in src/dashscope_agenticx/tools/vision.py
480 481 482 | |
auto_perceive
¶
auto_perceive(
safe_path: str, *, via: str = "read_file"
) -> str | None
Perceive an image inline and return the read, or None.
Called by read_file (an image opened as text) and by run_command (a
command referencing an image). safe_path must already exist.
Returns None — caller then falls back to its text hint — when the
hook is disabled (AGENTICX_AUTO_VISION=0), unconfigured (no agent
registered a perception context), this same image was already
perceived once (the content is in context; repeats just burn
latency), out of budget (AGENTICX_AUTO_VISION_MAX successful+failed
attempts per process), or the pipeline itself raises.
The agent loop runs sync tools inline on the event-loop thread, so the async pipeline runs on a helper thread with its own loop — the same blocking shape run_command already has.
Source code in src/dashscope_agenticx/tools/vision.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | |
register_vision_tools
¶
register_vision_tools(
config: Config, *, get_provider_fn: Callable
)
Register view_image; called once after agent construction.
Source code in src/dashscope_agenticx/tools/vision.py
561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 | |
技能¶
Skill
dataclass
¶
Skill(
name: str,
description: str,
mcp_service: str,
prompt_template: str,
arguments: list[str],
)
register
¶
register(skill: Skill)
Source code in src/dashscope_agenticx/skills/base.py
34 35 36 | |
load_skill_files
¶
load_skill_files()
Load skills from .md files in global and workspace skill folders.
Global files load first; workspace files override by name. File-sourced entries from the previous scan are dropped first, so deleting a skill file propagates without a restart.
Source code in src/dashscope_agenticx/skills/base.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 | |
register_skill_file
¶
register_skill_file(path: Path | str) -> bool
Register one skill .md at runtime, without waiting for a restart.
Copies path into the workspace skills dir when it lives elsewhere, then rescans so the catalog, /skill completion, and the prompt summary all see the change immediately. Returns True when the file parsed and its skill is registered after the rescan.
Source code in src/dashscope_agenticx/skills/base.py
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 | |
list_skills
¶
list_skills(
connected_services: set[str] | None = None,
) -> str
Format skills list for display.
Source code in src/dashscope_agenticx/skills/base.py
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 | |
render_skill
¶
render_skill(skill: Skill, args: list[str]) -> str | None
Render a skill prompt with given arguments. Returns None if args don't match.
Source code in src/dashscope_agenticx/skills/base.py
252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
SkillManager
dataclass
¶
SkillManager(
packages: list[SkillPackage] = list(),
_force_enabled: set[str] = set(),
_force_disabled: set[str] = set(),
_hook_bus: HookBus | None = None,
_global: bool = False,
_registry_url: str = "",
tool_registry: ToolRegistry = (lambda: registry)(),
)
Manages loaded skill packages and their activation state.
packages
class-attribute
instance-attribute
¶
packages: list[SkillPackage] = field(default_factory=list)
tool_registry
class-attribute
instance-attribute
¶
tool_registry: ToolRegistry = field(
default_factory=lambda: registry
)
load
¶
load(hook_bus: HookBus | None = None) -> None
Discover and register packages from workspace and global dirs.
Source code in src/dashscope_agenticx/skills/manager.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | |
reload
¶
reload() -> None
Reload packages from disk.
Source code in src/dashscope_agenticx/skills/manager.py
55 56 57 58 59 | |
list
¶
list() -> list[dict[str, Any]]
Return package info for display.
Source code in src/dashscope_agenticx/skills/manager.py
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 | |
install
¶
install(source: str) -> str
Install a skill package and reload.
Source code in src/dashscope_agenticx/skills/manager.py
91 92 93 94 95 96 97 98 99 | |
link
¶
link(source_dir: str) -> str
Symlink a local skill package and reload.
Source code in src/dashscope_agenticx/skills/manager.py
101 102 103 104 105 | |
uninstall
¶
uninstall(name: str) -> bool
Remove an installed skill package and reload.
Source code in src/dashscope_agenticx/skills/manager.py
107 108 109 110 111 112 113 114 | |
update
¶
update(name: str) -> str
Update a single installed skill package and reload.
Source code in src/dashscope_agenticx/skills/manager.py
116 117 118 119 120 121 122 123 124 | |
update_all
¶
update_all() -> builtins.list[tuple[str, str | None]]
Update all installed skill packages and reload.
Source code in src/dashscope_agenticx/skills/manager.py
126 127 128 129 130 131 132 133 | |
search
¶
search(query: str) -> builtins.list[dict[str, Any]]
Search installed packages and the registry.
Source code in src/dashscope_agenticx/skills/manager.py
135 136 137 138 139 140 141 | |
publish
¶
publish(source_dir: str) -> Path
Validate and package a skill directory.
Source code in src/dashscope_agenticx/skills/manager.py
143 144 145 | |
active_packages
¶
active_packages(
user_input: str,
) -> builtins.list[SkillPackage]
Return packages that should be active for the given user input.
Source code in src/dashscope_agenticx/skills/manager.py
147 148 149 150 151 152 153 154 155 | |
active_prompts
¶
active_prompts(user_input: str) -> str
Concatenate prompts from active packages.
Source code in src/dashscope_agenticx/skills/manager.py
157 158 159 160 161 162 163 164 165 166 | |
enable
¶
enable(name: str) -> bool
Source code in src/dashscope_agenticx/skills/manager.py
168 169 170 171 172 173 174 | |
disable
¶
disable(name: str) -> bool
Source code in src/dashscope_agenticx/skills/manager.py
176 177 178 179 180 181 182 | |
get_skill_manager
¶
get_skill_manager() -> SkillManager
Source code in src/dashscope_agenticx/skills/manager.py
195 196 | |
应用与专家¶
AppManifest
dataclass
¶
AppManifest(
name: str,
version: str,
description: str = "",
publisher: str = "",
schema_version: str = "1",
permissions: AppPermissions = AppPermissions(),
declared_checksum: str = "",
checksum: str = "",
trust: AppTrust = AppTrust.UNTRUSTED,
runtime_requires: str = ">=1.0.0,<2",
profile: str = ".agenticx",
eval_path: str = "",
acceptance_path: str = "",
)
Declarative App identity and requested host capabilities.
permissions
class-attribute
instance-attribute
¶
permissions: AppPermissions = field(
default_factory=AppPermissions
)
AppTrust
¶
Bases: str, Enum
Runtime trust assigned externally, never self-declared by an App.
parse
classmethod
¶
parse(value: object) -> 'AppTrust'
Source code in src/dashscope_agenticx/apps/manifest.py
27 28 29 30 31 32 33 34 | |
AppPermissions
dataclass
¶
AppPermissions(
python_tools: bool = False,
shell_hooks: bool = False,
shell: bool = False,
network: tuple[str, ...] = (),
filesystem: tuple[str, ...] = (),
)
Capabilities an App asks the host to grant.
from_mapping
classmethod
¶
from_mapping(value: object) -> 'AppPermissions'
Source code in src/dashscope_agenticx/apps/manifest.py
47 48 49 50 51 52 53 54 55 56 57 58 59 | |
names
¶
names() -> tuple[str, ...]
Source code in src/dashscope_agenticx/apps/manifest.py
61 62 63 64 65 66 67 68 69 70 71 | |
as_dict
¶
as_dict() -> dict[str, object]
Source code in src/dashscope_agenticx/apps/manifest.py
73 74 75 76 77 78 79 80 | |
load_app_manifest
¶
load_app_manifest(
path: Path,
*,
trust: AppTrust | str = AppTrust.UNTRUSTED,
expected_checksum: str = ""
) -> AppManifest | None
Load and verify an App manifest from a package directory.
Source code in src/dashscope_agenticx/apps/manifest.py
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 | |
compute_app_checksum
¶
compute_app_checksum(path: Path) -> str
Return a deterministic SHA-256 over regular App files.
Symlinks are rejected because checksumming the link text while later importing its target would verify different bytes from those executed. Generated caches and install metadata are excluded from the identity.
Source code in src/dashscope_agenticx/apps/manifest.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 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | |
permission_diff
¶
permission_diff(
before: AppPermissions | None, after: AppPermissions
) -> dict[str, list[str]]
Return stable added/removed permission names for install prompts.
Source code in src/dashscope_agenticx/apps/manifest.py
227 228 229 230 231 232 233 234 235 236 237 | |
install
¶
install(
source: str,
*,
root: Path | None = None,
trust: AppTrust | str = AppTrust.COMMUNITY,
expected_checksum: str = "",
confirm_permissions: (
Callable[[AppManifest, dict], bool] | None
) = None
) -> AppInstallResult
Source code in src/dashscope_agenticx/apps/store.py
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 | |
AppInstallResult
dataclass
¶
AppInstallResult(
manifest: AppManifest,
permission_changes: dict[str, list[str]],
path: Path,
)
load_registry
¶
load_registry(root: Path | None = None) -> dict[str, Any]
Source code in src/dashscope_agenticx/apps/store.py
54 55 56 57 58 59 60 61 62 63 64 65 66 | |
runtime_compatible
¶
runtime_compatible(
manifest: AppManifest, version: str = __version__
) -> bool
Source code in src/dashscope_agenticx/apps/store.py
77 78 79 80 81 82 83 84 | |
运行时扩展¶
来自 .agenticx/custom-extensions.toml 的声明式 Provider、工具、
能力与技能:
CustomExtensions
dataclass
¶
CustomExtensions(
providers: list[CustomProvider] = list(),
capabilities: list[CustomCapability] = list(),
skills: list[CustomSkill] = list(),
shell_tools: list[CustomShellTool] = list(),
errors: list[str] = list(),
)
providers
class-attribute
instance-attribute
¶
providers: list[CustomProvider] = field(
default_factory=list
)
capabilities
class-attribute
instance-attribute
¶
capabilities: list[CustomCapability] = field(
default_factory=list
)
shell_tools
class-attribute
instance-attribute
¶
shell_tools: list[CustomShellTool] = field(
default_factory=list
)
CustomProvider
dataclass
¶
CustomProvider(
name: str,
base_url: str,
api_key_env: str = "",
api_key_enc: str = "",
default_model: str = "",
models: list[str] = list(),
vision_models: list[str] = list(),
audio_models: list[str] = list(),
protocol: str = "openai",
reasoning_field: str = "",
auth: bool = True,
source: str = "",
)
vision_models
class-attribute
instance-attribute
¶
vision_models: list[str] = field(default_factory=list)
audio_models
class-attribute
instance-attribute
¶
audio_models: list[str] = field(default_factory=list)
resolved_models
¶
resolved_models() -> list[str]
Source code in src/dashscope_agenticx/extensions.py
91 92 93 94 95 96 | |
resolved_protocol
¶
resolved_protocol() -> str
Normalize protocol aliases. 'openai_compatible' → 'openai'; 'dashscope' / 'anthropic' / 'openai' pass through unchanged.
Source code in src/dashscope_agenticx/extensions.py
98 99 100 101 102 103 104 | |
resolve_api_key
¶
resolve_api_key(config=None) -> str
Source code in src/dashscope_agenticx/extensions.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
CustomTool
dataclass
¶
CustomTool(
name: str,
description: str,
endpoint: str,
http_method: str = "POST",
auth: str = "",
params: list[dict] = list(),
body_template: str = "",
headers: dict[str, str] = dict(),
result_jsonpath: str = "",
permission: str = "auto",
type: str = "http",
provider: str = "",
model: str = "",
)
CustomCapability
dataclass
¶
CustomCapability(
key: str,
display: str = "",
auth: str = "",
api_key_env: str = "",
api_key_enc: str = "",
tools: list[CustomTool] = list(),
source: str = "",
runtime_key: str = "",
)
resolve_auth_key
¶
resolve_auth_key() -> str
Auth token resolution: env var (named by api_key_env if set OR derived from auth's "bearer:$X" form) wins, then a reused built-in provider key, falling back to keyring/legacy storage. Empty string when nothing's available.
Source code in src/dashscope_agenticx/extensions.py
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
CustomSkill
dataclass
¶
CustomSkill(
name: str,
description: str,
prompt_template: str,
arguments: list[str] = list(),
mcp_service: str = "",
source: str = "",
)
CustomShellTool
dataclass
¶
CustomShellTool(
name: str,
description: str,
command_template: str,
params: list[dict] = list(),
permission: str = "confirm",
source: str = "",
)
load_extensions
¶
load_extensions() -> CustomExtensions
Read global + workspace extension files; workspace entries with the same name as a global entry override (later wins). Errors are collected rather than raised — partial successes still register; bad entries get surfaced to the user via the cli banner.
Source code in src/dashscope_agenticx/extensions.py
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 | |