AutoGen 공식 문서
https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/index.html
AgentChat — AutoGen
Tutorial Step-by-step guide to using AgentChat, learn about agents, teams, and more
microsoft.github.io
🎠 Human-in-the-Loop
팀과 상호작용하고 팀에 피드백을 제공하는 방법
- During a team’s run – execution of run() or run_stream(), provide feedback through a UserProxyAgent.
- Once the run terminates, provide feedback through input to the next call to run() or run_stream().
Providing Feedback During a Run
UserProxyAgent는 사용자가 팀에 피드백을 제공하기 위해 프록시 역할을 하는 특별한 기본 제공 에이전트
UserProxyAgent 인스턴스를 만들어 팀에 포함
팀은 사용자로부터 피드백을 요청하기 위해 UserProxyAgent를 호출할 시기를 결정
팀이 UserProxyAgent를 호출하면 애플리케이션/사용자에게 제어를 전송하고 피드백을 기다리며,
피드백이 제공되면 제어가 다시 팀으로 전송되고 팀은 실행을 계속
이 접근방식의 차단 특성으로 인해 버튼 클릭으로 승인 또는 비승인을 요청하거나
작업 실패 시 즉각적인 주의가 필요한 알림과 같이
사용자의 즉각적인 피드백이 필요한 짧은 상호작용에만 사용하는 것이 좋음.
user_proxy = UserProxyAgent("user_proxy", input_func=input) # Use input() to get user input from console.
# Create the termination condition which will end the conversation when the user says "APPROVE".
termination = TextMentionTermination("APPROVE")
# Create the team.
team = RoundRobinGroupChat([assistant, user_proxy], termination_condition=termination)
APPROVE 들어오면 멈추게
Providing Feedback to the Next Run
팀이 종료될 때까지 실행되고, 애플리케이션이나 사용자가 피드백을 제공하며, 팀이 피드백을 받아 다시 실행
이 방식은 팀과 애플리케이션/사용자 간의 비동기 통신이 있는 지속 세션에서 유용
팀이 실행을 완료하면 애플리케이션은 팀의 상태를 저장하고 영구 저장소에 저장한 다음 피드백이 도착하면 팀을 다시 시작
이 접근 방식을 구현하는 두 가지 방법
- 팀이 지정된 턴 수 후에 항상 멈추도록 최대 턴 수를 설정
- 팀의 내부 상태를 고려하여 팀이 언제 멈추고 제어권을 넘길지 결정할 수 있도록 TextMentionTermination 및 HandoffTermination 등의 종료 조건을 사용
Using Max Turns
최대 턴 수를 설정하여 사용자 입력을 위해 팀을 일시 중지할 수 있음
team = RoundRobinGroupChat([...], max_turns=1)
(max_turns를 1로 설정하여 첫 번째 에이전트가 응답한 후에 팀이 중지되도록 구성할 수 있음)
Using Termination Conditions
종료 조건 설정하기
🎠 Termination
마지막으로 조건이 호출된 이후 일련의 AgentEvent 또는 ChatMessage 개체를 받아 대화를 종료해야 할 경우 StopMessage를 반환하고 그렇지 않은 경우 None을 반환하는 호출 가능 항목입
+
종료 조건에 도달한 후에는 다시 사용하기 전에 reset()을 호출하여 재설정
- MaxMessageTermination: 상담원 및 작업 메시지를 모두 포함하여 지정된 수의 메시지가 생성된 후 중지
- TextMentionTermination: 메시지에서 특정 텍스트나 문자열이 언급되면 중지
- TokenUsageTermination: 특정 수의 프롬프트 또는 완료 토큰이 사용될 때 중지
- TimeoutTermination: 지정된 기간(초) 후에 중지
- HandoffTermination: 특정 타겟에 대한 핸드오프가 요청되면 중지
- SourceMatchTermination: 특정 에이전트가 응답한 후 실행을 중지
- ExternalTermination: 실행 외부에서 프로그래밍 방식으로 종료를 제어
- StopMessageTermination: 상담원이 StopMessage를 생성하면 중지
🎠 Managing State
구성 요소의 상태를 디스크에 저장했다가 나중에 다시 로드하는 것이 유용
=>
에이전트, 팀 및 종료 조건의 상태를 저장하고 로드하는 방법
Saving and Loading Agents
save_state() method on an AssistantAgent
agent_state = await assistant_agent.save_state()
Saving and Loading Teams
team_state = await agent_team.save_state()
팀을 리셋하면
await agent_team.reset()
참조가 사라져서 더 이상 agent_team의 이전 내용은 확인할 수 없음
하지만 저장된 team_state에는 내용이 저장되어 있음@!
Persisting State (File or Database)
팀의 상태를 디스크(또는 데이터베이스)에 유지했다가 나중에 다시 로드하기
import json
## save state to disk
with open("coding/team_state.json", "w") as f:
json.dump(team_state, f)
## load state from disk
with open("coding/team_state.json", "r") as f:
team_state = json.load(f)
new_agent_team = RoundRobinGroupChat([assistant_agent], termination_condition=MaxMessageTermination(max_messages=2))
await new_agent_team.load_state(team_state)
stream = new_agent_team.run_stream(task="What was the last line of the poem you wrote?")
await Console(stream)
'🤖 AI > AI' 카테고리의 다른 글
☄️autoGen MultimodalConversableAgent 트러블 슈팅 (0) | 2025.02.13 |
---|---|
🎠 AutoGen 공식문서 following : Advanced - Custom Agents (0) | 2025.02.11 |
🎠 AutoGen 공식문서 following : intro, model, messages, agents, Teams (0) | 2025.02.10 |
🧉 AGI / Test-time Scaling : Reasoning (0) | 2025.02.07 |
🔬LLM 운영하기 : LLM 평가 (0) | 2025.02.07 |