agent-toolkit

tool

https://python.langchain.com/v0.2/docs/integrations/tools/

toolkit

https://python.langchain.com/v0.2/docs/integrations/toolkits/

agent executor๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ agent๋ฅผ ๊ตฌ์ถ•ํ•˜๋Š”๋ฐ ๋‹ค์Œ ๋ฌธ์„œ๋ฅผ ๋ณด์ž.

https://python.langchain.com/v0.2/docs/how_to/agent_executor/#jupyter-notebook

์ด ์„น์…˜์—์„œ๋Š” ๋ ˆ๊ฑฐ์‹œ LangChain AgentExecutor๋ฅผ ์‚ฌ์šฉํ•œ ๊ตฌ์ถ•์„ ๋‹ค๋ฃน๋‹ˆ๋‹ค. ์‹œ์ž‘ํ•˜๋Š” ๋ฐ๋Š” ๊ดœ์ฐฎ์ง€๋งŒ ํŠน์ • ์ง€์ ์ด ์ง€๋‚˜๋ฉด ์ด ๊ธฐ๋Šฅ์ด ์ œ๊ณตํ•˜์ง€ ์•Š๋Š” ์œ ์—ฐ์„ฑ๊ณผ ์ œ์–ด ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•  ๊ฒƒ์ž…๋‹ˆ๋‹ค. ๊ณ ๊ธ‰ ์—์ด์ „ํŠธ๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด LangGraph ์—์ด์ „ํŠธ ๋˜๋Š” ๋งˆ์ด๊ทธ๋ ˆ์ด์…˜ ๊ฐ€์ด๋“œ๋ฅผ ํ™•์ธํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค.

๋ ˆ๊ฑฐ์‹œ๋กœ ์ฒ˜๋ฆฌ๋˜๊ณ  ์ž‡๋‹ค. langgraph agent๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ๋งž๋Š”๊ฑฐ๊ฐ™์€๋ฐ ๊ทธ๋ž˜์„œ ๊ทธ๋Ÿฐ์ง€ ์ด๊ฑด ๋Œ€์ถฉ ๋ด๋‘๊ณ  ๋ฐ”๋กœ langgraph๋กœ ๊ฐ€์ž.

Python REPL

%pip install langchain_experimental
from langchain_core.tools import Tool
from langchain_experimental.utilities import PythonREPL
python_repl = PythonREPL()
python_repl.run("print(1+1)")
# You can create the tool to pass to an agent
repl_tool = Tool(
    name="python_repl",
    description="ํŒŒ์ด์ฌ ์…ธ์ž…๋‹ˆ๋‹ค. ํŒŒ์ด์ฌ ๋ช…๋ น์„ ์‹คํ–‰ํ•  ๋•Œ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ž…๋ ฅ์€ ์œ ํšจํ•œ ํŒŒ์ด์ฌ ๋ช…๋ น์ด์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๊ฐ’์˜ ์ถœ๋ ฅ์„ ํ™•์ธํ•˜๋ ค๋ฉด `print(...)`๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ถœ๋ ฅํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.",
    func=python_repl.run,
)

์ฃผ์‹ ํ‹ฐ์ปค ์ฐพ๊ธฐ agent

sql agent

https://github.com/lerocha/chinook-database/blob/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite

chinook_sqlite๋ฅผ ์‚ฌ์šฉํ•จ

!wget 'https://github.com/lerocha/chinook-database/releases/download/v1.4.2/Chinook_Sqlite.sql'

langgraph

์š”์ฆ˜์€ langchain agent๋ณด๋‹ค langgraph๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด ์ข‹์€๊ฑฐ๊ฐ™์€ ๊ฐœ์ธ์  ๋А๋‚Œ์ด๋ผ. agent์ชฝ์€ ๋งŽ์ด ๋ณด์ง€๋Š” ์•Š๊ณ  langgraph๋กœ ๋ฐ”๋กœ ๋„˜์–ด๊ฐ€๋ฒ„๋ฆด๊นŒ ํ•ฉ๋‹ˆ๋‹ค.

Agent

์ธ๊ณต์ง€๋Šฅ Agent๋Š” ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ๋ฐ›์€ ํ›„ ์–ด๋–ค ๊ธฐ๋Šฅ์„ ์–ด๋–ค ์ˆœ์„œ๋กœ ์‹คํ–‰ํ• ์ง€ ๊ฒฐ์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค. Agent์˜ ์ฃผ์š” ํŠน์ง•๋“ค์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • ๋ชฉํ‘œ(์ •์ฑ…) ๊ธฐ๋ฐ˜ ํ–‰๋™: ์ฃผ์–ด์ง„ ๋ชฉํ‘œ๋ฅผ ๋‹ฌ์„ฑํ•˜๊ธฐ ์œ„ํ•ด ํ–‰๋™ํ•ฉ๋‹ˆ๋‹ค.

  • ์ž์œจ์„ฑ: ๋ชฉํ‘œ๊ฐ€ ์ฃผ์–ด์ง€๋ฉด ์ž๋™์œผ๋กœ ์ž‘๋™ํ•ฉ๋‹ˆ๋‹ค.

  • ๊ฐ์ง€: ์ฃผ๋ณ€ ํ™˜๊ฒฝ์—์„œ ์ •๋ณด๋ฅผ ์ˆ˜์ง‘ํ•ฉ๋‹ˆ๋‹ค.

Tools๋Š” Agent๊ฐ€ ํ•  ์ˆ˜ ์žˆ๋Š” ์ผ

alt text
  1. Input: ์‚ฌ์šฉ์ž๊ฐ€ Agent์—๊ฒŒ ์ž‘์—…์„ ํ• ๋‹นํ•ฉ๋‹ˆ๋‹ค.

  2. Thought: Agent๊ฐ€ ์ž‘์—…์„ ์™„์ˆ˜ํ•˜๊ธฐ ์œ„ํ•ด ๋ฌด์—‡์„ ํ• ์ง€ ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค.

  3. Action/Action Input: ์‚ฌ์šฉํ•  ๋„๊ตฌ๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ , ๋„๊ตฌ์˜ ์ž…๋ ฅ(ํ•จ์ˆ˜์˜ ์ž…๋ ฅ๊ฐ’)์„ ๊ฒฐ์ •ํ•ฉ๋‹ˆ๋‹ค.

  4. Observation: ๋„๊ตฌ์˜ ์ถœ๋ ฅ ๊ฒฐ๊ณผ๋ฅผ ๊ด€์ฐฐํ•ฉ๋‹ˆ๋‹ค.

  5. ๊ด€์ฐฐ ๊ฒฐ๊ณผ ์ž‘์—…์„ ์™„๋ฃŒ(Finish)ํ–ˆ๋‹ค๋Š” ํŒ๋‹จ์— ๋„๋‹ฌํ•  ๋•Œ๊นŒ์ง€ 2~4๋ฒˆ ๊ณผ์ •์„ ๋ฐ˜๋ณตํ•ฉ๋‹ˆ๋‹ค.

Last updated

Was this helpful?