JSON2 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.. 2026. 8. 23. IV. AI Agent가 LLM의 응답을 JSON으로 받고, 그 안에서 Tool 이름과 인자(arguments)를 꺼내서 실제 Tool 실행으로 연결하기 위한 기초 # 1. JSON 문자열을 Python 객체로. import json raw = '{"tool":"search", "args":{"query":"refund policy"}, "done":false}' data = json.loads(raw) print(type(data)) print(data["tool"]) print(data["args"]["query"]) print(data["done"], type(data["done"])) #-------- 2. Python 객체를 JSON 문자열로 import json payload = { "model":"some-model", "max_tokens": 2048, .. 2026. 8. 22. 이전 1 다음 반응형