본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

팁 & 모범 사례

원문 보기 위키 갱신

팁 & 모범 사례 (Tips & Best Practices)

효과적이고 효율적이며 안전한 에이전트를 구축하기 위한 전문가 지침이에요.

출처: 문서

본문

구성 팁 (Configuration Tips)

빠른 시작을 위한 자동 모드 (Auto Mode for Quick Start)

구성 파일이 없나요? Docker Agent가 사용 가능한 API 키를 자동으로 감지하고 적절한 모델을 사용할 수 있어요:

# Automatically uses the best available provider
$ docker agent run

# Provider priority: Anthropic → OpenAI → Google → Mistral → Amazon Bedrock → DMR

특수 auto 모델 값은 구성에서도 동작해요:

agents:
  root:
    model: auto # Uses best available provider
    description: Adaptive assistant
    instruction: You are a helpful assistant.

환경 변수 보간 (Environment Variable Interpolation)

명령은 환경 변수에 대해 JavaScript 템플릿 리터럴 구문을 지원해요:

agents:
  root:
    model: openai/gpt-4o
    description: Deployment assistant
    instruction: You help with deployments.
    commands:
      # Simple variable
      greet: "Hello ${env.USER}!"

      # With default value
      deploy: "Deploy to ${env.ENV || 'staging'}"

      # Multiple variables
      release: "Release ${env.PROJECT} v${env.VERSION || '1.0.0'}"

모델 별칭은 자동 고정됨 (Model Aliases Are Auto-Pinned)

Docker Agent는 모델 별칭을 최신 고정 버전으로 자동 해석해요. 이것은 재현 가능한 동작을 보장해요:

# You write:
model: anthropic/claude-sonnet-4-5

# docker-agent resolves to:
# anthropic/claude-sonnet-4-5-20250929 (or latest available)

특정 버전을 사용하려면 구성에서 명시적으로 지정하세요.

성능 팁 (Performance Tips)

더 빠른 시작을 위한 도구 지연 (Defer Tools for Faster Startup)

큰 MCP toolset은 에이전트 시작을 늦출 수 있어요. defer 를 사용해 도구를 온디맨드로 로드해요:

agents:
  root:
    model: openai/gpt-4o
    description: Multi-tool assistant
    instruction: You have many tools available.
    toolsets:
      - type: mcp
        ref: docker:github-official
        defer: true
      - type: mcp
        ref: docker:slack
        defer: true
      - type: mcp
        ref: docker:linear
        defer: true

또는 toolset 안의 특정 도구를 지연시켜요:

toolsets:
  - type: mcp
    ref: docker:github-official
    defer:
      - "list_issues"
      - "search_repos"
  - type: mcp
    ref: docker:slack
    defer:
      - "list_channels"

MCP 도구 필터링 (Filter MCP Tools)

많은 MCP 서버는 수십 개의 도구를 노출해요. 필요한 것만 필터링해요:

toolsets:
  - type: mcp
    ref: docker:github-official
    # Only expose these specific tools
    tools:
      - list_issues
      - create_issue
      - get_pull_request
      - create_pull_request

도구가 적을수록 도구 선택이 빠르고 모델의 혼란이 적어요.

max_iterations 설정 (Set max_iterations)

강력한 도구를 가진 에이전트에는 무한 루프를 막기 위해 항상 max_iterations 를 설정하세요:

agents:
  developer:
    model: anthropic/claude-sonnet-4-5
    description: Development assistant
    instruction: You are a developer.
    max_iterations: 30 # Reasonable limit for development tasks
    toolsets:
      - type: filesystem
      - type: shell

전형적인 값: 개발 에이전트 20-30, 간단한 작업 10-15.

신뢰성 팁 (Reliability Tips)

폴백 모델 사용 (Use Fallback Models)

제공자 중단이나 요청 제한에 대한 복원력을 위해 폴백 모델을 구성해요:

agents:
  root:
    model: anthropic/claude-sonnet-4-5
    description: Reliable assistant
    instruction: You are a helpful assistant.
    fallback:
      models:
        # Different provider for resilience
        - openai/gpt-4o
        # Cheaper model as last resort
        - openai/gpt-4o-mini
      retries: 2 # Retry 5xx errors twice
      cooldown: 1m # Stick with fallback for 1 min after rate limit

폴백 체인의 모범 사례:

  • 진짜 중복을 위해 다른 제공자 사용
  • 선호도순 정렬 (좋은 것 먼저)
  • 최후의 수단으로 더 저렴/빠른 모델 포함

비추론 모델용 Think 도구 사용 (Use Think Tool for Non-Reasoning Models)

think 도구는 내장 thinking 능력이 없는 모델을 위한 추론 스크래치패드를 제공해요:

toolsets:
  - type: think # Useful for models without native reasoning

에이전트는 계획과 의사 결정을 위한 스크래치패드로 그것을 사용해요. 모델이 이미 thinking 버짓을 지원한다면(예: extended thinking이 있는 Claude, OpenAI o-series, thinking이 활성화된 Gemini), 이 도구는 필요 없어요 — 모델은 내부적으로 추론할 수 있어요.

보안 팁 (Security Tips)

--yolo 모드 주의해서 사용 (Use --yolo Mode Carefully)

--yolo 플래그는 확인 없이 모든 도구 호출을 자동 승인해요:

# Auto-approve everything (use with caution!)
$ docker agent run agent.yaml --yolo

언제 적절한가:

  • 통제된 입력이 있는 CI/CD 파이프라인
  • 자동화된 테스트
  • 안전하고 읽기 전용 도구만 있는 에이전트

언제 피할 것:

  • 테스트되지 않은 프롬프트가 있는 대화형 세션
  • 셸이나 파일시스템 쓰기 접근이 있는 에이전트
  • 검토되지 않은 동작이 해를 끼칠 수 있는 어떤 상황

Permissions와 Sandbox 결합 (Combine Permissions with Sandbox)

심층 방어를 위해 permissions와 샌드박스 모드를 모두 사용해요:

agents:
  secure_dev:
    model: anthropic/claude-sonnet-4-5
    description: Secure development assistant
    instruction: You are a secure coding assistant.
    toolsets:
      - type: filesystem
      - type: shell

    permissions:
      allow:
        - "read_*"
        - "shell:cmd=go*"
        - "shell:cmd=npm*"
      deny:
        - "shell:cmd=sudo*"
        - "shell:cmd=rm*-rf*"
# Run with sandbox enabled
docker-agent run --sandbox agent.yaml

전역 권한 가드레일 설정 (Set Global Permission Guardrails)

사용자 구성의 전역 권한을 사용해 모든 에이전트에 걸쳐 안전 규칙을 강제해요:

# ~/.config/cagent/config.yaml
settings:
  permissions:
    deny:
      - "shell:cmd=sudo*"
      - "shell:cmd=rm*-rf*"
      - "shell:cmd=git push --force*"
    allow:
      - "read_*"
      - "shell:cmd=ls*"
      - "shell:cmd=cat*"

이 규칙들은 에이전트 레벨 권한과 병합돼요. 전역 구성의 deny 패턴은 에이전트 구성이 재정의할 수 없으므로, 어떤 에이전트를 실행하든 위험한 명령이 차단된 상태로 유지되는 걸 신뢰할 수 있어요.

감사 로깅용 Hooks 사용 (Use Hooks for Audit Logging)

컴플라이언스나 디버깅을 위해 모든 도구 호출을 로그해요:

agents:
  audited:
    model: openai/gpt-4o
    description: Audited assistant
    instruction: You are a helpful assistant.
    hooks:
      post_tool_use:
        - matcher: "*"
    hooks:
      - type: command
        command: "./scripts/audit-log.sh"

다중 에이전트 팁 (Multi-Agent Tips)

Handoffs vs Sub-Agents

sub_agents 와 handoffs 의 차이를 이해해요:

  • sub_agents(transfer_task) — 하위 세션의 자식에게 작업을 위임하고, 결과를 기다린 뒤 계속. 계층적: 부모가 통제를 유지.
sub_agents: [researcher, writer]
  • handoffs(동료 간) — 전체 대화를 같은 세션의 다른 에이전트에게 넘겨요. 활성 에이전트가 전환되고 전체 기록을 봐요. 에이전트가 순환을 형성할 수 있어요.
handoffs:
  - specialist
  - summarizer

상세 비교는 Multi-Agent Systems 참고.

하위 에이전트에 명확한 설명 주기 (Give Sub-Agents Clear Descriptions)

루트 에이전트는 description을 사용해 어떤 하위 에이전트에게 위임할지 결정해요:

agents:
  root:
    model: anthropic/claude-sonnet-4-5
    description: Technical lead
    instruction: Delegate to specialists based on the task.
    sub_agents: [frontend, backend, devops]

  frontend:
    model: openai/gpt-4o
    # Good: specific and actionable
    description: |
      Frontend specialist. Handles React, TypeScript, CSS,
      UI components, and browser-related issues.

  backend:
    model: openai/gpt-4o
    # Good: clear domain boundaries
    description: |
      Backend specialist. Handles APIs, databases,
      server logic, and Go/Python code.

  devops:
    model: openai/gpt-4o
    description: |
      DevOps specialist. Handles CI/CD, Docker, Kubernetes,
      infrastructure, and deployment pipelines.

디버깅 팁 (Debugging Tips)

디버그 로깅 활성화 (Enable Debug Logging)

--debug 플래그를 사용해 상세 실행 로그를 봐요:

# Default log location: ~/.cagent/cagent.debug.log
$ docker agent run agent.yaml --debug

# Custom log location
$ docker agent run agent.yaml --debug --log-file ./debug.log

토큰 사용량 확인 (Check Token Usage)

세션 중 /cost 명령을 사용해 토큰 소비를 봐요:

/cost

Token Usage:
Input: 12,456 tokens
Output: 3,789 tokens
Total: 16,245 tokens

긴 세션 압축 (Compact Long Sessions)

세션이 너무 길어지면 /compact 로 요약하고 컨텍스트를 줄여요:

/compact

Session compacted. Summary generated and history trimmed.

더 많은 팁 (More Tips)

사용자 정의 기본 모델 (User-Defined Default Model)

~/.config/cagent/config.yaml 에서 선호하는 기본 모델을 설정해요:

settings:
  default_model: anthropic/claude-sonnet-4-5

이 모델은 구성 인자 없이 docker agent run 을 실행하고 프로젝트 레벨 docker-agent.yaml, docker-agent.yml, docker-agent.hcl 이 존재하지 않을 때 내장 기본 에이전트가 사용해요.

Hooks로 데스크톱 알림 받기 (Get Desktop Notifications with Hooks)

오래 실행되는 에이전트가 터미널을 쳐다볼 것을 요구해선 안 돼요. 사용자 구성에 전역 훅을 추가해 모든 에이전트가 관심이 필요하거나 끝났을 때 알리게 해요:

# ~/.config/cagent/config.yaml
settings:
  hooks:
    # Agent is waiting for your input (question, approval prompt, ...)
    on_user_input:
      - type: command
        command: osascript -e 'display notification "Agent needs your input" with title "docker-agent"'

    # Agent finished responding
    stop:
      - type: command
        command: osascript -e 'display notification "Task finished" with title "docker-agent"'

Linux에서는 osascript 를 notify-send 로 바꿔요:

command: notify-send "docker-agent" "Agent needs your input"

훅은 Docker Agent의 환경을 상속하므로, 데스크톱 터미널에서는 그대로 동작해요. 분리된 컨텍스트(SSH, 데스크톱 세션 밖에서 시작된 tmux, 컨테이너)에서 notify-send 는 알림 데몬에 도달하기 위해 세션의 DISPLAY 와 DBUS_SESSION_BUS_ADDRESS 가 필요하고, 그것들 없이는 조용히 실패해요. 훅별 env 옵션으로 전달해요:

on_user_input:
  - type: command
    command: notify-send "docker-agent" "Agent needs your input"
    env:
      DISPLAY: ":0"
      DBUS_SESSION_BUS_ADDRESS: "unix:path=/run/user/1000/bus"

에러와 경고에도 알림을 받으려면 notification 이벤트를 훅하고 stdin의 JSON 페이로드에서 메시지를 읽어요:

settings:
  hooks:
    notification:
      - type: command
        timeout: 10
        command: |
          MESSAGE=$(cat | jq -r '.notification_message // "Agent error"')
          osascript -e "display notification \"$MESSAGE\" with title \"docker-agent\""

소리로 충분하면 대신 settings: { sound: true } 를 설정해요 — Docker Agent는 작업이 에러 시 실패음을, sound_threshold(기본 10)초보다 오래 실행된 작업이 완료되면 성공음을 재생해요.

이벤트, 페이로드, 훅별 옵션(env, working_dir, timeout)의 전체 목록은 Hooks 문서 참고.

GitHub PR 리뷰어 예제 (GitHub PR Reviewer Example)

Docker Agent를 GitHub Actions PR 리뷰어로 사용해요:

# .github/workflows/pr-review.yml
name: PR Review
on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Run docker-agent review
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          # Install docker-agent
          curl -fsSL https://get.docker-agent.dev | sh

          # Run the review
          docker agent run --exec reviewer.yaml --yolo \
            "Review PR #${{ github.event.pull_request.number }}"

간단한 리뷰어 에이전트와 함께:

# reviewer.yaml
agents:
  root:
    model: anthropic/claude-sonnet-4-5
    description: PR reviewer
    instruction: |
      Review pull requests for code quality, bugs, and security issues.
      Be constructive and specific in your feedback.
    toolsets:
      - type: mcp
        ref: docker:github-official
      - type: think

더 알아보기 (Learn more)