Overview
Agent Main Loop
- Receive request: Reads your input and combines it with the current context (Conversation History, project instructions, Memory) to understand what you want to achieve.
- Plan the next step: The model decides what to do next—whether to read a file to understand the current state, search the codebase, make direct modifications, or run a command for verification.
- Call tools: The Agent executes specific actions through tools, such as reading files, editing code, executing shell commands, searching code, or retrieving web pages.
- Observe results: Incorporates the results returned by the tools back into the context.
- Continue or finish: Determines whether the task is complete based on the results. If not, it returns to step 2 to plan the next step; if complete, it provides a summary.
You can use --max-turns to limit the maximum number of Conversation Turns for a single run, preventing infinite loops in automated scenarios.
Tools
- File operations: Read, write, and edit files, and browse directories.
- Execution: Run shell commands.
- Search: Search code by content (Grep) and find files by name (Glob).
- Information: Web search and Web Scraping.
Permissions
- allow: Execute the tool immediately.
- ask: Require confirmation before execution.
- deny: Block the call.
ask differently: an interactive terminal will prompt you for confirmation, non-interactive (Headless) mode will convert ask to a denial, and SDK and IDE integrations will delegate the decision to the Host Application.
For a complete explanation of permission modes, rule configurations, and directory trust, see Permissions.
Context
- Conversation Context: Historical messages, tool calls, and results within the current session. As the conversation progresses, the context continuously accumulates.
- Project instructions: Static memory maintained by you or your team, such as
AGENTS.mdand rules, which describe the project structure, development standards, and collaboration conventions. - Long-term memory: Information retained across sessions, including team conventions and optional Auto-Memory.