惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园_首页
量子位
V
Visual Studio Blog
博客园 - Franky
宝玉的分享
宝玉的分享
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 【当耐特】
罗磊的独立博客
小众软件
小众软件
V
V2EX
GbyAI
GbyAI
B
Blog RSS Feed
博客园 - 三生石上(FineUI控件)
大猫的无限游戏
大猫的无限游戏
有赞技术团队
有赞技术团队
月光博客
月光博客
Recent Announcements
Recent Announcements
雷峰网
雷峰网
F
Fortinet All Blogs
M
MIT News - Artificial intelligence

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
터미널 AI 에이전트 구축 (v21)
matias yoon · 2026-05-25 · via DEV Community

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

터미널에서 작동하는 AI 에이전트를 구축하여 코드 작성과 리팩토링을 자동화하는 것은 현대 개발 워크플로우의 핵심입니다. 이 가이드는 실제 개발자가 사용할 수 있는, 저렴하고 효율적인 터미널 AI 에이전트 구축 방법을 다룹니다.

1. CLI AI 에이전트 생태계

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

Aider: GitHub Copilot과 유사한 기능으로, 코드 생성과 수정을 지원합니다.

pip install aider
aider --help

Enter fullscreen mode Exit fullscreen mode

Continue.dev: VSCode 확장 프로그램이지만 터미널에서도 사용 가능합니다.

npm install -g continue
continue --help

Enter fullscreen mode Exit fullscreen mode

OpenCode: OpenAI API 기반의 커스텀 에이전트입니다.

pip install openai

Enter fullscreen mode Exit fullscreen mode

커스텀 스크립트: 직접 구축한 에이전트는 높은 유연성을 제공합니다.

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

로컬 LLM을 사용하여 API 엔드포인트를 설정하는 방법입니다:

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

# 2. 모델 다운로드 및 변환
wget https://huggingface.co/TheBloke/Qwen-7B-Chat-GGUF/resolve/main/qwen-7b-chat.Q4_K_M.gguf
./convert-hf-to-ggml.py models/Qwen-7B-Chat/ 1
./quantize models/Qwen-7B-Chat/ggml-model-f16.bin qwen-7b-chat.Q4_K_M.gguf 4

# 3. 로컬 서버 실행
./server -m qwen-7b-chat.Q4_K_M.gguf -c 2048 --host 0.0.0.0 --port 8080

Enter fullscreen mode Exit fullscreen mode

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

다음은 기능 호출을 지원하는 간단한 Python 에이전트입니다:

# aider_agent.py
import subprocess
import json
import requests
import sys

class TerminalAgent:
    def __init__(self, api_url="http://localhost:8080"):
        self.api_url = api_url

    def execute_command(self, command):
        """명령어 실행"""
        try:
            result = subprocess.run(
                command, 
                shell=True, 
                capture_output=True, 
                text=True,
                timeout=30
            )
            return {
                "success": result.returncode == 0,
                "output": result.stdout,
                "error": result.stderr
            }
        except subprocess.TimeoutExpired:
            return {"success": False, "error": "Command timed out"}

    def chat_with_ai(self, prompt):
        """AI와 대화"""
        payload = {
            "prompt": prompt,
            "temperature": 0.7,
            "max_tokens": 512
        }
        try:
            response = requests.post(
                f"{self.api_url}/completion",
                json=payload,
                timeout=30
            )
            return response.json()
        except requests.exceptions.RequestException as e:
            return {"error": str(e)}

# 사용 예시
if __name__ == "__main__":
    agent = TerminalAgent()

    if len(sys.argv) > 1:
        command = " ".join(sys.argv[1:])
        if command.startswith("run:"):
            result = agent.execute_command(command[4:])
            print(json.dumps(result, indent=2))
        else:
            response = agent.chat_with_ai(command)
            print(json.dumps(response, indent=2))

Enter fullscreen mode Exit fullscreen mode

4. tmux와 통합

터미널 분할 환경에서 에이전트를 활용하려면 tmux와 통합해야 합니다:

# tmux 세션 생성
tmux new-session -d -s ai_agent

# 에이전트 실행 (백그라운드)
tmux send-keys -t ai_agent "python3 aider_agent.py" Enter

# 세션 정보 확인
tmux ls

Enter fullscreen mode Exit fullscreen mode

사용자 정의 스크립트로 tmux 컨트롤:

# tmux_helper.py
import subprocess
import json

def create_ai_session():
    """AI 세션 생성"""
    subprocess.run(["tmux", "new-session", "-d", "-s", "ai_agent"])

def send_to_session(session, command):
    """세션에 명령어 전송"""
    subprocess.run(["tmux", "send-keys", "-t", session, command, "Enter"])

def get_session_output(session):
    """세션 출력 가져오기"""
    result = subprocess.run(
        ["tmux", "capture-pane", "-p", "-t", session],
        capture_output=True,
        text=True
    )
    return result.stdout

# 사용 예시
create_ai_session()
send_to_session("ai_agent", "python3 aider_agent.py '리팩토링해줘'")

Enter fullscreen mode Exit fullscreen mode

5. 사용자 정의 도구 개발

코드 검색 도구

# code_search.py
import os
import subprocess
import re

class CodeSearcher:
    def __init__(self, project_root="."):
        self.project_root = project_root

    def search_function(self, function_name):
        """함수 검색"""
        cmd = f"grep -r '{function_name}' --include='*.py' {self.project_root}"
        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
        return result.stdout

    def search_pattern(self, pattern):
        """정규 표현식으로 검색"""
        cmd = f"grep -r '{pattern}' --include='*.py' {self.project_root}"
        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
        return result.stdout

# 사용 예시
searcher = CodeSearcher("/path/to/project")
functions = searcher.search_function("calculate_total")

Enter fullscreen mode Exit fullscreen mode

Git 도구

# git_tools.py
import subprocess
import json

class GitTools:
    def __init__(self, repo_path="."):
        self.repo_path = repo_path

    def get_changes(self):
        """변경사항 가져오기"""
        cmd = "git diff --name-only"
        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
        return result.stdout.splitlines()

    def get_status(self):
        """상태 정보"""
        cmd = "git status --porcelain"
        result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
        return result.stdout

# 사용 예시
git_tools = GitTools("/path/to/repo")
changes = git_tools.get_changes()

Enter fullscreen mode Exit fullscreen mode

6. 컨텍스트 윈도우 관리

대규모 코드베이스의 컨텍스트 윈도우를 관리하기 위한 전략:

# context_manager.py
import os
import hashlib
from typing import List, Dict

class ContextManager:
    def __init__(self, max_context_size=4096):
        self.max_context_size = max_context_size
        self.context_cache = {}

    def add_file_context(self, file_path: str, content: str):
        """파일 컨텍스트 추가"""
        file_hash = hashlib.md5(file_path.encode()).hexdigest()
        self.context_cache[file_hash] = {
            "path": file_path,
            "content": content,
            "size": len(content)
        }

    def get_context_summary(self, file_paths: List[str]) -> Dict:
        """컨텍스트 요약"""
        summary = {}
        total_size = 0

        for path in file_paths:
            if path in self.context_cache:
                file_info = self.context_cache[path]
                summary[path] = {
                    "size": file_info["size"],
                    "content_preview": file_info["content"][:100] + "..."
                }
                total_size += file_info["size"]

        return {
            "files": summary,
            "total_size": total_size,
            "over_limit": total_size > self.max_context_size
        }

# 사용 예시
context = ContextManager(2048)
context.add_file_context("main.py", "def hello():\n    print('Hello')")
summary = context.get_context_summary(["main.py"])

Enter fullscreen mode Exit fullscreen mode

7. 비용/속도 최적화

로컬 vs API 모델의 성능 비교:


python
# performance_optimizer.py
import time
import subprocess
import json

class ModelOptimizer:
    def __init__(self):
        self.local_models = {
            "qwen7b": "qwen-7b-chat.Q4_K_M.gguf",
            "gemma7b": "gemma-7b-it.Q4_K_M.gguf"
        }

    def benchmark_model(self, model_name, prompt):
        """모델 성능 벤치마크"""
        # 로컬 모델 테스트
        start_time = time.time()


---

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

Enter fullscreen mode Exit fullscreen mode