範例 - Amazon Q Developer

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

範例

本節提供常見開發工作流程和使用案例的自訂代理程式組態實際範例。

AWS 專業自訂代理程式

此自訂代理程式已針對 AWS 基礎設施管理和開發任務進行最佳化。它提供預先核准的 AWS 工具存取權,同時包含相關文件。

範例 AWS 專家自訂代理程式組態
{ "description": "Specialized custom agent for AWS infrastructure and development tasks", "tools": [ "fs_read", "fs_write", "execute_bash", "use_aws" ], "allowedTools": [ "fs_read", "use_aws" ], "toolsSettings": { "use_aws": { "allowedServices": [ "s3", "lambda", "cloudformation", "ec2", "iam", "logs" ] }, "fs_write": { "allowedPaths": [ "infrastructure/**", "scripts/**", "*.yaml", "*.yml", "*.json" ] } }, "resources": [ "file://README.md", "file://infrastructure/**/*.yaml", "file://infrastructure/**/*.yml", "file://docs/aws-setup.md", "file://scripts/deploy.sh" ], "hooks": { "agentSpawn": [ { "command": "aws sts get-caller-identity", "timeout_ms": 10000, "cache_ttl_seconds": 300 } ] } }

此自訂代理程式的使用案例:

  • 部署 CloudFormation 堆疊

  • 管理 S3 儲存貯體和 Lambda 函數

  • 故障診斷 AWS 服務問題

  • 以程式碼形式檢閱和更新基礎設施

開發工作流程自訂代理程式

此自訂代理程式專為一般軟體開發任務而設計,包括程式碼檢閱、測試和 Git 操作。

範例 開發工作流程自訂代理程式組態
{ "description": "General development workflow custom agent with Git integration", "mcpServers": { "git": { "command": "git-mcp-server", "args": [], "timeout": 30000 } }, "tools": [ "fs_read", "fs_write", "execute_bash", "@git" ], "allowedTools": [ "fs_read", "@git/git_status", "@git/git_log", "@git/git_diff" ], "toolAliases": { "@git/git_status": "status", "@git/git_log": "log", "@git/git_diff": "diff" }, "toolsSettings": { "fs_write": { "allowedPaths": [ "src/**", "tests/**", "docs/**", "*.md", "*.json", "package.json", "requirements.txt" ] } }, "resources": [ "file://README.md", "file://CONTRIBUTING.md", "file://docs/**/*.md", "file://package.json", "file://requirements.txt" ], "hooks": { "agentSpawn": [ { "command": "git status --porcelain", "timeout_ms": 5000 }, { "command": "git branch --show-current", "timeout_ms": 3000 } ] } }

此自訂代理程式的使用案例:

  • 程式碼檢閱和分析

  • 撰寫和更新測試

  • Git 工作流程管理

  • 說明文件更新

  • 相依性管理

程式碼檢閱自訂代理程式

此自訂代理程式特別著重於程式碼檢閱任務,其工具和內容經過最佳化,可用於分析程式碼品質、安全性和最佳實務。

範例 程式碼檢閱自訂代理程式組態
{ "description": "Specialized custom agent for code review and quality analysis", "tools": [ "fs_read", "execute_bash" ], "allowedTools": [ "fs_read", "execute_bash" ], "toolsSettings": { "execute_bash": { "allowedCommands": [ "grep", "find", "wc", "head", "tail", "cat", "diff", "git diff", "git log", "eslint", "pylint", "rubocop" ] } }, "resources": [ "file://CONTRIBUTING.md", "file://docs/coding-standards.md", "file://docs/security-guidelines.md", "file://.eslintrc.json", "file://.pylintrc", "file://pyproject.toml" ], "hooks": { "agentSpawn": [ { "command": "git diff --name-only HEAD~1", "timeout_ms": 5000, "max_output_size": 2048 } ], "userPromptSubmit": [ { "command": "find . -name '*.py' -o -name '*.js' -o -name '*.ts' | wc -l", "timeout_ms": 3000, "cache_ttl_seconds": 60 } ] } }

此自訂代理程式的使用案例:

  • 檢閱程式碼品質的提取請求

  • 識別安全漏洞

  • 檢查是否符合編碼標準

  • 分析程式碼複雜性和可維護性

  • 建議改善和重構機會

專案特定的自訂代理程式

此範例說明如何建立針對特定專案量身打造的自訂代理程式,包括專案特定的工具、文件和建置程序。

範例 專案特定的自訂代理程式組態
{ "description": "Custom agent for the mobile app backend project", "mcpServers": { "docker": { "command": "docker-mcp-server", "args": ["--socket", "/var/run/docker.sock"] }, "database": { "command": "postgres-mcp-server", "args": ["--connection", "postgresql://localhost:5432/myapp"], "env": { "PGPASSWORD": "$DATABASE_PASSWORD" } } }, "tools": [ "fs_read", "fs_write", "execute_bash", "@docker", "@database" ], "allowedTools": [ "fs_read", "@docker/docker_ps", "@docker/docker_logs", "@database/query_read_only" ], "toolAliases": { "@docker/docker_ps": "containers", "@docker/docker_logs": "logs", "@database/query_read_only": "query" }, "toolsSettings": { "fs_write": { "allowedPaths": [ "src/**", "tests/**", "migrations/**", "docker-compose.yml", "Dockerfile", "requirements.txt" ] }, "execute_bash": { "allowedCommands": [ "npm test", "npm run build", "python manage.py test", "docker-compose up", "docker-compose down" ] } }, "resources": [ "file://README.md", "file://docs/api-documentation.md", "file://docs/database-schema.md", "file://docker-compose.yml", "file://requirements.txt", "file://src/config/settings.py" ], "hooks": { "agentSpawn": [ { "command": "docker-compose ps", "timeout_ms": 10000, "cache_ttl_seconds": 30 }, { "command": "git status --porcelain", "timeout_ms": 5000 } ] } }

此自訂代理程式的使用案例:

  • 管理 Docker 容器和服務

  • 執行資料庫查詢和遷移

  • 建置和測試應用程式

  • 偵錯生產問題

  • 更新 API 文件

建立有效自訂代理程式的秘訣

  • 啟動簡單 - 從基本工具組態開始,並視需要增加複雜性

  • 使用描述性名稱 - 選擇明確指出其用途的自訂代理程式名稱

  • 包含相關內容 - 將專案文件和組態檔案新增至資源

  • 預先核准安全工具 - 在 allowedTools 中包含常用的低風險工具

  • 使用動態內容的掛鉤 - 透過命令掛鉤包含目前的系統狀態

  • 限制工具範圍 - 使用 toolsSettings 限制工具存取相關路徑和服務

  • 徹底測試 - 確認您的自訂代理程式組態如預期般運作

  • 記錄您的自訂客服人員 - 使用清晰的描述來協助團隊成員了解自訂客服人員的目的