메모리로 챗봇 출력 구성하기

LangChain으로 에이전트형 시스템 설계하기

Dilini K. Sumanapala, PhD

Founder & AI Engineer, Genverv, Ltd.

여러 도구 출력 스트리밍

    전체 그래프 워크플로.

 

  • 여러 도구의 출력 인쇄
      - Agent: [Tool 1: answer]
      - Agent: [Tool 2: answer]
    
  • 사용자 쿼리 인쇄 및 메모리 활성화
      - User: [Query]
      - Agent: [Tool 1: answer]
    
      - User: [Follow-up query]
      - Agent: [Tool 1: follow-up answer]
    
LangChain으로 에이전트형 시스템 설계하기

여러 도구 출력 스트리밍

from langchain_core.messages import AIMessage, HumanMessage


config = {"configurable": {"thread_id": "1"}}
# Create input message with the user's query def multi_tool_output(query):
inputs = {"messages": [HumanMessage(content=query)]}
# Stream messages and metadata from the chatbot application for msg, metadata in app.stream(inputs, config, stream_mode="messages"):
# Check if the message has content and is not from a human if msg.content and not isinstance(msg, HumanMessage): print(msg.content, end="", flush=True)
print("\n")
LangChain으로 에이전트형 시스템 설계하기

여러 도구로 테스트

동적 도구 할당 확인
multi_tool_output("Is `Stella won no wallets` a palindrome?")

multi_tool_output("What happened on April 12th, 1955?")
The phrase or word 'Stella won no wallets' is a palindrome.

Yes, the phrase "Stella won no wallets" is a palindrome.
April 12th, 1955, is notable for several reasons, particularly in the context of science and technology. On this date, the first successful polio vaccine developed by Dr. Jonas Salk was announced to the public. This vaccine was a significant breakthrough in the fight against poliomyelitis, a disease that had caused widespread fear and numerous outbreaks, particularly affecting children. The announcement marked a turning point in public health and led to widespread vaccination campaigns that ultimately contributed to the near-eradication of polio...
LangChain으로 에이전트형 시스템 설계하기

여러 도구를 활용한 후속 질문

# Print the user query first for every interaction
def user_agent_multiturn(queries):
    for query in queries:
        print(f"User: {query}")


# Stream through messages corresponding to queries, excluding metadata print("Agent: " + "".join(msg.content for msg, metadata in app.stream( {"messages": [HumanMessage(content=query)]}, config, stream_mode="messages")
# Filter out the human messages to print agent messages if msg.content and not isinstance(msg, HumanMessage)) + "\n")
queries = ["What happened on the 12 April 1961?", "What about 10 December 1948?", "Is `Mr. Owl ate my metal worm?` a palindrome?", "What about 'palladium stadium?'"] user_agent_multiturn(queries)
LangChain으로 에이전트형 시스템 설계하기

전체 대화 출력

  • 역사적 사건
User: What happened on the 12 April 1961?
Agent: On April 12, 1961, Yuri Gagarin, a Soviet cosmonaut, became the first human to travel 
into space aboard the Vostok 1 spacecraft...

User: What about 22 November 1963?
Agent: December 10, 1948... marks the Universal Declaration of Human Rights (UDHR).
  • 회문 검사
User: Is `Mr. Owl ate my metal worm?` a palindrome?
Agent: The phrase or word 'Mr. Owl ate my metal worm?' is a palindrome...

User: What about 'palladium stadium'?
Agent: No, the phrase `palladium stadium` is not a palindrome...
LangChain으로 에이전트형 시스템 설계하기

연습해 봅시다!

LangChain으로 에이전트형 시스템 설계하기

Preparing Video For Download...