Published on

AI Powered by SBLive

Authors
  • avatar
    Name
    Linell Bonnette
    Twitter

It's hard to deny the sweeping impact LLMs have had on the technology world recently, so I've been playing around with it all in an effort to better understand what is and isn't possible. One of the most interesting things have been agents.

The core idea of agents is to use an LLM to choose a sequence of actions to take. In chains, a sequence of actions is hardcoded (in code). In agents, a language model is used as a reasoning engine to determine which actions to take and in which order.

Tools are the functions that an agent calls. My idea was to create a couple of custom tools that would allow the agent to answer queries about data powered by the SBLive Connect API. I haven't done much more than debug Python code since around 2014, so that's a little rusty, but I ended up with something like:

class SBLiveSchoolTool(BaseTool):
    name = "SBLive School Tool"
    description = (
    "Use this tool when you need information about schools within SBLive, which knows everything about high school sports."
    "To use this tool, you must provide a either a 'name', 'state', or both. Information about the school will be returned, and the ID can be used for fetching other information from SBLive."
)

    def _run(
        self,
        name: Optional[str] = None,
        state: Optional[str] = None
    ):
        api = SBLiveAPI("https://api.sbliveconnect.io/staging")
        school_params = { "name": name, "state": state, "first": 5 }
        school_params = {key: value for key, value in school_params.items() if value is not None}
        schools = api.fetch_schools(school_params)
        if schools:
            return schools["data"]
        else:
            return "Encountered an error searching SBLive's API."

    def _arun(self, query: str):
        raise NotImplementedError("This tool does not support async")

From there, it's really as simple as just plugging the right bits and pieces into setting up and running the agent. Once you've got it all hooked together, the results are seriously just neat as heck.

asciicast