DEV Community

matias yoon
matias yoon

Posted on

터미널 AI 에이전트 구축 (v44)

터미널 AI 에이전트 구축 (v44)

터미널에서 실행되는 AI 에이전트를 구축하는 것은 현대 개발자에게 매우 실용적인 기술입니다. 이 가이드에서는 로컬 LLM을 기반으로 하는 터미널 AI 에이전트를 구축하고 운영하는 방법을 단계별로 설명합니다.

1. CLI AI 에이전트 생태계

현재 CLI AI 에이전트 시장은 다음과 같은 주요 플랫폼들로 구성되어 있습니다:

Aider

가장 인기 있는 오픈소스 터미널 AI 에이전트입니다. Python 기반으로 개발되어 있으며, Git 연동과 코드 생성 기능을 제공합니다.

pip install aider
aider --help
Enter fullscreen mode Exit fullscreen mode

Continue.dev

VS Code와 함께 사용하는 AI 코딩 도우미이지만, CLI 버전도 존재합니다. Git 기반의 코드 리뷰와 자동완성 기능을 제공합니다.

OpenCode

가볍고 빠른 CLI 기반 에이전트로, 터미널 내에서 직접 코드를 생성하고 수정할 수 있습니다.

커스텀 스크립트

이 가이드에서는 직접 개발한 Python 기반 CLI 에이전트를 만들어보겠습니다.

2. 로컬 LLM API 엔드포인트 설정

로컬 LLM을 사용하기 위해서는 API 서버를 실행해야 합니다. 이 예제에서는 LLaMA.cpp를 사용하겠습니다:

# LLaMA.cpp 설치
git clone https://github.com/ggerganov/llama.cpp
cd llama.cpp
make

# 모델 다운로드 및 변환
wget https://huggingface.co/TheBloke/Llama-3.2-1B-Instruct-GGUF/resolve/main/llama-3.2-1b-instruct-q4_K_M.gguf
python convert.py llama-3.2-1b-instruct-q4_K_M.gguf

# API 서버 실행
./server -m llama-3.2-1b-instruct-q4_K_M.gguf -c 2048 --host 127.0.0.1 --port 1234
Enter fullscreen mode Exit fullscreen mode

API 엔드포인트 테스트:

curl -X POST http://localhost:1234/v1/completions \
  -H "Content-Type: application/json" \
  -d '{
    "prompt": "Write a Python function to calculate Fibonacci numbers",
    "max_tokens": 200,
    "temperature": 0.7
  }'
Enter fullscreen mode Exit fullscreen mode

3. 간단한 Python CLI 에이전트 구축

다음은 기본적인 Python CLI 에이전트입니다:


python
#!/usr/bin/env python3
# ai_agent.py

import requests
import json
import os
import sys
from typing import Dict, List, Any

class TerminalAgent:
    def __init__(self, api_url: str = "http://localhost:1234"):
        self.api_url = api_url
        self.session = requests.Session()
        self.context = []

    def call_model(self, prompt: str, max_tokens: int = 500) -> str:
        """로컬 LLM API 호출"""
        try:
            response = self.session.post(
                f"{self.api_url}/v1/completions",
                json={
                    "prompt": prompt,
                    "max_tokens": max_tokens,
                    "temperature": 0.7,
                    "stop": ["

---

📥 **Get the full guide on Gumroad**: https://gumroad.com/l/auto ($5)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)