How AI agents work
Section titled “How AI agents work”A plain chat model can only suggest code in a reply. An AI agent pairs a reasoning model with tools: reading files, editing code, running terminal commands, and inspecting a live browser. That lets the agent observe real feedback and iterate until the task passes.
The agent loop
Section titled “The agent loop”When you give Antigravity a task, the agent works through a repeating loop rather than guessing the whole answer at once:
- The agent inspects context. It reads relevant files, searches symbols, and checks your workspace rules and prompt constraints.
- The agent plans the next step. It chooses which files to change or which diagnostic command to run next.
- The agent calls a tool. It edits a file, runs a test command, queries an MCP server, or opens a page in the browser.
- The agent reads the result. It checks compiler diagnostics, test assertions, console output, or screenshots from that tool call.
- The agent iterates or finishes. It fixes any failures and repeats until verification passes, then summarizes the diff for your review.
Example: one bug fix through the loop
Section titled “Example: one bug fix through the loop”Here is how a single billing-date bug moves through those five steps:
- Inspect: The agent reads
src/billing/renewal.tsandtests/renewal.test.tsto trace where renewal dates shift. - Plan: It spots a local-midnight
Datecall that breaks across daylight saving transitions. - Call tools: It updates the calculation to UTC and runs
npm test -- tests/renewal.test.ts. - Read result: One edge-case test fails on February 29 leap-year rollover.
- Iterate and finish: It clamps month-end dates, re-runs the tests until they pass, and hands back the diff.
Tools, MCP, and hooks
Section titled “Tools, MCP, and hooks”Built-in tools cover local files, code search, terminal commands, and browser checks. For external context like issue trackers, databases, or cloud docs, the agent connects through the Model Context Protocol (MCP):
- Standardized external tools: MCP lets agents discover and call external tools without custom glue code for each service.
- Global and workspace configs: Configure global MCP servers in
~/.gemini/config/mcp_config.jsonor project-scoped servers in.agents/mcp_config.json. - Curated plugin bundles: Install pre-built bundles of skills, MCP servers, rules, agents, and hooks from the Marketplace or Build with Google.
- Deterministic lifecycle hooks: Configure Hooks in
.agents/hooks.jsonor~/.gemini/config/hooks.jsonto run shell scripts onPreToolUseandPostToolUse. Use them to auto-format files or block risky commands.
Choose an agent pattern
Section titled “Choose an agent pattern”Most everyday tasks run best in a single conversation. Reach for specialized orchestrators when work is unusually hard, divides cleanly across files, or needs independent review:
| Pattern | How it works | Best for | Surfaces | Plans |
|---|---|---|---|---|
| Single agent | One conversation reads, edits, and verifies sequentially. | Focused bug fixes, single-module edits, and quick prototypes. | All surfaces | All plans |
| Orchestrator | Pairs a planner model with a faster executor model inside one conversation. | Everyday feature work and multi-file debugging with lower latency. | App, CLI | Paid Pro, Ultra, Enterprise |
| Subagents (built-in & custom) | Main agent delegates scoped tasks (research, browser, or .agents/) to isolated child sessions. | Deep codebase research, browser checks, or reusable audit roles. | App, CLI, IDE | All plans |
Swarm (/swarm) | A coordinator splits work across named workers and a @verifier on a shared live board. | Broad tasks that divide cleanly across separate files or packages. | App, CLI | All plans (Preview) |
Dynamic workflows (/run-workflow) | Agent writes and runs a Python script coordinating parallel() and pipeline() agents. | Fan-out audits across many files or repeatable staged pipelines. | App, CLI | All plans |
Boost (/boost) | Multi-agent pipeline where workers implement, challenge, fix, and re-verify solutions. | Hard bugs, race conditions, and complex algorithms. | App, CLI | Paid plans |
Teamwork (/teamwork) | Scoping interview followed by milestone orchestration (Critic, Challenger, Auditor) in ~/. | Multi-milestone migrations, simulations, and multi-day projects. | App, CLI | Paid plans |
Compare a focused single-agent prompt with a parallel /swarm prompt you can
try in any repository:
Find all TODO and FIXME comments in this repository, group them by directory, and list the top three with the highest bug risk without editing any files.
/swarm Audit this repository's tests and docs in parallel: have @test-audit list untested edge cases, @docs-audit check README commands against project scripts, and @verifier cross-check both reports on the board.
Where you stay in control
Section titled “Where you stay in control”Agents do the heavy lifting, while you own the architecture and release bar:
- Define boundaries up front with clear prompts, Rules, Hooks, and Permissions.
- Review plans and diffs before accepting edits or running sensitive commands.
- Keep verification objective by anchoring tasks to automated tests and visual checks.
Next steps
Section titled “Next steps”Learn how to combine tests, live browser checks, hooks, and sandboxing to keep agent edits safe.
Run parallel named workers and an independent verifier on a shared board.
Watch four parallel swarm workers and /browser build and verify a live Three.js app.