본문 바로가기

명사 美 비격식 (무리 중에서) 아주 뛰어난[눈에 띄는] 사람[것]

이론

Agents Agentic AI의 4요소 LLM, 도구, 기억, 루프 : 프롬프트, API 호출, Agent Loop, RAG, 장기기억, 팀협업(feat.에이전트 아키텍처 그리기)


Agentic AI 

에이전트형 AI 두뇌 LLM에 세가지를 붙인 시스템 도구, 기억, 루프.

말은 잘하지만 스스로 행동은 못하는 도구. 여기에 도구.기억.반복 루프를 붙여 실제로 일을 끝내게 만든것이 에이전트. 

https://standout.tistory.com/1879

 

LLM의 정의와 LLM 종류

LLMLarge Language Model, 대규모 언어모델GPT-3 는 2020 년에 공개된 대표적인 초거대언어모델이며, 1,750 억 개 파라미터를 가진 자기회귀 언어 모델기존 NLP모델은 감성분석, 번역모델, 요약모델, 질문답

standout.tistory.com

https://standout.tistory.com/1876

 

RAG(Retrieval-Augmented Generation)와 LLM의 Hallucination(환각): 외부 문서를 검색한 후 검색 결과를 바탕으

RAG(Retrieval-Augmented Generation)기업은 범용 언어모델을 그대로 사용하는 것이 아니라 사내 문서, 정보, 고객데이터 등을 추가해 기업전용 AI시스템을 구축하며 LLM은 이때 존재하지않는 정보를 생성

standout.tistory.com

 

 

에이전트 작업

1. 프롬프트 설계, 복잡한 문제는 단계적으로 추론하게 만든다. 

2. LLM이 스스로 외부 함수를 호출하게 만드는 에이전트 루프를 구현한다. 

3. RAG 문서를 근거로 답하게한다. 

4. LLM은 stateless 존재이니 장기기억이 가능하게한다. 

5. 워크플로우를 선언하고 전문 에니전트를 만들어 팀으로 협업하게한다. 

 

 

 

 

1. 프롬프트 설계, 복잡한 문제는 단계적으로 추론하게 만든다.

from openai import OpenAI

client = OpenAI()

response = client.responses.create(
    model="gpt-5",
    input="""
당신은 네트워크 전문가입니다.

다음 순서대로 답변하세요.

1. 문제 분석
2. 원인 후보
3. 해결 방법
4. 최종 결론

질문:
Meraki AP가 인터넷은 되지만 Dashboard에 Offline으로 표시됩니다.
"""
)

print(response.output_text)

 

 

2. LLM이 스스로 외부 함수를 호출하게 만드는 에이전트 루프를 구현한다.

질문 - LLM - 함수 호출 여부 판단 - API호출 - 결과전달 - LLM - 최종답변 

from openai import OpenAI

client = OpenAI()

tools = [
    {
        "type": "function",
        "name": "get_weather",
        "description": "현재 날씨 조회",
        "parameters": {
            "type": "object",
            "properties": {
                "city": {
                    "type": "string"
                }
            }
        }
    }
]

response = client.responses.create(
    model="gpt-5",
    input="서울 날씨 알려줘",
    tools=tools
)

print(response.output)
def get_weather(city):
    return {
        "city": city,
        "weather": "맑음",
        "temperature": 29
    }
while True:

    response = llm()

    if response.tool_call:

        result = get_weather(response.city)

        send_to_llm(result)

    else:
        break

 

 

3. RAG  문서를 근거로 답하게한다. 

질문 - embedding - Vector DB 검색 - 관련문서 - LLM - 답변

from langchain.vectorstores import FAISS
from langchain.embeddings import OpenAIEmbeddings

vector_db = FAISS.load_local(
    "meraki_docs",
    OpenAIEmbeddings()
)

docs = vector_db.similarity_search(
    "MX VPN 설정",
    k=3
)

context = "\n".join(doc.page_content for doc in docs)

prompt = f"""
다음 문서를 참고해서 답하세요.

{context}

질문:
MX VPN 설정 방법은?
"""

response = client.responses.create(
    model="gpt-5",
    input=prompt
)

print(response.output_text)

 

 

4. LLM은 stateless 존재이니 장기기억이 가능하게한다. 

사용자 - LLM - 대화저장(DB) - 다음질문 - DB검색 - LLM

memory = []

def save_memory(user, assistant):
    memory.append({
        "user": user,
        "assistant": assistant
    })
history = ""

for m in memory:
    history += f"""
User:
{m['user']}

Assistant:
{m['assistant']}
"""

prompt = history + """

User:
계속 설명해줘
"""
CREATE TABLE memory(
    id INTEGER PRIMARY KEY,
    user TEXT,
    assistant TEXT,
    created_at DATETIME
);

 

 

5. 워크플로우를 선언하고 전문 에니전트를 만들어 팀으로 협업하게한다.

Planner Agent 문제를 분석, NetworkAgent VPN, Switch, Wireless, Routing 분석, Security Agent Firewall, ACL, VPN, IDS 분석.. Writer Agent 최종보고서 작성

                사용자 질문
                      │
                      ▼
              Planner Agent
                      │
          ┌───────────┴───────────┐
          ▼                       ▼
   Network Agent          Security Agent
          │                       │
          └───────────┬───────────┘
                      ▼
               Writer Agent
                      │
                      ▼
                 최종 답변
planner = PlannerAgent()

network = NetworkAgent()

security = SecurityAgent()

writer = ReportAgent()
question = "VPN이 연결되지 않습니다."

plan = planner.run(question)

network_result = network.run(plan)

security_result = security.run(plan)

answer = writer.run(
    network_result,
    security_result
)

print(answer)

 

 

 

전체 에이전트 아키텍처

                    사용자 질문
                          │
                          ▼
                 Prompt Engineering
                          │
                          ▼
                    Planner Agent
                          │
        ┌─────────────────┼─────────────────┐
        ▼                 ▼                 ▼
     Tool Call          RAG 검색        Memory 조회
   (API/함수 호출)    (Vector DB)      (DB/Redis)
        │                 │                 │
        └─────────────────┼─────────────────┘
                          ▼
                      LLM 추론
                          │
                          ▼
               전문 Agent 협업
     (Network / Security / Report)
                          │
                          ▼
                     최종 답변