
This project is a small Node.js–based AI agent that combines OpenAI’s Large Language Model (LLM) with a set of modular tools. The agent can figure out when to call these tools — such as fetching posts from Reddit or generating images — and then incorporate the results back into its conversation with the user. It maintains a running memory of the conversation, so it can keep track of context across user queries.
-
User Input
You run the AI Agent by providing a message via the command line:
npm start "Fetch posts from LaLiga sub-reddit and then create a humorous meme image based on choosen post. If there is any with Vinicius, pick this one."
-
Agent Orchestration
-
The entry point
index.ts
takes in your user message and forwards it torunAgent
. -
Inside
runAgent
the system:- Logs your message to a memory store (using
lowdb
) - Calls
runLLM
to get a response from the OpenAI GPT-based model - If the AI decides it needs extra data (e.g., from Reddit) or wants to generate an image, it will output a tool call—at which point
toolRunner.ts
triggers the relevant tool.
- Logs your message to a memory store (using
- Memory
- Every message (including system and AI replies) is stored with metadata in a dummy JSON database
(db.json)
viamemory.ts
. This allows the AI to understand the context of previous messages.
- Tools
- Reddit
(reddit.ts)
: Fetches the latest posts from a specified subreddit (in this example, r/laliga). - Image Generation
(generateImage.ts)
: Uses DALL·E 3–style image generation to produce an image from a text prompt.
- UI/Logging
- The console output is managed by
ui.ts
, which provides a spinner and color-coded labels for each message role (user, assistant, etc.).
- Install Dependencies
npm install
-
Configure OpenAI
- Create a
.env
file with your OpenAI credentials:
- Create a
OPENAI_API_KEY=your_api_key_here
-
Run the agent
- For example:
npm start "Fetch posts from LaLiga subreddit and then create a humorous meme image..."