AG2 ์—์ด์ „ํŠธ ์‚ฌ์šฉ

์ด ํŽ˜์ด์ง€์—์„œ๋Š” ์—์ด์ „ํŠธ ์‚ฌ์šฉ์„ ์œ„ํ•œ ์ผ๋ฐ˜ ์•ˆ๋‚ด ์™ธ์—๋„ AG2Agent์™€ ๊ด€๋ จ๋œ ๊ธฐ๋Šฅ์„ ์„ค๋ช…ํ•ฉ๋‹ˆ๋‹ค.

์‹œ์ž‘ํ•˜๊ธฐ ์ „์—

์ด ํŠœํ† ๋ฆฌ์–ผ์—์„œ๋Š” ์‚ฌ์šฉ์ž๊ฐ€ ๋‹ค์Œ ์•ˆ๋‚ด๋ฅผ ์ฝ๊ณ  ๋”ฐ๋ž๋‹ค๊ณ  ๊ฐ€์ •ํ•ฉ๋‹ˆ๋‹ค.

์ง€์›๋˜๋Š” ์ž‘์—…

AG2Agent์— ์ง€์›๋˜๋Š” ์ž‘์—…์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • query: ์ฟผ๋ฆฌ์— ๋Œ€ํ•œ ์‘๋‹ต์„ ๋™๊ธฐ์‹์œผ๋กœ ๊ฐ€์ ธ์˜ต๋‹ˆ๋‹ค.

query ๋ฉ”์„œ๋“œ๋Š” ๋‹ค์Œ ์ธ์ˆ˜๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.

  • input: ์—์ด์ „ํŠธ์—๊ฒŒ ์ „์†กํ•  ๋ฉ”์‹œ์ง€์ž…๋‹ˆ๋‹ค.
  • max_turns: ํ—ˆ์šฉ๋˜๋Š” ์ตœ๋Œ€ ๋Œ€ํ™” ํ„ด ์ˆ˜์ž…๋‹ˆ๋‹ค. ๋„๊ตฌ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ๋Š” ์ตœ์†Œ max_turns=2์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋„๊ตฌ ์ธ์ˆ˜๋ฅผ ์ƒ์„ฑํ•˜๋Š” ๋ฐ ํ•œ ๋ฒˆ, ๋„๊ตฌ๋ฅผ ์‹คํ–‰ํ•˜๋Š” ๋ฐ ํ•œ ๋ฒˆ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

์—์ด์ „ํŠธ ์ฟผ๋ฆฌ

query() ๋ฉ”์„œ๋“œ๋Š” ์ƒ๋‹ด์‚ฌ์™€ ์ƒํ˜ธ์ž‘์šฉํ•˜๋Š” ๊ฐ„์†Œํ™”๋œ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค. ์ผ๋ฐ˜์ ์ธ ํ˜ธ์ถœ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

response = agent.query(input="What is the exchange rate from US dollars to Swedish currency?", max_turns=2)

์ด ๋ฉ”์„œ๋“œ๋Š” ์—์ด์ „ํŠธ์™€์˜ ๊ธฐ๋ณธ ํ†ต์‹ ์„ ์ฒ˜๋ฆฌํ•˜๊ณ  ์—์ด์ „ํŠธ์˜ ์ตœ์ข… ์‘๋‹ต์„ ์‚ฌ์ „์œผ๋กœ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ๋‹ค์Œ๊ณผ ๋™์ผํ•ฉ๋‹ˆ๋‹ค (์ „์ฒด ํ˜•์‹).

from autogen import ConversableAgent
import dataclasses
import json

input_message: str = "What is the exchange rate from US dollars to Swedish currency?"
max_turns: int = 2

with agent._runnable._create_or_get_executor(
    tools=agent._ag2_tool_objects,            # Use the agent's existing tools
    agent_name="user",                        # Default
    agent_human_input_mode="NEVER",           # query() enforces this
) as executor:
    chat_result = executor.initiate_chat(
        agent._runnable,
        message=input_message,
        max_turns=max_turns,
        clear_history=False,                  # Default
        summary_method="last_msg"             # Default
    )

response = json.loads(
  json.dumps(dataclasses.asdict(chat_result)) # query() does this conversion
)

query()์— ํ‚ค์›Œ๋“œ ์ธ์ˆ˜๋ฅผ ์ถ”๊ฐ€๋กœ ์ „๋‹ฌํ•˜์—ฌ input ๋ฐ max_turns ์™ธ์—๋„ ์—์ด์ „ํŠธ์˜ ๋™์ž‘์„ ๋งž์ถค์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

response = agent.query(
    input="What is the exchange rate from US dollars to Swedish currency?",
    max_turns=2,
    msg_to="user"  # Start the conversation with the "user" agent
)
print(response)

์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ๋งค๊ฐœ๋ณ€์ˆ˜์˜ ์ „์ฒด ๋ชฉ๋ก์€ ConversableAgent.run ๋ฌธ์„œ๋ฅผ ์ฐธ๊ณ ํ•˜์„ธ์š”. ํ•˜์ง€๋งŒ user_input๋Š” ํ•ญ์ƒ AG2Agent ํ…œํ”Œ๋ฆฟ์— ์˜ํ•ด False๋กœ ์žฌ์ •์˜๋ฉ๋‹ˆ๋‹ค.

๋‹ค์Œ ๋‹จ๊ณ„