The Utility Agent is a command-line interface (CLI) program built with TypeScript. It integrates tools, APIs, and memory to act as an intelligent agent for fetching data, interacting with APIs, and running automated tasks. With robust integration with libraries like @balldontlie/sdk
for NBA data, OpenAI, Puppeteer, and more, it offers an extensible foundation for creating custom workflows.
- CLI-Based: Interact with the agent through a terminal interface.
- Robust API Integration: Leverage tools like Balldontlie, OpenAI, and Tomorrow.io for NBA data, LLM prompts, and weather data.
- Local LLM Integration: Run the agent with local LLMs powered by Ollama or LM Studio.
- Rate-Limiting and Retry Logic: Centralized request handling ensures compliance with API limits.
- Memory and State Management: Persistent and transient memory layers using
lowdb
for effective state tracking. - Web Scraping: Integrated tools for extracting and cleaning web data with Puppeteer and Cheerio.
- Node.js (v16+ recommended)
- NPM/Yarn for dependency management
- TypeScript
-
Clone the repository:
git clone https://github.com/bklynate/agent-from-scratch.git cd agent-from-scratch
-
Install dependencies:
nvm use npm install
-
Configure environment variables: Create a
.env
file in the root directory:BALL_DONT_LIE_API_KEY=<your_api_key> OPENAI_API_KEY=<your_openai_api_key> TOMORROW_WEATHER_API_KEY=<your_api_key> ORT_LOG_SEVERITY_LEVEL=ERROR
The entry point for the program is the index.ts
file, which serves as the main interface for the CLI agent. To execute the program:
npm run dev (this cleans the database each time)
or
npm run start
-
index.ts
- The main entry point for the CLI program.
- Handles argument parsing and routes user commands to the appropriate tools or tasks.
-
agent.ts
- Core agent logic, including memory management, tool execution, and LLM interactions.
-
ui.ts
- Manages user interactions in the terminal, providing input prompts and displaying results.
-
toolRunner.ts
- Coordinates the execution of tools, handling errors, retries, and formatted output.
-
bdlAPI.ts
- Provides NBA data using the
@balldontlie/sdk
. - Tools like fetching team records and standings are implemented here.
- Provides NBA data using the
-
queryGoogle.ts
- Fetches and processes Google search results for extracting information.
-
currentWeather.ts
- Retrieves real-time weather data for a specified location using the Tomorrow.io API.
-
cleanHTML.ts
- Cleans and sanitizes HTML for safe data processing.
-
memory.ts
- Implements persistent storage for tracking state and managing agent memory.
- Modify the tools or core logic in their respective files (e.g.,
toolRunner.ts
for tool execution,llm.ts
for LLM interactions). - Use
.env
to securely store API keys.
@balldontlie/sdk
: Fetch NBA data like teams, games, and players.@openai/openai
: Interface with OpenAI's LLM for dynamic prompts.p-throttle
: Rate-limiting API requests to avoid hitting limits.puppeteer-extra
: Adds stealth functionality for advanced web scraping.lowdb
: Lightweight database for managing agent memory and state.
- TypeScript definitions for robust type checking and IntelliSense.
Contributions are welcome! Submit pull requests or open issues to propose features or report bugs.
This project is licensed under the MIT License.