Skip to content

Commit b6e4e40

Browse files
r266-techteknium1
authored andcommitted
docs(guide): add Dispatch tools from slash commands section
1 parent 91f339b commit b6e4e40

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

website/docs/guides/build-a-hermes-plugin.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,45 @@ def register(ctx):
628628
ctx.register_command("check", handler=_handle_check, description="Run async check")
629629
```
630630

631+
### Dispatch tools from slash commands
632+
633+
Slash command handlers that need to orchestrate tools (spawn a subagent via `delegate_task`, call `file_edit`, etc.) should use `ctx.dispatch_tool()` instead of reaching into framework internals. The parent-agent context (workspace hints, spinner, model inheritance) is wired up automatically.
634+
635+
```python
636+
def register(ctx):
637+
def _handle_deliver(raw_args: str):
638+
result = ctx.dispatch_tool(
639+
"delegate_task",
640+
{
641+
"goal": raw_args,
642+
"toolsets": ["terminal", "file", "web"],
643+
},
644+
)
645+
return result
646+
647+
ctx.register_command(
648+
"deliver",
649+
handler=_handle_deliver,
650+
description="Delegate a goal to a subagent",
651+
)
652+
```
653+
654+
**Signature:** `ctx.dispatch_tool(name: str, args: dict, *, parent_agent=None) -> str`
655+
656+
| Parameter | Type | Description |
657+
|-----------|------|-------------|
658+
| `name` | `str` | Tool name as registered in the tool registry (e.g. `"delegate_task"`, `"file_edit"`) |
659+
| `args` | `dict` | Tool arguments, same shape the model would send |
660+
| `parent_agent` | `Agent \| None` | Optional override. When omitted, resolves from the current CLI agent (or degrades gracefully in gateway mode) |
661+
662+
**Runtime behavior:**
663+
664+
- **CLI mode:** `parent_agent` is resolved from the active CLI agent so workspace hints, spinner, and model selection inherit as expected.
665+
- **Gateway mode:** There is no CLI agent, so tools degrade gracefully — workspace is read from `TERMINAL_CWD` and no spinner is shown.
666+
- **Explicit override:** If the caller passes `parent_agent=` explicitly, it is respected and not overwritten.
667+
668+
This is the public, stable interface for tool dispatch from plugin commands. Plugins should not reach into `ctx._cli_ref.agent` or similar private state.
669+
631670
:::tip
632671
This guide covers **general plugins** (tools, hooks, slash commands, CLI commands). For specialized plugin types, see:
633672
- [Memory Provider Plugins](/docs/developer-guide/memory-provider-plugin) — cross-session knowledge backends

0 commit comments

Comments
 (0)