LLM AI Agent
LLM AI Agent toy project - #2 Tool call
ybjeon.today
2026. 5. 29. 23:51
목표
LLM이 필요한 도구를 직접 골라 실행할 수 있게끔 Agent 설계
코드
코드 링크: https://github.com/ybjeon/ai-agent-toyproject/blob/main/test_toolcall.py
1) test_toolcall.py - get_today_schedule() Tool call 정의
from langchain_core.tools import tool
@tool
def get_today_schedule() -> dict:
"""Retrieve today's calendar schedule."""
today = TODAY # str(date.today())
events = FAKE_CALENDAR.get(today, [])
return {
"date": today,
"events": events if events else [],
"message": f"You have {len(events)} event(s) today." if events else "No events scheduled for today.",
}
2) test_toolcall.py - tool call을 포함한 agent 생성
from langchain.agents import create_agent
tools = [get_today_schedule, save_schedule, send_email, read_sms]
agent = create_agent(llm, tools, system_prompt="You are a helpful personal assistant.")
tool들을 포함한 create_agent 함수
결과
>>>>>>> User: What's on my schedule today?
2026-05-29 23:42:10 [INFO] HTTP Request: POST http://localhost:11434/api/chat "HTTP/1.1 200 OK"
2026-05-29 23:42:10 [INFO] [TOOL START] get_today_schedule | input: {}
2026-05-29 23:42:10 [INFO] [TOOL END] output: content='{"date": "2026-05-05", "events": [{"time": "09:00", "title": "Team Standup Meeting"}, {"time": "14:00", "title": "Project Review"}, {"time": "18:00", "title": "Dinner Appointment"}], "message": "You have 3 event(s) today."}' name='get_today_schedule' tool_call_id='045c3771-c1c7-4ae2-b72a-47b62c24c8fc'
2026-05-29 23:42:10 [INFO] HTTP Request: POST http://localhost:11434/api/chat "HTTP/1.1 200 OK"
<<<<<<< Assistant: Today, May 5th, 2026, you have the following events scheduled:
- Team Standup Meeting at 09:00
- Project Review at 14:00
- Dinner Appointment at 18:00
You have a total of 3 events today.