Coding agents

Working with agents

View as Markdown

Developers are now writing a lot of code with agents. Instead of typing every line by hand, they talk to an agent and have it write the code for them.

In the Foundations course, you learned the core behavior behind agents: give them powerful tools and let them run autonomously in a loop. This course covers strategies to work effectively with coding agents when you're building software.

What's an agent harness?

Grok Build is an AI editor with a built-in coding agent. The agent runs inside what's called a "harness," which is made up of three things:

  1. Instructions: The system prompt and rules that guide behavior
  2. Tools: File editing, codebase search, terminal execution, and more
  3. Model: The agent model you pick for the task

Coding agents help you accomplish tasks based on the goals you give them. Every harness has slightly different behavior based on how it's tuned and the models you use.

Some models are trained to call shell commands more often. Others need more explicit instructions. Grok Build aims to support every frontier model and optimize the harness as much as possible, including the tools they have access to.

Writing effective prompts

Your first entry point into working with agents is the prompt you give them. Consider two different approaches:

Agent example: Vague prompt
Add a user settings page
See the agent's response
Searched codebase settings page patterns
Read src/app/page.tsx
Createdpage.tsx+62
import { SettingsForm } from '@/components/SettingsForm'
import styles from './settings.module.css'

export default function SettingsPage() {
  return <main className={styles.container}>...
CreatedSettingsForm.tsx+45
import { useState } from 'react'

export function SettingsForm() {
  const [formData, setFormData] = useState({
    username: '', email: '', theme: 'light'
  })
I've created a settings page at src/app/settings/page.tsx. I used a basic form layout with the following fields:
•Username
•Email
•Password change
•Theme (light/dark)
I also added a new SettingsForm component with inline CSS modules and a saveSettings API route.

The agent had to guess at everything: what layout you wanted, the components, the styling approach, and more. Sometimes this works, but often you need to be more specific with your intent.

Compare that with a more detailed prompt that references existing patterns in your codebase:

Agent example: Constrained prompt
Add a user settings page.
Look at the existing profile page in src/app/profile/page.tsx for our layout pattern. Use the same form components from src/components/ui/Form.tsx. Settings should include:
•Display name (text input)
•Email notifications (toggle)
•Theme preference (dropdown: light, dark, system)
Store settings using our existing useUserPreferences hook. Follow the same API route pattern as src/app/api/user/profile/route.ts.
See the agent's response
Read src/app/profile/page.tsx
Read src/components/ui/Form.tsx
Read src/app/api/user/profile/route.ts
Grepped useUserPreferences
CreatedSettings.tsx+47
import { FormField, FormToggle, FormSelect } from '@/components/ui/Form'
import { useUserPreferences } from '@/hooks/useUserPreferences'

export default function Settings() {
  const { preferences, update } = useUserPreferences()
Createdroute.ts+23
// Follows the same pattern as profile/route.ts
export async function PATCH(req: Request) {
Created the settings page following your existing patterns:
•Layout: Matches Profile.tsx with the same page shell and spacing
•Form components: Uses FormField, FormToggle, and FormSelect from your UI library
•State: Wired to useUserPreferences hook for reading and saving
•API route: Added src/app/api/user/settings/route.ts following the same auth and validation pattern as profile/route.ts
The three settings (display name, email notifications toggle, theme dropdown) are all functional and save through the existing preferences system.

The second prompt is much better because it gives the agent specific instructions grounded in your codebase: existing files, components, and clear scope. The agent follows your patterns instead of inventing new ones.

The developing features chapter covers planning larger changes across multiple files.

Which approach gives agents the best results?

Managing your context

As you work with an agent, your conversation builds up context: messages, tool calls, file contents, and more. This context is the agent's working memory, and it has limitations.

Be mindful of how much context the agent is using. Start a new conversation when you're switching to a new task, or if you notice the agent making mistakes.

If you're still working on the same feature and the agent has useful context from earlier messages, it's worth continuing the conversation. But if the agent keeps going in circles, start fresh even if you're mid-feature. You can reference the old conversation to allow the agent to read the chat transcript.

Referencing a past chat to bring its context into a new conversation
Agent example: Referencing a past conversation
Continue the auth refactor from Red auth refactor. I've addressed the review feedback on the JWT expiry handling. Now update the refresh token rotation to invalidate old tokens on use.
See the agent's response
Read src/services/AuthService.ts
Read src/middleware/authenticate.ts
Grepped refreshToken
EditedAuthService.ts+12-3
    return { accessToken, refreshToken }
    // Invalidate the old refresh token before issuing a new one
    await this.tokenStore.revoke(oldRefreshToken)
    return { accessToken, refreshToken: newRefreshToken }
Updated the refresh token rotation in AuthService.ts:
•The refreshTokens() method now revokes the old refresh token before issuing a new one
•Added a revoke() call to TokenStore that adds the old token to the blocklist
•If someone tries to reuse a revoked refresh token, authenticate.ts will reject it with a 401
This closes the window where an old refresh token could be replayed after rotation.

The latest models are getting good at finding context for you. With codebase search, the agent can pull in relevant files as needed. If you know the exact file, tag it. Otherwise, give the agent a general description and let it find the right files.

Common failure pattern: scope creep

One of the most common mistakes is asking for too large of a change without planning. You might notice the agent making unrelated changes, editing files you didn't want, or losing focus.

If you see this happening, stop and consider whether you could break the task into smaller pieces. If you're planning an ambitious feature, [developing features] covers how to create solid plans and specifications(/build/agents-window/learn/creating-features). Once you have that plan and kick off the first conversation, it's often faster to iterate in smaller follow-up conversations after that.

What's next

You've learned how agent harnesses work, how to think about writing effective prompts, and how to manage your context. The next chapter goes deeper on how agents search through your codebase and help you better understand the code and architecture you're working with.

You've completed this chapter

Next: Understanding your codebase

Last updated: November 23, 2026