Mastering Communication with AI Agents
Coding agents like Gemini CLI are powerful, but they require precise direction. Unlike a human colleague who might infer intent from vague requests, an agent needs explicit instructions to operate safely and correctly.
Explicit vs. Implicit Instructions
Implicit: "Fix the bug in the login page." (Ambiguous, risky)
Explicit: "In src/auth/login.ts, update the validateUser function to handle null inputs by returning false. Use read_file to check the context first." (Clear, actionable)
Providing Context Efficiently
Agents don't "know" your codebase until they read it. Always guide the agent to:
- List files to understand structure (
ls -R). - Read specific relevant files before editing.
- Avoid pasting huge files into the prompt if the agent can read them directly.
Breaking Out of Error Loops
If an agent gets stuck (e.g., repeatedly failing a test or misinterpreting a tool output):
- Stop: Don't just retry the same prompt.
- Analyze: Read the error message carefully.
- Redirect: Give a new, simpler task. "Forget the previous approach. List the directory contents first to verify the path."
Best Practices
- Atomic Tasks: Break big features into small, verifiable steps.
- Verify: Ask the agent to run tests or cat the file after editing.
- Constraints: Explicitly state what not to do (e.g., "Do not change the function signature").