전체 글 212

XIV. 작은 AI Agent 프로그램(가짜 LLM Model-script 사용)

# 1. 설계 주석 # 설계 # 목표: 사용자로부터 입력받은 문장 # 도구: 계산기, 파일 읽기, 조회 # 반복: 최대 6단계 # 메모리: 메시지 목록 (완료 시 디스크에 저장) # 종료: 모델이 '완료' 도구를 반환하거나 단계 제한에 도달함 # (아래는 영문으로 위와 동일한 내용) # The design # goal a sentence from the user # tools calculator, read_file, lookup # loop at most 6 steps # memory a list of messages, saved to dis..

Agentic AI/AI_AGENT 2026.08.26

XIII. Python 함수 자체를 분석하여, AI가 사용할 수 있는 Tool 설명서(schema)를 자동으로 만드는 방법

# 1. Type Hint 그리고 __annotations__ def search(query:str, limit:int=3, safe:bool=True)->str: mode = "safe" if safe else "open" return f"'{query}'에 대해 {limit}개의 결과물({mode})" print(search("환불 정책")) print(search("개점 시간", limit=1, safe=False)) print(search.__annotations__) #-------- 2. History 분석 def summarise(messages:list[dict], limit:int|None=None)->dict[str,i..

Agentic AI/AI_AGENT 2026.08.25

XII. Python 프로그램이 인터넷 너머의 API 서버와 대화하는 방법 → 오류, 재시도 ...→ 결국 실제 LLM 호출 함수 call_model()로 발전시키는 과정

# 1. HTTP 상태 코드 # 200 OK, it worked # 400 bad request, your JSON or parameters are wrong # 401 unauthorised, the API key is missing or invalid # 403 forbidden, the key is valid but not allowed to do this # 404 not found, check the URL # 429 too many requests, slow down and retry later # 500 server error on their side # 503 service unavailable, retry later #-------- ..

Agentic AI/AI_AGENT 2026.08.25

XI. Agent의 핵심 부품을 여러 파일로 나누어 실제 프로젝트 구조 만들기

# 1. tools.py 파일와 main.py 파일: main.py에서 tools 사용하기 # 파일1: tools.py def calculator(expr): return eval(expr) def word_count(text): return len(text.split()) REGISTRY = {"calculator":calculator, "word_count":word_count} # 파일2: main.py import tools from tools import REGISTRY, word_count print(tools.calculator("8*5")) print(word_count("에이전트는 루프입니다")) p..

Agentic AI/AI_AGENT 2026.08.24

X. Agent의 여러 요소를 하나의 class Agent로 묶어가는 과정.

# 1. Dictionary와 Class의 차이 # 다음과 같은 경우 딕셔너리를 사용하세요: # 단순히 데이터일 때 # JSON에 바로 전달할 때 # 별도의 규칙을 적용할 필요가 없을 때 # 다음과 같은 경우 클래스를 사용하세요: # 데이터와 동작이 함께 있어야 할 때 # 여러 개의 독립적인 복사본이 필요할 때 # 유효하지 않은 상태를 방지해야 할 때 #-------- 2. 첫 번째 Agent 클래스(Agent라는 새로운 자료형 만들기): __init__()와 self class Agent: def __init__(self, name, max_steps=5): self.na..

Agentic AI/AI_AGENT 2026.08.24

IX. AI Agent에 “기억과 기록” 기능을 붙이는 단계

# 1. 파일에 쓰고 읽기 with open("notes.txt", "w", encoding="utf-8") as f: f.write("에이전트 작동이 시작되었습니다. \n") f.write("tool: search \n") with open("notes.txt", "r", encoding="utf-8") as f: contents = f.read() print(contents) print("characters: ", len(contents)) #-------- 2. 로그 파일에 추가하기 with open("runlog.txt", "a", encoding="utf-8") as f: f.write("1단계 | searc..

Agentic AI/AI_AGENT 2026.08.23

VIII. Agent Loop + Tool Dispatcher 다음 단계인 예외 처리(Exception), 재시도(Retry), Logging 스터디

# 1. KeyError — 딕셔너리에 없는 키를 찾았을 때 # def get_units(record): # return record["units"] # get_units({"sku":"51001"}) # 결과: Exception has occurred: KeyError 'units' #-------- 2. try / except / else / finally def to_int(value): try: number = int(value) except ValueError: print(f" {value!r}을 숫자로 변환할 수 없습니다.") return None exce..

Agentic AI/AI_AGENT 2026.08.23

VII. Python 함수 → Tool 함수 → Agent의 Tool Dispatcher 구조

# 1. 함수의 기본값과 키워드 인수 def search(query, limit=3, safe=True): mode = "safe" if safe else "unfiltered" return f"searching '{query}' | limit={limit} | {mode}" print(search("환불정책")) print(search("환불정책", 10)) print(search("환불정책", limit=5, safe=False)) print(search(limit=1, query="환불정책")) #-------- 2. 함수 기본값의 함정 (mutable default) def add_bad(item, bucket=[]): ..

Agentic AI/AI_AGENT 2026.08.23

VI. Python의 반복문과 자료구조를 이용해 AI Agent의 실제 실행 흐름을 만드는 과정

# 1. history 순회 + range() history = [ {"role":"user","content":"제품번호 5001의 재고를 확인해라."}, {"role":"assistant", "content":"지금 찾아보고 있어요."}, {"role":"user", "content":"그 제품이 어느 창고로부터 배송되는지 확인해라."}, ] for message in history: print(f"{message['role']}: {message['content']}") print() for i in range(3): print(f"step {i}") #-------- 2. enumerate() + ..

Agentic AI/AI_AGENT 2026.08.23