Skip to content

Coder Agent

Alessio Rocchi edited this page Jan 27, 2026 · 1 revision

Coder Agent

Expert software engineer for writing clean, maintainable code.


Purpose

Write, edit, and refactor code with clean, maintainable implementations.

System Prompt

You are an expert software developer focused on writing clean, efficient code.

Core Principles:
- Write simple, readable code that solves the problem directly
- Follow established patterns in the codebase
- Avoid over-engineering - only add complexity when truly needed
- Use meaningful names and clear structure

Approach:
1. Understand the requirement fully before coding
2. Check existing code for patterns and conventions
3. Write minimal code that achieves the goal
4. Include only essential error handling
5. Test your changes work correctly

Guidelines:
- Prefer editing existing files over creating new ones
- Match the style of surrounding code
- Don't add features that weren't requested
- Keep functions focused and small
- Use types effectively for clarity

Capabilities

  • write-code - Create new code from scratch
  • edit-code - Modify existing code
  • refactor - Improve code quality
  • debug - Fix bugs and issues
  • implement-features - Build complete features

When to Use

  • Implementing new features
  • Fixing bugs
  • Refactoring code
  • Adding functionality
  • Optimizing code

Examples

Basic Usage

Spawn a coder agent named "auth-coder" to implement JWT token validation

With Context

// Start session
const session = await memory.createSession({ feature: 'authentication' });

// Spawn coder in session
const coder = spawnAgent('coder', {
  name: 'auth-coder',
  sessionId: session.id
});

// Store requirements in memory
await memory.store('requirements:jwt', 'JWT should use HS256, expire in 1h', {
  namespace: `session:${session.id}`
});

// Coder can access these requirements

Implementation Task

Using the auth-coder agent:
1. Implement a function to generate JWT tokens
2. Use HS256 algorithm
3. Set expiration to 1 hour
4. Include user ID and email in payload
5. Add proper TypeScript types

Expected Output:

import jwt from 'jsonwebtoken';

interface JWTPayload {
  userId: string;
  email: string;
}

/**
 * Generates a JWT token for a user
 * @param userId - The user's unique identifier
 * @param email - The user's email address
 * @returns JWT token string
 */
export function generateToken(userId: string, email: string): string {
  const payload: JWTPayload = {
    userId,
    email
  };

  const secret = process.env.JWT_SECRET;
  if (!secret) {
    throw new Error('JWT_SECRET environment variable not set');
  }

  return jwt.sign(payload, secret, {
    algorithm: 'HS256',
    expiresIn: '1h'
  });
}

Refactoring Task

Using the auth-coder agent, refactor this function to be more maintainable:

function auth(u,p){return u&&p&&db.query("SELECT*FROM users WHERE name='"+u+"'AND pass='"+p+"'")}

Expected Output:

interface User {
  id: string;
  name: string;
  passwordHash: string;
}

/**
 * Authenticates a user with username and password
 * @param username - User's username
 * @param password - User's password (will be hashed for comparison)
 * @returns User object if authenticated, null otherwise
 */
export async function authenticateUser(
  username: string,
  password: string
): Promise<User | null> {
  if (!username || !password) {
    return null;
  }

  // Use parameterized query to prevent SQL injection
  const query = `
    SELECT id, name, password_hash
    FROM users
    WHERE name = ?
  `;

  const user = await db.queryOne<User>(query, [username]);

  if (!user) {
    return null;
  }

  // Compare password hash (using bcrypt or similar)
  const isValid = await comparePassword(password, user.passwordHash);

  return isValid ? user : null;
}

Best Practices

Provide Clear Requirements

✓ GOOD:
"Implement a function to validate email addresses using a regex pattern, return boolean"

✗ BAD:
"Do email stuff"

Give Context

✓ GOOD:
"In the user authentication module, add rate limiting to the login endpoint (max 5 attempts per minute)"

✗ BAD:
"Add rate limiting"

Specify Language & Framework

✓ GOOD:
"Using TypeScript and Express, create a middleware for request logging"

✗ BAD:
"Create a middleware"

Common Workflows

Workflow 1: New Feature

1. Researcher explores existing patterns
2. Architect designs the feature
3. Coder implements
4. Tester creates tests
5. Reviewer validates

Workflow 2: Bug Fix

1. Researcher finds the bug location
2. Coder fixes the issue
3. Tester adds regression test

Workflow 3: Refactoring

1. Analyst identifies code smells
2. Architect designs better structure
3. Coder refactors
4. Tester ensures behavior preserved

Tips

Leverage Memory

Store patterns and conventions for reuse:

await memory.store('pattern:error-handling', 
  'Use custom AppError class with status codes',
  { namespace: 'coding-standards' }
);

// Coder can reference these patterns

Use Sessions for Context

const session = await memory.createSession({ feature: 'user-profile' });

// All coders in this session share context
const frontendCoder = spawnAgent('coder', { sessionId: session.id });
const backendCoder = spawnAgent('coder', { sessionId: session.id });

Combine with Other Agents

1. Spawn coder agent
2. Implement feature
3. Spawn adversarial agent
4. Review for security issues
5. Coder fixes issues

Related

Clone this wiki locally