pocketflow/cookbook/pocketflow-agent/README.md

2.2 KiB

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:

  1. Answer questions by searching for information when needed
  2. Make decisions about when to search and when to answer
  3. Generate helpful responses based on collected research

Setting Up

Prerequisites

  • Python 3.8+
  • OpenAI API key

Installation

  1. Install the required packages:
pip install -r requirements.txt

Structure

  • main.py: Entry point and user interface
  • flow.py: Creates and connects the agent flow
  • nodes.py: Defines the decision and action nodes
  • utils.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
  1. DecideAction: Determines whether to search for information or provide an answer
  2. SearchWeb: Searches the web for information
  3. AnswerQuestion: Creates a final answer once enough information is gathered