Pro Feature: Local Agent & Tools
Relevant source files
The following files were used as context for generating this wiki page:
- src/prompts/local_agent_prompt.ts
- src/prompts/system_prompt.ts
- e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-1.txt
- e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---read-then-edit-1.aria.yml
- e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---parallel-tool-calls-1.aria.yml
- e2e-tests/snapshots/local_agent_consent.spec.ts_local-agent---add-dependency-consent-decline-1.aria.yml
- e2e-tests/snapshots/local_agent_advanced.spec.ts_local-agent---mcp-tool-call-1.aria.yml
- src/prompts/summarize_chat_system_prompt.ts
The Local Agent is an AI assistant designed to create and modify web applications by directly interacting with the codebase. It operates in a local-agent chat mode, where it can autonomously use a suite of tools to perform file system operations, manage dependencies, and edit code based on user requests. This allows the agent to handle complex coding tasks, from creating new files to refactoring existing ones, while providing real-time feedback to the user.
The agent's behavior is governed by a detailed system prompt that outlines its role, capabilities, and constraints. It is instructed to be efficient, follow best practices, and make fully functional changes. The agent can read files to understand the context, make surgical edits, and even execute multiple independent tool calls in parallel to speed up its workflow.
Agent Architecture and Flow
The Local Agent's operation is initiated when the application's chat mode is set to local-agent. The system then constructs a specific system prompt that equips the AI with the necessary instructions and tool definitions to interact with the local development environment.
The general flow is as follows:
- The user provides a request in the chat.
- The AI, guided by the
LOCAL_AGENT_SYSTEM_PROMPT, analyzes the request. - The AI plans a series of actions and selects the appropriate tools to accomplish the task.
- The AI issues one or more tool calls in a single response. These can be parallel if the operations are independent.
- The application backend executes these tool calls (e.g., writing a file, reading a directory).
- The results of the tool executions are sent back to the AI.
- The AI processes the results and either continues with more tool calls or formulates a final response for the user.
This diagram illustrates the high-level interaction loop for the Local Agent.
System Prompt Configuration
The Local Agent's behavior is defined by the LOCAL_AGENT_SYSTEM_PROMPT. This prompt is constructed by the constructLocalAgentPrompt function and provides the AI with its core instructions.
Sources: src/prompts/local_agent_prompt.ts:8-100, src/prompts/system_prompt.ts:420-427
The prompt is divided into several key sections:
| Section | Description |
|---|---|
<role> | Defines the agent as "Dyad, an AI assistant that creates and modifies web applications." It emphasizes efficiency, best practices, and providing clear explanations. |
<app_commands> | Instructs the agent on how to suggest UI commands like Rebuild, Restart, and Refresh using the <dyad-command> tag, rather than suggesting shell commands. |
<general_guidelines> | Provides rules for interaction, such as replying in the user's language, checking if a feature is already implemented, making only fully functional changes, and keeping explanations concise. |
<tool_calling> | Outlines the rules for using tools, such as following the schema, not referring to tool names directly to the user, and using tools autonomously to gather information instead of asking the user. |
<tool_calling_best_practices> | Recommends a workflow for tool usage: 1. Read before writing, 2. Use search_replace for edits, 3. Be surgical, and 4. Handle errors gracefully. |
[[AI_RULES]] | A placeholder for project-specific rules, such as the tech stack (React, TypeScript), file structure conventions (src/pages, src/components), and preferred libraries (shadcn/ui, Tailwind CSS). |
Available Tools
The Local Agent has a powerful set of tools to interact with the codebase. These tools are defined with JSON schemas that specify their function, parameters, and which parameters are required.
The following diagram shows a sequence of a user asking for a file modification, and the agent using the read_file and search_replace tools to fulfill the request.
Diagram based on flow described in: e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---read-then-edit-1.aria.yml
The table below details each available tool.
| Tool | Description | Parameters |
|---|---|---|
write_file | Create or completely overwrite a file in the codebase. | path (string, required), content (string, required), description (string) |
delete_file | Delete a file from the codebase. | path (string, required) |
rename_file | Rename or move a file in the codebase. | from (string, required), to (string, required) |
add_dependency | Install npm packages. | packages (array of strings, required) |
search_replace | Apply targeted search/replace edits to a file. This is the preferred tool for editing a file. | path (string, required), search (string, required), replace (string, required), description (string) |
read_file | Read the content of a file from the codebase. The agent is encouraged to speculatively read multiple files as a batch. | path (string, required) |
list_files | List all files in the application directory recursively. | directory (string, optional) |
set_chat_summary | Set the title/summary for the chat message. This should be called at the end of a turn after all other tools have been called. | summary (string, required) |
add_integration | Add an integration provider (e.g., Supabase). The agent must stop after calling this tool to wait for user setup. | provider (enum: "supabase", required) |
Sources: e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---dump-request-1.txt:21-204
Parallel Tool Execution
The agent is capable of executing multiple, independent tool calls in parallel within a single turn. This is specified in the <tool_calling> guidelines. For example, if a user asks to create two unrelated utility files, the agent can issue two write_file calls simultaneously.
This feature improves the agent's efficiency by reducing the number of sequential back-and-forth steps required to complete a task.
Sources: src/prompts/local_agent_prompt.ts:80-82, e2e-tests/snapshots/local_agent_basic.spec.ts_local-agent---parallel-tool-calls-1.aria.yml
User Consent for Tools
Certain sensitive operations, such as adding a new dependency with the add_dependency tool, require explicit user consent before execution. When the agent calls such a tool, the UI will present a confirmation dialog to the user. The tool call will only proceed if the user approves it. If the user denies permission, the tool fails, and an error is returned to the agent, which must then handle the failure gracefully.
Sources: e2e-tests/snapshots/local_agent_consent.spec.ts_local-agent---add-dependency-consent-decline-1.aria.yml, e2e-tests/snapshots/local_agent_consent.spec.ts_local-agent---add-dependency-consent-allow-once-1.aria.yml