|
|
||
|---|---|---|
| .. | ||
| README.md | ||
| flow.py | ||
| main.py | ||
| nodes.py | ||
| requirements.txt | ||
| utils.py | ||
README.md
PocketFlow Research Agent - Tutorial for Dummy
This project demonstrates a simple LLM-powered research agent built with PocketFlow, a minimalist LLM framework in 100 lines. For more information on PocketFlow and how to build LLM agents, check out:
What It Does
This agent can:
- Answer questions by searching for information when needed
- Make decisions about when to search and when to answer
- Generate helpful responses based on collected research
Setting Up
Prerequisites
- Python 3.8+
- OpenAI API key
Installation
- Install the required packages:
pip install -r requirements.txt
Structure
main.py: Entry point and user interfaceflow.py: Creates and connects the agent flownodes.py: Defines the decision and action nodesutils.py: Contains utility functions for LLM calls and web searches
Quick Start Guide
Step 1: Set Up Your OpenAI API Key
First, you must provide your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"
Step 2: Test Utilities
Verify that your API key is working by testing the utilities:
python utils.py
This will test both the LLM call functionality and the web search capability.
Step 3: Run the Agent
Run the agent with the default question ("Who won the Nobel Prize in Physics 2024?"):
python main.py
Step 4: Ask Custom Questions
To ask your own question, use the -- prefix:
python main.py --"What is quantum computing?"
How It Works
The agent is structured as a simple directed graph with three main nodes:
graph TD
A[DecideAction] -->|"search"| B[SearchWeb]
A -->|"answer"| C[AnswerQuestion]
B -->|"decide"| A
- DecideAction: Determines whether to search for information or provide an answer
- SearchWeb: Searches the web for information
- AnswerQuestion: Creates a final answer once enough information is gathered