Skip to content

CodeTriage Agent

The CodeTriage agent performs root cause analysis by reading source code and using multi-turn LLM prompting.

  • Clone the target repository in a Sandbox
  • Read source code relevant to the error
  • Perform LLM-powered root cause analysis
  • Validate results with a second-opinion model for low-confidence findings
  • Route incidents to FixAgent or mark as needs_human
  1. Receive a TriageReadyMessage from the queue
  2. Clone the repository in a Sandbox container
  3. Read the entry point source code (src/index.ts)
  4. Send a structured prompt to Workers AI requesting JSON output:
{
"rootCauseFile": "src/handlers/auth.ts",
"rootCauseLines": [42, 58],
"rootCauseExplanation": "The JWT validation function doesn't handle expired tokens...",
"fixStrategy": "Add a check for TokenExpiredError before the general catch block...",
"confidence": "high",
"affectedFiles": ["src/handlers/auth.ts", "src/middleware/auth.ts"]
}

If the initial analysis returns low confidence:

  1. A second LLM call is made using a different model (Llama 3.3 70B)
  2. The second model reviews the first analysis and either confirms or revises it
  3. If confidence remains low after validation, the incident is marked needs_human
ConfidenceAction
high or mediumPublish to fix-ready queue
low (after validation)Mark needs_human
PurposeModel
Initial analysisWorkers AI default (Llama 3.3 70B)
Validation@cf/meta/llama-3.3-70b-instruct-fp8-fast

All LLM calls are recorded in the llm_calls D1 table for cost tracking and audit.

MethodPathDescription
POST/triageTriage an incident from a queue message
GET/statusCurrent agent state

src/agents/code-triage.ts