BaşlayınÜcretsiz Başlayın

ReAct agents

Time to have a go at creating your own ReAct agent! Recall that ReAct stands for Reason and Act, which describes how they make decisions. In this exercise, you'll load the built-in wikipedia tool to integrate external data from Wikipedia with your LLM. An llm has already been defined for you that uses OpenAI's gpt-4o-mini model

Note: The wikipedia tool requires the wikipedia Python library to be installed as a dependency, which has been done for you in this case.

Bu egzersiz

Developing LLM Applications with LangChain

kursunun bir parçasıdır
Kursu Görüntüle

Egzersiz talimatları

  • Load the "wikipedia" tool using the load_tools() function.
  • Define a ReAct agent using create_react_agent(), passing it the llm and tools to use.
  • Run the agent on the input provided and print the content from the final message in response.

Uygulamalı interaktif egzersiz

Bu örnek kodu tamamlayarak bu egzersizi bitirin.

# Define the tools
tools = load_tools(["____"])

# Define the agent
agent = create_react_agent(____, ____)

# Invoke the agent
response = agent.____({"messages": [("human", "How many people live in New York City?")]})
print(response['messages'][-1].____)
Kodu Düzenle ve Çalıştır