Skip to content

Commit ed86d33

Browse files
docs(sdk): Add missing file-based agent features documentation (#390)
Add documentation for features that are implemented in the SDK but were not yet documented for file-based agents: - mcp_servers: Inline MCP server configurations for external tools - hooks: Lifecycle hooks (pre_tool_use, post_tool_use, etc.) - permission_mode: Action confirmation control (always_confirm, never_confirm, confirm_risky) - profile_store_dir: Custom LLM profile directory Also added an 'Advanced Features' section with detailed examples showing how to use each feature in agent Markdown files. Co-authored-by: openhands <openhands@all-hands.dev>
1 parent a01ee98 commit ed86d33

1 file changed

Lines changed: 107 additions & 0 deletions

File tree

sdk/guides/agent-file-based.mdx

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ The YAML frontmatter configures the agent. The Markdown body becomes the agent's
5353
| `skills` | No | `[]` | List of skill names for this agent (see [Skill Loading Precedence](/overview/skills#skill-loading-precedence) for resolution order). |
5454
| `max_iteration_per_run` | No | `None`| Maximum iterations per run. Must be strictly positive, or `None` for the default value. |
5555
| `color` | No | `None` | [Rich color name](https://rich.readthedocs.io/en/stable/appendix/colors.html) (e.g., `"blue"`, `"green"`) used by visualizers to style this agent's output in terminal panels |
56+
| `mcp_servers` | No | `None` | MCP server configurations for this agent (see [MCP Servers](#mcp-servers)) |
57+
| `hooks` | No | `None` | Hook configuration for lifecycle events (see [Hooks](#hooks)) |
58+
| `permission_mode` | No | `None` | Controls how the subagent handles action confirmations (see [Permission Mode](#permission-mode)) |
59+
| `profile_store_dir` | No | `None` | Custom directory path for LLM profiles when using a named `model` |
5660

5761
### `<example>` Tags
5862

@@ -310,6 +314,109 @@ You are a skilled technical writer. When creating or improving documentation:
310314
Always include a usage example with expected output when documenting functions or APIs.
311315
```
312316

317+
## Advanced Features
318+
319+
### MCP Servers
320+
321+
File-based agents can define [MCP server configurations](/sdk/guides/mcp) inline, giving them access to external tools without any Python code:
322+
323+
```markdown icon="markdown"
324+
---
325+
name: web-researcher
326+
description: Researches topics using web fetching capabilities.
327+
tools:
328+
- file_editor
329+
mcp_servers:
330+
fetch:
331+
command: uvx
332+
args:
333+
- mcp-server-fetch
334+
filesystem:
335+
command: npx
336+
args:
337+
- -y
338+
- "@modelcontextprotocol/server-filesystem"
339+
---
340+
341+
You are a web researcher with access to fetch and filesystem tools.
342+
Use the fetch tool to retrieve web content and save findings to files.
343+
```
344+
345+
The `mcp_servers` field uses the same format as the [MCP configuration](/sdk/guides/mcp) — each key is a server name, and the value contains `command` and `args` for launching the server.
346+
347+
### Hooks
348+
349+
File-based agents can define [lifecycle hooks](/sdk/guides/hooks) that run at specific points during execution:
350+
351+
```markdown icon="markdown"
352+
---
353+
name: audited-agent
354+
description: An agent with audit logging hooks.
355+
tools:
356+
- terminal
357+
- file_editor
358+
hooks:
359+
pre_tool_use:
360+
- matcher: "terminal"
361+
hooks:
362+
- command: "./scripts/validate_command.sh"
363+
timeout: 10
364+
post_tool_use:
365+
- matcher: "*"
366+
hooks:
367+
- command: "./scripts/log_tool_usage.sh"
368+
timeout: 5
369+
---
370+
371+
You are an audited agent. All your actions are logged for compliance.
372+
```
373+
374+
**Hook event types:**
375+
- `pre_tool_use` — Runs before tool execution (can block with exit code 2)
376+
- `post_tool_use` — Runs after tool execution
377+
- `user_prompt_submit` — Runs before processing user messages
378+
- `session_start` / `session_end` — Run when conversation starts/ends
379+
- `stop` — Runs when agent tries to finish (can block)
380+
381+
Each hook matcher supports:
382+
- `"*"` — Matches all tools
383+
- Exact name — e.g., `"terminal"` matches only that tool
384+
- Regex patterns — e.g., `"/file_.*/"` matches tools starting with `file_`
385+
386+
For more details on hooks, see the [Hooks guide](/sdk/guides/hooks).
387+
388+
### Permission Mode
389+
390+
Control how a file-based agent handles action confirmations with the `permission_mode` field:
391+
392+
```markdown icon="markdown"
393+
---
394+
name: autonomous-agent
395+
description: Runs without requiring user confirmation.
396+
tools:
397+
- terminal
398+
- file_editor
399+
permission_mode: never_confirm
400+
---
401+
402+
You are an autonomous agent that executes tasks without manual approval.
403+
```
404+
405+
**Available modes:**
406+
| Mode | Behavior |
407+
|------|----------|
408+
| `always_confirm` | Requires user approval for **all** actions |
409+
| `never_confirm` | Executes all actions without approval |
410+
| `confirm_risky` | Only requires approval for actions above a risk threshold (requires a [security analyzer](/sdk/guides/security)) |
411+
412+
When `permission_mode` is omitted (or set to `None`), the subagent inherits the confirmation policy from its parent conversation.
413+
414+
<Note>
415+
Permission mode is particularly useful for specialized sub-agents. For example, a "read-only explorer" agent might use `never_confirm` since it only reads files, while a "deploy" agent might use `always_confirm` for safety.
416+
</Note>
417+
418+
For more details on security and confirmation policies, see the [Security guide](/sdk/guides/security).
419+
313420
## Agents in Plugins
314421

315422
> Plugins bundle agents, tools, skills, and MCP servers into reusable packages.

0 commit comments

Comments
 (0)