Build a tool that invokes the LLM
The school administration loves your work on the education app with the Wikipedia search agent. They would love you to expand the app even further with some additional tools. Here, you'll build a tool called historical_events() that's able to invoke the LLM within the body of the tool to answer questions about famous dates in history. The Wikipedia tool has already been set up for you and the llm is available in your environment.
Deze oefening maakt deel uit van de cursus
Designing Agentic Systems with LangChain
Oefeninstructies
- Add a decorator to label the tool and set the input format to string.
- Within the
tryblock, use the.invoke()method with thellmto query the LLM with thedate_inputto generate historical events. - Return the content of the LLM's response using
.content. - Add an
Exceptionblock aseto catch errors and format the error message to include the error details.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# Use a decorator to label the tool and set the input format to string
@____
def historical_events(date_input: ____) -> ____:
"""Provide a list of important historical events for a given date in any format."""
try:
# Invoke the LLM to interpret the date and generate historical events
response = ____.____(f"List important historical events that occurred on {____}.")
# Return the response
return ____.____
# Set an exception block for errors in retrieval
except ____ as ____:
return f"Error retrieving events: {str(____)}"