Skip to content

CS-153/ai-agent-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CS 153 - Weather Agent Example Code

Here is an example of a very simple final project. This should be a good starter point giving you a sense of what technical abilities you will need for this class. This would be an example of a simple, passing grade project that has been built off our starter code. We're looking for much cooler and technically complex projects that will catch the eyes of our judges :).

Weather Agent

CleanShot.2025-01-21.at.20.50.33.mp4

This Discord bot listens for messages requesting information about the weather in a specific location (i.e. "What's the weather in SF?" or "Is it raining right now in NYC?") and responds to their prompt with accurate weather information.

This is achieved through use of a weather tool which gives the agent access to real-time weather data. Your projects will probably incorporate a tool of some sort as well to enhance the abilities of your agent.

What is an Agent?

An LLM turns into an Agent when it is given the ability to take actions on the user's behalf. In this case, the action was looking up weather data. Other examples of actions are adding an event to your calendar, scraping a website, or sending an email. This is the beauty of Agents: there's infinite actions out there yet to be explored.

What are tools?

An Agent accomplishes its task using tools, which are Python functions that the agent can call to obtain certain information or take certain actions. In this case, the Weather Agent uses the seven_day_forecast(long, lat) function in /tools/weather.py to fetch weather data for a specific location.

See more on function calling in Mistral's documentation.

Weather Agent Structure

This project uses two separate LLM conversations to achieve its task.

Task 1

To act as a passive observer of the channel, the first task is to check if a message explicitly requests weather information for a specific city. While this could be combined with the second task, separating the two is a design decision to allow the agent to fully focus on one single task at a time.

Task one is defined by EXTRACT_LOCATION_PROMPT in agent.py.

If no weather request is extracted from the message, which will likely be the case most of the time, the bot will not respond.

Otherwise, the bot extracts the location and continues to task 2.

Task 2

Once the location is extracted, task 2 provides the agent with the seven_day_forecast(long, lat) tool to fetch weather information for a specific longitude and latitude. The LLM is great at providing the longitude and latitude itself given a location, so it's able to call the function directly.

The function is then called, and its response is piped back into the LLM.

Finally, the LLM replies with its final response, the message that will be sent to the user that answers their weather question.

About

Weather agent bot written in python

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages