Principle:3641397194 wq Gpt6 Astra Tool Execution Dispatch
| Knowledge Sources | |
|---|---|
| Domains | Tool_Design, Plugin_Architecture, Security |
| Last Updated | 2026-10-26 12:00 GMT |
Overview
A dispatch-and-execute architecture where a central engine validates tool arguments against schemas, routes to type-specific handlers, and provides workspace containment for file-producing tools.
Description
Tool Execution Dispatch is the pattern for executing named tools with validated arguments in a contained workspace. It addresses the problem of safe tool invocation in an agentic system: an AI model selects a tool and provides arguments, but those arguments must be validated against the tool's schema before execution, and file-producing tools must write only inside a contained workspace directory.
The engine provides:
- Schema validation: every tool call's arguments are validated against the tool's `inputSchema` before dispatch. Unknown tools or invalid arguments throw before any handler runs.
- Handler dispatch: tools are dispatched by name to type-specific handlers: network tools (resolve_host, scan_ports, inspect_http, crawl_site, find_paths, fuzz_http, check_web), binary tools (analyze_binary, search_bytes, diff_files, decode_text, match_hash, patch_bytes), IDA tools (ida_connect, ida_call), and the workflow orchestrator (run_workflow).
- Workspace containment: the `file()` method resolves any file argument to a `realpathSync` inside the workspace, rejecting paths that escape via `..` or symlinks. The `directory()` method creates and validates output directories within the workspace.
- Task lifecycle: `start()` runs tools as async tasks with a 4-concurrent / 100-total limit, cancellation via AbortController, and persistence to `runs/<uuid>/result.json` + `report.md`.
Usage
Use this principle when you need a controlled execution environment for a set of security tools callable by an AI agent or directly by the UI. It is the execution engine behind the toolbox agent loop and the standalone tool execution interface.
Theoretical Basis
The dispatch pattern:
# Abstract algorithm (NOT real implementation)
class ToolboxEngine:
def __init__(self, workspace):
self.workspace = realpath(workspace)
self.tasks = {}
def execute(self, name, args, ctx):
check_cancelled(ctx.signal)
tool = TOOLS.find(t => t.name == name)
if not tool: raise Error(f"Unknown tool {name}")
validate(args, tool.input_schema)
# Dispatch by name to handler
if name in NETWORK_TOOLS:
return network_handlers[name](args, ctx)
if name == "analyze_binary":
return binary.analyze(self.read(args.file), args)
if name == "patch_bytes":
output = binary.patch_bytes(self.read(args.file), args.patches)
relative = f"patched/{uuid()}-{basename(args.file)}"
write(f"{workspace}/{relative}", output)
return {file: relative, ...manifest}
if name == "run_workflow":
return self.workflow(args, ctx)
# ...
def file(self, value):
# Containment: resolve and verify inside workspace
candidate = realpath(resolve(workspace, value))
if relative(workspace, candidate) starts with "..":
raise Error("file path escapes workspace")
return candidate
The `workflow()` method chains multiple tools:
def workflow(self, args, ctx):
stages = []
if args.mode == "web":
stages.append(run("resolve_host", {host}))
stages.append(run("scan_ports", {host, ports}))
stages.append(run("inspect_http", {url}))
stages.append(run("crawl_site", {url, max_pages}))
stages.append(run("find_paths", {url}))
stages.append(run("check_web", {url}))
else: # reverse mode
stages.append(run("analyze_binary", {file: args.file}))
if args.use_ida:
connection = run("ida_connect", {url: args.ida_url})
run("ida_call", {name: read_tool.name})
return {mode, status: aggregate(stages), stages}
Key properties:
- Fail-fast validation: `validate(args, tool.inputSchema)` throws on first schema violation before any handler runs.
- Workspace realpath: all file operations resolve through `fs.realpathSync` — symlinks are followed and the canonical path is checked against workspace boundaries.
- 64 MiB file limit: `file()` rejects files larger than `binary.MAX_FILE` (64 MiB).
- Import sample: `importSample` copies a file into `samples/<sha256prefix>-<name>` with content-addressed deduplication.
- Patch isolation: `patch_bytes` writes to `patched/<uuid>-<name>` with a `.json` manifest — the source file is never modified (`sourceUnchanged: true`).
- Concurrency limits: `start()` allows max 4 non-terminal tasks concurrently, max 100 total tasks (oldest terminal tasks are evicted).
Practical Guide
- Use `catalog()` to get the list of available tools and their schemas for display to the AI model.
- `directory(relative)` creates nested directories with symlink-guarded validation at each level.
- `save(task)` writes a `result.json` and `report.md` to `runs/<task.id>/` — the report includes a SHA-256 digest of the JSON.
- `cancel(id)` aborts a running task via `AbortController`; the task status becomes `cancelled`.
- `redact(args)` is applied to all task arguments before storage — secrets in arguments are sanitized.