Dyad ships a local agent mode that runs AI agent tool calling loops entirely within the Electron app. The agent reads files, writes code, executes SQL, manages dependencies, searches the codebase, and calls MCP tools, all on your machine. No code leaves your device unless you connect to a cloud model provider. This post covers how it works, from the loop architecture to the consent UX.
The Agent Loop
The core of Dyad's agent mode is a multi-step loop. When you send a message, Dyad does the following:
- Builds a system prompt and prepares your message history.
- Sends everything to the AI model (cloud or local) via the Vercel AI SDK.
- The model responds with text, tool calls, or both.
- Dyad executes the tool calls locally, on your machine, inside the Electron main process.
- Tool results go back into the conversation, and the model gets another turn.
- This repeats until the model stops calling tools or hits a 25-step limit.
- Dyad commits all file changes to Git automatically.
This is the standard AI agent tool calling pattern: the model decides what to do, the host app executes actions, and results feed back into the next model turn. The difference here is that every tool runs locally. File writes go directly to your filesystem. SQL runs against your connected database. There is no intermediary server.
The stopWhen configuration caps the loop at 25 steps. It also stops when a specific tool is called (like add_integration, which requires user setup before continuing). This prevents runaway loops while giving the agent enough room to handle multi-step tasks.
Tool Definitions with Zod Schemas
Each tool in Dyad follows a consistent interface. A tool has a name, description, Zod input schema, consent default, and an execute function. The Zod schema validates model-generated arguments before execution.
Dyad includes about 20 built-in tools:
- File operations:
read_file,write_file,edit_file,search_replace,delete_file,rename_file - Codebase search:
list_files,grep,code_search - Database:
execute_sql,get_supabase_table_schema,get_supabase_project_info - Dependencies:
add_dependency - Diagnostics:
read_logs,run_type_checks - Web:
web_search,web_crawl - Task tracking:
update_todos,set_chat_summary
Using Zod for input schemas has a practical benefit for AI agent tool calling. The .describe() annotations on each field become part of the tool definition sent to the model. This gives the AI structured guidance on what each parameter expects without relying on unstructured prompt text.
The Consent System
Running an autonomous agent on your local machine raises obvious concerns. Dyad handles this with a per-tool consent system. Every tool has a defaultConsent value: "always" (auto-approve), "ask" (prompt the user each time), or "never" (disabled).
Read-only tools like read_file and list_files default to "always". State-changing tools that modify your filesystem or database can be configured per your preference.
When a tool requires consent, Dyad pauses the agent loop and shows a prompt in the UI. You get three choices:
- Accept once: allow this specific invocation
- Accept always: auto-approve this tool going forward
- Decline: block the call and let the agent handle the refusal
Consent preferences persist in your local settings. You can change them at any time from the settings panel. If you cancel a stream mid-flight, Dyad cleans up all pending consent requests to prevent stale UI.
MCP Tool Integration
Beyond built-in tools, Dyad loads tools from any connected MCP servers. MCP (Model Context Protocol) is an open standard for connecting AI applications to external services.
At the start of each agent turn, Dyad queries all enabled MCP servers for their available tools and merges them into the same tool set the model sees. MCP tools follow the same consent flow. The agent can call a Neon database query, a Playwright browser test, or a Context7 docs lookup in the same conversation as built-in file operations.
This is the practical value of AI agent tool calling inside a desktop app. Because Dyad runs locally, it can bridge local filesystem tools and remote MCP services in a single agent loop without routing everything through a cloud intermediary.
Challenges of Running an Agent in a Desktop App
Building an AI agent tool calling system inside Electron has some specific challenges that differ from server-side implementations.
Process architecture. Tool execution happens in the Electron main process, which also handles the UI event loop. Long-running tools (like type-checking a large project) need to be non-blocking. Dyad uses async execution and streams partial results to the renderer so the UI stays responsive during multi-step agent runs.
Streaming tool previews. As the model streams tool arguments token by token, Dyad parses the partial JSON in real-time using jsonrepair and renders a live preview of what the tool will do. This gives you visibility into the agent's actions before they complete.
Abort handling. Users can cancel an agent run at any point. When that happens, Dyad aborts the model stream, resolves all pending consent requests as "decline", and preserves whatever work was completed up to that point.
File edit reliability. The agent has multiple strategies for editing files: precise search-and-replace for small changes, full file rewrites for larger ones. If one approach fails (a search string does not match), the agent can retry with a different tool. Dyad tracks which edit tools were used on each file for telemetry, so the system improves over time.
Read-Only Mode
The agent also supports a read-only mode (used in Dyad's "Ask" mode) where all state-modifying tools are filtered out. The model can still read files, search code, and answer questions about your project, but it cannot write files or execute SQL. No commits or deploys happen. This is useful when you want to understand a codebase without risking changes.
Getting Started
Dyad is open-source under the MIT license (with FSL 1.1 for pro features). The source code is on GitHub. Agent mode is available for Dyad Pro members and as a free Basic Agent mode with a daily quota.
- Download Dyad for Mac, Windows, or Linux.
- Select Agent mode from the chat mode picker.
- Start prompting. The agent will read your project, make changes, and debug its own errors.
You can review the tool definitions, consent system, and agent loop code directly in the repository. If you build your own AI agent tool calling system, Dyad's implementation is a practical reference for how to structure tool schemas, handle consent, and manage multi-step loops inside a desktop app.