diff --git a/docs/agents/overview.mdx b/docs/agents/overview.mdx index 037b91b14..ad3591598 100644 --- a/docs/agents/overview.mdx +++ b/docs/agents/overview.mdx @@ -34,44 +34,59 @@ You can run Agents in three main ways: **Interactive web interface** - + Trigger from the Continue Mission Control and review results in real-time. - + ```bash # Navigate to hub.continue.dev/agents # Click "Run Agent" on any agent # Monitor progress and review outputs ``` - + Perfect for: Interactive debugging, reviewing agent outputs, team collaboration **Interactive terminal mode** - + Launch from terminal for live interaction and testing. - + ```bash cn --agent my-org/github-pr-agent # Interactive chat interface opens # Type your specific request # Review and approve actions ``` - + Perfect for: Local development, testing prompts, quick one-off tasks **Automated execution** - + Run one-off or scheduled tasks automatically without interaction. - + ```bash cn -p --agent my-org/snyk-agent "Run weekly security scan" --auto ``` - + Perfect for: CI/CD pipelines, scheduled tasks, webhook integrations + + + **Version-controlled agents in your repository** + + Define agents in `.continue/agents/` and run them with the CLI or GitHub Actions. + + ```bash + # Run a local agent file + cn --agent .continue/agents/my-agent.md + ``` + + Perfect for: Team-shared workflows, CI/CD automation, version-controlled agent definitions + + [Learn more about local agents →](/guides/run-agents-locally) + ## Pre-configured Agents @@ -213,15 +228,19 @@ The practice of using cloud agents, which we call Continuous AI, requires foreth Build your first custom agent with prompts, rules, and tools - + + + Set up version-controlled agents in your repository + + Browse pre-built agents for security, analytics, and more - + Learn to run agents from the command line - + Access the web interface to manage agents diff --git a/docs/docs.json b/docs/docs.json index afd202c95..0f34f3853 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -267,7 +267,11 @@ }, { "group": "CLI Guides", - "pages": ["guides/cli", "guides/doc-writing-agent-cli"] + "pages": [ + "guides/cli", + "guides/run-agents-locally", + "guides/doc-writing-agent-cli" + ] }, { "group": "Continuous AI Guides", diff --git a/docs/guides/run-agents-locally.mdx b/docs/guides/run-agents-locally.mdx new file mode 100644 index 000000000..1279c7891 --- /dev/null +++ b/docs/guides/run-agents-locally.mdx @@ -0,0 +1,487 @@ +--- +title: "Run Agents Locally with .continue/agents" +sidebarTitle: "Run Agents Locally" +description: "Set up version-controlled agents in your repository and run them with Continue CLI or GitHub Actions" +--- + + + A local agent system that: + - Keeps agent definitions version-controlled alongside your code + - Runs agents with Continue CLI for local development + - Automates agent execution on pull requests via GitHub Actions + - Applies consistent workflows across your team + + +## Why Local Agents? + + + + Agent definitions evolve with your codebase. Track changes, review in PRs, and roll back when needed. + + + + Everyone runs the same agents with the same rules. No configuration drift across machines. + + + + Trigger agents automatically on pull requests, commits, or any GitHub event. + + + +## Prerequisites + +Before starting, ensure you have: + +- [Continue CLI installed](/cli/install) (`npm i -g @continuedev/cli`) +- An LLM API key (e.g., `ANTHROPIC_API_KEY`) +- [GitHub CLI](https://cli.github.com/) if your agents interact with GitHub + +## Quick Setup + + + + ```bash + mkdir -p .continue/agents + ``` + + + + Create a markdown file with YAML frontmatter defining the agent's behavior: + + ```bash + touch .continue/agents/my-agent.md + ``` + + Add content like: + + ```markdown + --- + name: My First Agent + description: Describes what this agent does + tools: built_in + --- + + You are an agent that helps with [specific task]. + + ## Your Task + + 1. First, do this + 2. Then, do that + 3. Finally, complete this + + ## Rules + + - Follow this guideline + - Avoid this pattern + ``` + + + + ```bash + cn --agent .continue/agents/my-agent.md + ``` + + For headless execution (useful for automation): + + ```bash + cn -p --agent .continue/agents/my-agent.md + ``` + + + +## Agent File Format + +Agent files are markdown documents with YAML frontmatter. The frontmatter configures the agent, and the markdown body contains the prompt instructions. + +### Frontmatter Options + +| Field | Required | Description | +|-------|----------|-------------| +| `name` | Yes | Display name for the agent | +| `description` | Yes | Brief description of what the agent does | +| `tools` | No | Tool configuration (`built_in` for standard tools) | + + + The markdown body is the agent's system prompt. Write clear, specific instructions with examples for best results. + + +## Example: Conventional PR Title Agent + +This agent updates pull request titles to follow conventional commit format: + +```markdown +--- +name: Conventional Title +description: Updates PR title to follow conventional commit format +tools: built_in +--- + +You are reviewing a pull request to format its title according to conventional commit standards. + +## Your Task + +1. **Get the current PR title and number:** + ```bash + gh pr view --json number,title -q '{number: .number, title: .title}' + ``` + +2. **Get the PR diff to understand changes:** + ```bash + git diff origin/main...HEAD --name-only + ``` + +3. **Analyze the changes to determine type:** + - `feat`: New feature + - `fix`: Bug fix + - `docs`: Documentation only + - `refactor`: Code refactoring + - `chore`: Build, tooling, configs + +4. **Update the PR title:** + ```bash + gh pr edit --title "type: description" + ``` + +## Rules + +- If title already follows format, do NOT modify +- Keep description under 72 characters +- Use lowercase, no period at end +``` + +## Security Considerations + + + Agents can execute commands and modify files. Review these security practices before deploying to CI/CD. + + +### Limit Agent Permissions + +When running agents in CI/CD, follow the principle of least privilege: + + + + Only grant the permissions your agent needs: + + ```yaml + permissions: + contents: read # Read repository files + pull-requests: write # Comment on PRs + # Avoid: contents: write unless agent needs to push commits + ``` + + + Avoid granting `contents: write` unless your agent specifically needs to push commits. This prevents accidental or malicious code modifications. + + + + + Use `cn` permission flags to restrict what agents can do: + + ```bash + # Only allow specific tools + cn --allow "Read()" --allow "Grep()" --exclude "Bash()" \ + --agent .continue/agents/analysis-only.md + + # Always ask before running commands + cn --ask "Bash(*)" --agent .continue/agents/my-agent.md + ``` + + Learn more in the [CLI documentation](/cli/overview#how-to-set-tool-permissions). + + + + Never commit secrets. Use GitHub Actions secrets or environment variables: + + ```yaml + env: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + GH_TOKEN: ${{ github.token }} # Scoped to the repo + ``` + + + Never hardcode API keys in agent files or workflows. Always use secrets management. + + + + +### Review Agent Outputs + +Before enabling fully automated agents: + +1. **Test locally first** - Run agents with `cn` to verify behavior +2. **Use `--ask` mode** - Require approval for sensitive operations during testing +3. **Review CI logs** - Check what commands agents execute in your workflows +4. **Start with read-only agents** - Begin with agents that analyze rather than modify + + + For high-risk operations (like pushing commits or modifying infrastructure), consider requiring manual approval steps in your workflow. + + +## GitHub Actions Integration + +Automate agent execution on pull requests with this workflow. + +### Basic Workflow + +Create `.github/workflows/continue-agents.yml`: + +```yaml +name: Continue Agents + +on: + pull_request: + types: [opened, reopened, synchronize] + branches: + - main + +permissions: + contents: write + checks: write + pull-requests: write + +jobs: + discover: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.discover.outputs.matrix }} + has-agents: ${{ steps.discover.outputs.has_agents }} + steps: + - uses: actions/checkout@v4 + + - name: Discover agents + id: discover + run: | + AGENTS_DIR=".continue/agents" + if [ -d "$AGENTS_DIR" ]; then + FILES=$(find "$AGENTS_DIR" -name "*.md" -type f 2>/dev/null | jq -R . | jq -sc .) + COUNT=$(echo "$FILES" | jq 'length') + HAS_AGENTS=$([[ $COUNT -gt 0 ]] && echo "true" || echo "false") + else + FILES="[]" + HAS_AGENTS="false" + fi + + echo "matrix=$FILES" >> $GITHUB_OUTPUT + echo "has_agents=$HAS_AGENTS" >> $GITHUB_OUTPUT + + run-agent: + needs: discover + if: needs.discover.outputs.has-agents == 'true' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + agent: ${{ fromJson(needs.discover.outputs.matrix) }} + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install Continue CLI + run: npm i -g @continuedev/cli + + - name: Extract agent name + id: agent-name + run: | + AGENT_FILE="${{ matrix.agent }}" + AGENT_NAME=$(basename "$AGENT_FILE" .md) + echo "name=$AGENT_NAME" >> $GITHUB_OUTPUT + + - name: Create Check Run + id: check + uses: actions/github-script@v7 + env: + AGENT_NAME: ${{ steps.agent-name.outputs.name }} + with: + script: | + const { data: check } = await github.rest.checks.create({ + owner: context.repo.owner, + repo: context.repo.repo, + name: `Continue: ${process.env.AGENT_NAME}`, + head_sha: context.sha, + status: 'in_progress', + started_at: new Date().toISOString(), + }); + core.setOutput('id', check.id); + + - name: Run agent + id: run + env: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + GH_TOKEN: ${{ github.token }} + run: | + AGENT_FILE="${{ matrix.agent }}" + + if OUTPUT=$(cn -p --agent "$AGENT_FILE" 2>&1); then + echo "success=true" >> $GITHUB_OUTPUT + echo "output<> $GITHUB_OUTPUT + echo "$OUTPUT" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + else + echo "success=false" >> $GITHUB_OUTPUT + echo "error<> $GITHUB_OUTPUT + echo "$OUTPUT" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + fi + + - name: Update Check Run + if: always() + uses: actions/github-script@v7 + env: + AGENT_OUTPUT: ${{ steps.run.outputs.output }} + AGENT_ERROR: ${{ steps.run.outputs.error }} + AGENT_SUCCESS: ${{ steps.run.outputs.success }} + CHECK_RUN_ID: ${{ steps.check.outputs.id }} + with: + script: | + const success = process.env.AGENT_SUCCESS === 'true'; + const output = process.env.AGENT_OUTPUT || ''; + const error = process.env.AGENT_ERROR || ''; + + await github.rest.checks.update({ + owner: context.repo.owner, + repo: context.repo.repo, + check_run_id: parseInt(process.env.CHECK_RUN_ID, 10), + status: 'completed', + conclusion: success ? 'success' : 'failure', + completed_at: new Date().toISOString(), + output: { + title: success ? 'Agent completed' : 'Agent failed', + summary: success + ? `Agent completed.\n\n\`\`\`\n${output.slice(0, 60000)}\n\`\`\`` + : `Agent failed.\n\n\`\`\`\n${error.slice(0, 60000)}\n\`\`\``, + }, + }); + + - name: Fail if agent failed + if: steps.run.outputs.success != 'true' + run: exit 1 +``` + +### Required Secrets + +Add these secrets to your repository under **Settings > Secrets and variables > Actions**: + +| Secret | Description | +|--------|-------------| +| `ANTHROPIC_API_KEY` | Your Anthropic API key for Claude | + + + The `GH_TOKEN` is automatically provided by GitHub Actions via `${{ github.token }}`. This token is scoped to the repository and expires after the workflow completes. + + +## Environment Variables + +When running agents locally that interact with GitHub, set the `GH_TOKEN`: + +```bash +# Use your GitHub CLI token +export GH_TOKEN=$(gh auth token) +cn --agent .continue/agents/my-agent.md +``` + +## Directory Structure + +A typical setup looks like: + +``` +your-repo/ +├── .continue/ +│ └── agents/ +│ ├── conventional-title.md +│ ├── deploy-checklist.md +│ └── security-scan.md +├── .github/ +│ └── workflows/ +│ └── continue-agents.yml +└── ... +``` + +## Troubleshooting + + + + Ensure the path is correct and the file exists: + + ```bash + ls -la .continue/agents/ + ``` + + The path must be relative to your repository root. + + + + If agents using `gh` fail, verify authentication: + + ```bash + # Check auth status + gh auth status + + # Set token for local testing + export GH_TOKEN=$(gh auth token) + ``` + + In GitHub Actions, ensure `GH_TOKEN: ${{ github.token }}` is set in the environment. + + + + - Simplify the prompt and add more specific instructions + - Check if the agent has access to required tools + - Enable verbose logging: `cn --verbose --agent .continue/agents/my-agent.md` + - Review logs at `~/.continue/logs/cn.log` + + + + Verify your agents are in the correct directory: + + ```bash + find .continue/agents -name "*.md" -type f + ``` + + The workflow looks for `.md` files in `.continue/agents/`. + + + +## Best Practices + + + + Begin with read-only agents that analyze code before adding agents that make changes. + + + + Always run `cn --agent` locally before enabling CI automation. + + + + Name agent files clearly: `conventional-title.md`, `security-scan.md`, `deploy-checklist.md`. + + + + Each agent should do one thing well. Combine multiple agents for complex workflows. + + + +## Next Steps + + + + Learn about agent components and capabilities + + + + Full Continue CLI documentation + + + + Add external tools to your agents + + + + Configure agent behavior with rules + + diff --git a/draft_pr.md b/draft_pr.md new file mode 100644 index 000000000..64fda5d7f --- /dev/null +++ b/draft_pr.md @@ -0,0 +1,22 @@ +## Description + +[TODO: Add a brief description of what changed in this PR] + +## AI Code Review + +- **Team members only**: AI review runs automatically when PR is opened or marked ready for review +- Team members can also trigger a review by commenting `@continue-review` + +## Checklist + +- [ ] I've read the [contributing guide](https://github.com/continuedev/continue/blob/main/CONTRIBUTING.md) +- [ ] The relevant docs, if any, have been updated or created +- [ ] The relevant tests, if any, have been updated or created + +## Screen recording or screenshot + +[TODO: Add screen recording or screenshot if applicable - see [this PR](https://github.com/continuedev/continue/pull/6455) as a good example] + +## Tests + +[TODO: Describe what tests were added or updated to ensure the changes work as expected]