> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bothive.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Codebase Assistants

> Build AI agents that read your repos, review PRs, and answer code questions.

<div className="hero-container">
  <h1 className="hero-title">
    Codebase Assistants
  </h1>

  <p className="hero-subtitle">
    AI agents that understand your codebase — reviewing PRs, answering "how does X work?", and keeping your team unblocked.
  </p>
</div>

## What you can build

<CardGroup cols={2}>
  <Card title="PR Reviewer" icon="code-pull-request" className="glass-effect">
    Automatically reviews pull requests for security issues, performance problems, and style violations. Posts constructive comments on GitHub.
  </Card>

  <Card title="Code Q&A Agent" icon="question" className="glass-effect">
    Answers "how does X work?" questions by reading the actual source code — not hallucinating from memory.
  </Card>

  <Card title="Issue Triage Bot" icon="tags" className="glass-effect">
    Reads incoming GitHub issues, classifies them (bug/feature/docs), adds labels, and assigns to the right team.
  </Card>

  <Card title="Docs Generator" icon="file-code" className="glass-effect">
    Reads functions and modules, generates docstrings and README sections, and opens PRs with the generated docs.
  </Card>
</CardGroup>

## Setup

<Steps>
  <Step title="Connect GitHub">
    **Integrations** → **GitHub** → **Connect with GitHub** → authorize the repos you want the agent to access.

    <Warning>
      Only grant access to repositories the agent needs. Use a dedicated GitHub App or OAuth App — not your personal account — for production agents.
    </Warning>
  </Step>

  <Step title="Write your agent">
    Use GitHub capabilities in HiveLang:

    ```hivelang theme={null}
    bot PRReviewer {
      description: "Automated PR reviewer for the engineering team"

      capabilities {
        github.getPRDiff
        github.addComment
        github.labelPR
        github.listFiles
      }
    }
    ```
  </Step>

  <Step title="Configure PR review trigger">
    Set up a GitHub webhook to trigger the agent on new PRs:

    In GitHub repo → **Settings** → **Webhooks** → Add webhook:

    * Payload URL: `https://api.bothive.cloud/v1/bots/{bot_id}/webhook`
    * Content type: `application/json`
    * Events: `Pull requests`
  </Step>

  <Step title="Test on a draft PR">
    Open a draft PR → confirm the agent posts a review comment → check the trace to verify the diff was read correctly.
  </Step>
</Steps>

## Full swarm example — code review team

```hivelang theme={null}
swarm CodeReviewTeam {
  description: "Multi-agent PR review system"

  agent SecurityReviewer {
    role: "Find security vulnerabilities and flag them as critical"
    capabilities {
      github.getPRDiff
      github.listFiles
    }
  }

  agent QualityReviewer {
    role: "Review code quality, performance, and style"
    capabilities {
      github.getPRDiff
      knowledgebase.search
    }
  }

  agent CommentPoster {
    role: "Post consolidated review comments on the PR"
    capabilities {
      github.addComment
      github.labelPR
    }
  }

  on github.pull_request.opened {
    diff = call github.getPRDiff with { pr_number: event.number }

    security_issues = delegate to SecurityReviewer with { diff: diff }
    quality_issues = delegate to QualityReviewer with { diff: diff }

    if security_issues.count > 0 {
      call github.labelPR with { label: "security-review-required" }
    }

    delegate to CommentPoster with {
      security: security_issues,
      quality: quality_issues,
      pr_number: event.number
    }
  }
}
```

## GitHub capabilities reference

| Capability           | What it does                      | Read/Write |
| -------------------- | --------------------------------- | ---------- |
| `github.getPRDiff`   | Get the full diff of a PR         | Read       |
| `github.addComment`  | Post a comment on a PR or issue   | Write      |
| `github.labelPR`     | Add or remove labels on a PR      | Write      |
| `github.listFiles`   | List files changed in a PR        | Read       |
| `github.readFile`    | Read contents of a file at a path | Read       |
| `github.searchCode`  | Search code across a repo         | Read       |
| `github.createIssue` | Open a new GitHub issue           | Write      |
| `github.getIssue`    | Read an existing issue            | Read       |

## Best practices for code agents

<AccordionGroup>
  <Accordion title="Never auto-push code without human approval">
    Code agents should always open PRs or suggest changes — never commit directly to main. Add explicit rules: "Always create a PR, never push directly."
  </Accordion>

  <Accordion title="Use read-only access where possible">
    For PR review and Q\&A agents, connect only read scopes. Write access (`github.addComment`) should be a deliberate, minimal addition.
  </Accordion>

  <Accordion title="Provide your coding standards in the knowledge base">
    Upload your team's style guide, security checklist, and architecture decisions as a knowledge base. Connect it to the agent so it reviews against your actual standards, not generic ones.
  </Accordion>

  <Accordion title="Tune the model for code">
    Claude 3.5 Sonnet is excellent for code review. GPT-4o is good for mixed text + code. Set `model: claude-3-5-sonnet` in your HiveLang for best code quality.
  </Accordion>
</AccordionGroup>

## Next reads

<CardGroup cols={3}>
  <Card title="Custom Integrations" icon="plug" href="./custom-integrations" className="glass-effect" />

  <Card title="Integration Capabilities" icon="list" href="./integration-capabilities" className="glass-effect" />

  <Card title="HiveLang v5" icon="code" href="../concepts/hivelang" className="glass-effect" />
</CardGroup>
