-
-
Notifications
You must be signed in to change notification settings - Fork 730
feat: Add Agentic RAG Example to Cookbooks #1084
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Add Agentic RAG Example to Cookbooks #1084
Conversation
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds two new example notebooks demonstrating agentic RAG workflows with PraisonAI: one builds a Thai-recipe RAG agent (gpt-4o) with web search and PDF KB; the other provides a CLI-style interactive agent example targeting GPT-5 (gpt-5-nano) with dotenv/API-key handling and an interactive loop. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor U as User
participant N as Recipe Notebook
participant A as PraisonAI Agent
participant K as PDF KB
participant W as Web Search
participant L as LLM (gpt-4o)
U->>N: run cells / ask recipe question
N->>A: invoke(question)
A->>K: retrieve(relevant passages)
A->>W: internet_search(query)
W-->>A: search results
K-->>A: passages
A->>L: prompt(with context)
L-->>A: generated answer (Markdown/HTML)
A-->>N: formatted response
N-->>U: display answer
sequenceDiagram
autonumber
actor U as User (CLI)
participant S as GPT‑5 Notebook (script)
participant A as PraisonAI Agent
participant L as LLM (gpt-5-nano)
U->>S: start / enter query
S->>A: create_agent() / start(query)
A->>L: prompt(query + tools/context)
L-->>A: response
A-->>S: answer (rich display)
S-->>U: print "💡 Answer" / loop or exit
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20–30 minutes Possibly related PRs
Poem
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @Dhivya-Bharathy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request adds a new, comprehensive example to the PraisonAI cookbooks, demonstrating an agentic Retrieval-Augmented Generation (RAG) system. The core purpose is to provide a practical illustration of how to build an AI agent capable of specializing in a particular domain, in this case, Thai cuisine. The agent is designed to enhance its knowledge by integrating web search capabilities and referencing a PDF knowledge base, offering a robust solution for interactive information retrieval and generation. This addition aims to guide users in implementing similar intelligent agents within the PraisonAI framework.
Highlights
- New Agentic RAG Example: This PR introduces a new example of an Agentic RAG system within the PraisonAI cookbooks, showcasing how to build an AI agent that can retrieve information and generate responses.
- Thai Recipe Specialization: The agent is specifically designed to answer questions about Thai recipes and cooking, leveraging a dedicated PDF knowledge base for specialized information.
- Web Search Integration: The RAG agent integrates web search capabilities using DuckDuckGo, allowing it to fetch additional, up-to-date information beyond its internal knowledge base.
- Interactive Chat Interface: The example provides an interactive conversational interface, enabling users to ask cooking-related questions and receive comprehensive answers.
- Enhanced User Experience: The implementation includes robust error handling and supports Markdown formatting for improved readability of the agent's responses.
- Google Colab Notebook: A Google Colab notebook (
PraisonAI_RecipeAgent.ipynb
) is included, providing a ready-to-run environment for easy experimentation and learning.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1084 +/- ##
========================================
Coverage 14.23% 14.24%
========================================
Files 25 25
Lines 2571 2717 +146
Branches 367 389 +22
========================================
+ Hits 366 387 +21
- Misses 2189 2314 +125
Partials 16 16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request adds a great example of an Agentic RAG to the cookbooks. The Jupyter notebook is well-structured and provides a clear demonstration of using PraisonAI for building a specialized AI agent. My main feedback is a small improvement to the API key handling in the notebook to make it more robust and less confusing for users. Otherwise, the example is excellent.
"import os\n", | ||
"\n", | ||
"# Set your OpenAI API key here\n", | ||
"os.environ['OPENAI_API_KEY'] = 'Enter your api key here'\n", | ||
"\n", | ||
"# Or use this method to input it securely\n", | ||
"from getpass import getpass\n", | ||
"api_key = getpass('Enter your OpenAI API key: ')\n", | ||
"os.environ['OPENAI_API_KEY'] = api_key\n", | ||
"\n", | ||
"print(\"✅ API key set successfully!\")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation for setting the OpenAI API key is a bit confusing. It includes a hardcoded placeholder key that is immediately overwritten by the getpass
input. This is redundant and can be simplified to avoid confusion.
A cleaner approach is to first check if the API key is already set in the environment, and only prompt the user if it's not found. This makes the notebook more robust and easier to re-run without re-entering the key every time.
import os
from getpass import getpass
# Input your OpenAI API key securely.
# If the key is already set as an environment variable, that will be used.
api_key = os.environ.get("OPENAI_API_KEY")
if not api_key:
api_key = getpass('Enter your OpenAI API key: ')
os.environ['OPENAI_API_KEY'] = api_key
print("✅ API key set successfully!")
PR Code Suggestions ✨Explore these optional code suggestions:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 6
🧹 Nitpick comments (4)
examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb (4)
247-454
: Strip notebook outputs and execution counts before committing.Large embedded outputs make diffs noisy and can include sensitive context.
Use nbstripout/pre-commit, or in Jupyter: Edit > Clear All Outputs, then save. I can add a minimal
.pre-commit-config.yaml
if desired.
461-461
: Fix mojibake in print label.“��” indicates an encoding issue; use a valid emoji or plain text.
Apply this diff:
- print(f"�� Answer: {response1}") + print(f"✅ Answer: {response1}")
225-235
: Make verbose output opt-in for cookbook clarity.The current verbose HTML frames distract from the example.
Apply this diff:
- verbose=True + verbose=False # set True if you want detailed agent logs
455-463
: Add a web-search test to prove agentic behavior.Demonstrate a query that requires current info and verify that the tool runs.
Add a second test cell like:
# New cell question2 = "What Thai basil substitutes are recommended in 2025 per reputable sources?" print(f"🤔 Question: {question2}") try: response2 = rag_agent.start(question2) print(f"✅ Answer: {response2}") except Exception as e: print(f"❌ Error: {e}")Please confirm via logs that
internet_search
is actually invoked (per PraisonAI docs).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
16-16: requests
imported but unused
Remove unused import: requests
(F401)
17-17: tempfile
imported but unused
Remove unused import: tempfile
(F401)
18-18: pathlib.Path
imported but unused
Remove unused import: pathlib.Path
(F401)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: quick-test
- GitHub Check: test-core (3.11)
"[](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb)\n" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix incorrect Colab badge link (points to a fork).
Update the badge to the upstream repo path so it works after merge.
Apply this diff:
- "[](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb)\n"
+ "[](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb)\n"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"[](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb)\n" | |
] | |
"[](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb)\n" |
🤖 Prompt for AI Agents
In examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
around lines 41-42, the Colab badge currently links to the fork
(Dhivya-Bharathy/PraisonAI); update the badge URL to point to the upstream
repository path (replace the fork owner/repo in both the badge image link and
the href with the upstream owner/repo and correct branch/path, e.g.
https://colab.research.google.com/github/<UPSTREAM_OWNER>/<UPSTREAM_REPO>/blob/main/examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb)
so the badge opens the notebook in Colab after merge.
"!pip install praisonaiagents openai requests" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Use requirements or pin deps; drop unused package.
Unpinned installs harm reproducibility; requests
isn’t used.
Apply this diff:
- "!pip install praisonaiagents openai requests"
+ "!pip install -U praisonaiagents openai"
+ # Alternatively, to match the repo:
+ # "%pip -q install -r examples/cookbooks/rag_examples/agentic_rag/requirements.txt"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"!pip install praisonaiagents openai requests" | |
] | |
"!pip install -U praisonaiagents openai" | |
# Alternatively, to match the repo: | |
# "%pip -q install -r examples/cookbooks/rag_examples/agentic_rag/requirements.txt" | |
] |
🤖 Prompt for AI Agents
In examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
around lines 61-62, the notebook currently runs an unpinned pip install
including an unused package; update it to use pinned dependencies (or a
requirements.txt) and remove the unused "requests" package. Either replace the
inline "!pip install praisonaiagents openai requests" with a pinned install like
"!pip install praisonaiagents==<version> openai==<version>" or add a
requirements.txt with exact versions and run "!pip install -r requirements.txt",
and eliminate "requests" from the install list.
"import os\n", | ||
"\n", | ||
"# Set your OpenAI API key here\n", | ||
"os.environ['OPENAI_API_KEY'] = 'Enter your api key here'\n", | ||
"\n", | ||
"# Or use this method to input it securely\n", | ||
"from getpass import getpass\n", | ||
"api_key = getpass('Enter your OpenAI API key: ')\n", | ||
"os.environ['OPENAI_API_KEY'] = api_key\n", | ||
"\n", | ||
"print(\"✅ API key set successfully!\")" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove plaintext API key placeholder; prefer env or secure prompt.
Avoid accidental secret leakage in committed notebooks.
Apply this diff:
-import os
-
-# Set your OpenAI API key here
-os.environ['OPENAI_API_KEY'] = 'Enter your api key here'
-
-# Or use this method to input it securely
-from getpass import getpass
-api_key = getpass('Enter your OpenAI API key: ')
-os.environ['OPENAI_API_KEY'] = api_key
-
-print("✅ API key set successfully!")
+import os
+from getpass import getpass
+
+# Prefer existing env; otherwise prompt securely.
+api_key = os.getenv("OPENAI_API_KEY") or getpass("Enter your OpenAI API key: ")
+os.environ["OPENAI_API_KEY"] = api_key
+print("✅ API key set successfully!")
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"import os\n", | |
"\n", | |
"# Set your OpenAI API key here\n", | |
"os.environ['OPENAI_API_KEY'] = 'Enter your api key here'\n", | |
"\n", | |
"# Or use this method to input it securely\n", | |
"from getpass import getpass\n", | |
"api_key = getpass('Enter your OpenAI API key: ')\n", | |
"os.environ['OPENAI_API_KEY'] = api_key\n", | |
"\n", | |
"print(\"✅ API key set successfully!\")" | |
] | |
import os | |
from getpass import getpass | |
# Prefer existing env; otherwise prompt securely. | |
api_key = os.getenv("OPENAI_API_KEY") or getpass("Enter your OpenAI API key: ") | |
os.environ["OPENAI_API_KEY"] = api_key | |
print("✅ API key set successfully!") |
🤖 Prompt for AI Agents
In examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
around lines 94 to 105, remove the hardcoded plaintext API key assignment and
replace it with a secure pattern: delete the os.environ['OPENAI_API_KEY'] =
'Enter your api key here' line, keep (or add) a secure prompt using getpass to
read the key at runtime and set os.environ['OPENAI_API_KEY'] = api_key, and
ensure any example includes a comment advising use of environment variables or
secrets managers rather than embedding keys in the notebook.
"from praisonaiagents import Agent\n", | ||
"import requests\n", | ||
"import tempfile\n", | ||
"from pathlib import Path\n", | ||
"\n", | ||
"print(\"✅ Tools imported successfully!\")" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Drop unused imports (Ruff F401).
requests
, tempfile
, and Path
are unused.
Apply this diff:
-from praisonaiagents import Agent
-import requests
-import tempfile
-from pathlib import Path
+from praisonaiagents import Agent
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"from praisonaiagents import Agent\n", | |
"import requests\n", | |
"import tempfile\n", | |
"from pathlib import Path\n", | |
"\n", | |
"print(\"✅ Tools imported successfully!\")" | |
] | |
from praisonaiagents import Agent | |
print("✅ Tools imported successfully!") |
🤖 Prompt for AI Agents
In examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
around lines 136 to 142, the imports requests, tempfile, and Path are unused and
trigger Ruff F401; remove those three import statements so only used imports
remain (keep "from praisonaiagents import Agent" and any other used imports),
and rerun linting to confirm the F401 warnings are resolved.
"# Agent configuration and instructions\n", | ||
"AGENT_INSTRUCTIONS = \"\"\"\n", | ||
"You are a helpful AI assistant specialized in Thai recipes and cooking.\n", | ||
"\n", | ||
"You have access to a PDF knowledge base about Thai recipes from: https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf\n", | ||
"\n", | ||
"You can also search the web for additional information about Thai cooking, ingredients, and techniques.\n", | ||
"\n", | ||
"When answering questions:\n", | ||
"1. Use your knowledge about Thai cuisine to provide helpful information\n", | ||
"2. If needed, search the web for additional details, current information, or clarification\n", | ||
"3. Provide comprehensive, helpful answers about Thai cuisine\n", | ||
"4. Always be informative and helpful about Thai cooking!\n", | ||
"\n", | ||
"You can use the internet_search function to search the web when needed.\n", | ||
"\n", | ||
"Focus on providing practical cooking advice, ingredient information, and authentic Thai recipe guidance.\n", | ||
"\"\"\"\n", | ||
"\n", | ||
"print(\"✅ Agent instructions configured!\")" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claims about PDF KB and web search aren’t implemented.
Instructions reference a PDF KB and internet_search
, but no tools/KB are wired; this is a plain LLM chat, not RAG.
I can help wire actual retrieval (PDF loader + index) and enable web search, or adjust the copy to avoid claiming RAG until it’s truly connected.
🤖 Prompt for AI Agents
In examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
around lines 173 to 193, the AGENT_INSTRUCTIONS wrongly claim access to a PDF
knowledge base and an internet_search tool that aren’t implemented; either wire
those resources or remove the claims. Fix option A (implement RAG): add a PDF
loader that fetches/ingests
https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf, create an
embeddings/index (e.g., FAISS/Lance/annoy) and a retrieval function the agent
can call, and register an internet_search tool (or integrate a search API
client) in the agent’s toolset so internet_search calls are routed to that
function. Or fix option B (downgrade instructions): edit AGENT_INSTRUCTIONS to
remove mentions of the PDF and internet_search and reword to reflect this is a
plain LLM chat with no external KB or web access. Ensure whichever path you
choose, the text and code stay consistent (either add the loader/tool
integrations and reference them in agent construction, or remove all external
access references from the instruction string).
"# Create the RAG agent\n", | ||
"rag_agent = Agent(\n", | ||
" instructions=AGENT_INSTRUCTIONS,\n", | ||
" llm=\"gpt-4o\",\n", | ||
" markdown=True,\n", | ||
" verbose=True\n", | ||
")\n", | ||
"\n", | ||
"print(\"🤖 Thai Recipe RAG Agent created successfully!\")\n", | ||
"print(\"The agent is ready to answer questions about Thai cooking.\")" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Wire the RAG pieces: enable internet search and attach the PDF KB.
Without explicit tool registration and document ingestion, the agent cannot search or retrieve. Please integrate per PraisonAI APIs.
Confirm the correct PraisonAI API to (a) enable DuckDuckGo search and (b) attach a PDF/document store:
Once confirmed, update this cell accordingly. For example (pattern only; adjust to actual API):
rag_agent = Agent(
instructions=AGENT_INSTRUCTIONS,
- llm="gpt-4o",
- markdown=True,
- verbose=True
+ llm="gpt-4o",
+ markdown=True,
+ # Enable web search tool
+ tools=["internet_search"],
+ # Attach KB (local path or URL after download/indexing)
+ knowledge_base=["ThaiRecipes.pdf"],
+ verbose=False
)
Additionally, add a preceding cell to fetch and persist the PDF (only if the Agent requires a local file/index):
# New cell (insert before agent creation)
import requests, tempfile, os
pdf_url = "https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
kb_dir = tempfile.mkdtemp(prefix="thai_kb_")
pdf_path = os.path.join(kb_dir, "ThaiRecipes.pdf")
with requests.get(pdf_url, stream=True, timeout=30) as r:
r.raise_for_status()
with open(pdf_path, "wb") as f:
for chunk in r.iter_content(8192):
f.write(chunk)
print(f"📚 KB downloaded to: {pdf_path}")
🌐 Web query:
PraisonAI Agents: How to enable the `internet_search` tool on an Agent?
PraisonAI Agents: How to attach PDFs or a knowledge base for RAG (e.g., passing file paths/URLs or an index) to Agent?
💡 Result:
Short answer — yes.
- Enable internet_search tool for an Agent
- Implement the search as a normal Python function (example uses duckduckgo-search/DDGS).
- Pass that function in the agent's tools list when you construct the Agent. The agent will call the tool when its instructions/task require web search.
- Example pattern:
- define def internet_search_tool(query: str) -> List[Dict]: ... (use DDGS, requests, Google API, etc.)
- Agent(..., tools=[internet_search_tool], ...)
- See PraisonAI docs on adding tools / web-search tool examples. [1][2]
- Attach PDFs / build a RAG knowledge base for an Agent
- You can pass file paths, URLs, or text directly to the Agent via the knowledge parameter: e.g. knowledge=["doc.pdf","https://...","notes.txt"] or pass a Knowledge instance. The agent will index/process those files for retrieval.
- To customise vector-store behavior, supply knowledge_config (example: provider "chroma", collection name and path). You can also use the Knowledge module directly (Knowledge.add(), store(), search()) and attach that to the Agent.
- Example:
- Agent(..., knowledge=["manual.pdf","https://example.com/article"], knowledge_config={ "vector_store": {"provider":"chroma","config":{"collection_name":"my_kb","path":".praison"}} })
- See PraisonAI Knowledge / RAG / Chat-with-PDF docs for file formats, indexing APIs, and sample code. [3][4][5]
Sources
- Adding tools / internet-search examples (tools, DDGS example). [1][2]
- Knowledge, RAG, and PDF-chat docs (knowledge parameter, knowledge_config, Knowledge.add/store usage). [3][4][5]
References
[1] https://docs.praison.ai/docs/course/agents/12-adding-tools-to-agents
[2] https://docs.praison.ai/concepts/tools
[3] https://docs.praison.ai/docs/api/praisonaiagents/knowledge/knowledge
[4] https://docs.praison.ai/features/rag
[5] https://docs.praison.ai/features/chat-with-pdf
Enable web‐search tool and ingest PDF KB
- Define and register an
internet_search_tool
(e.g. wrapping DuckDuckGo via DDGS) and pass it intotools
- Supply the PDF to
knowledge
(and optionally configure your vector store viaknowledge_config
)
Update the agent cell as follows:
rag_agent = Agent(
instructions=AGENT_INSTRUCTIONS,
- llm="gpt-4o",
- markdown=True,
- verbose=True
+ llm="gpt-4o",
+ markdown=True,
+ tools=[internet_search_tool], # enable web search
+ knowledge=[pdf_path], # attach local PDF KB
+ knowledge_config={ # optional store settings
+ "vector_store": {
+ "provider": "chroma",
+ "config": {"collection_name": "thai_kb", "path": ".praison"}
+ }
+ },
+ verbose=False
)
Add a new cell before the above to download and persist the PDF locally:
import requests, tempfile, os
pdf_url = "https://phi-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
kb_dir = tempfile.mkdtemp(prefix="thai_kb_")
pdf_path = os.path.join(kb_dir, "ThaiRecipes.pdf")
with requests.get(pdf_url, stream=True, timeout=30) as r:
r.raise_for_status()
with open(pdf_path, "wb") as f:
for chunk in r.iter_content(8192):
f.write(chunk)
print(f"📚 KB downloaded to: {pdf_path}")
🤖 Prompt for AI Agents
In examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
around lines 225 to 235, the agent is created without a web-search tool or the
PDF knowledge base; define and register an internet_search_tool (e.g., a
DuckDuckGo/DDGS wrapper) and pass it into the Agent via the tools parameter, and
supply the downloaded PDF into the Agent via the knowledge parameter (optionally
configure knowledge_config to set your vector store/index settings); also add a
new cell before this agent cell that downloads and persists the PDF locally (use
requests with streaming and timeout, save to a temp directory and print the
path) so the Agent can ingest the local PDF when created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 7
🧹 Nitpick comments (4)
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb (4)
513-517
: Normalize quit command and ignore pure whitespace.
Current code misses inputs like " Quit ".- if user_query.lower() in ['quit', 'exit', 'q']: + if user_query.strip().lower() in ['quit', 'exit', 'q']: print("👋 Goodbye!") break
534-534
: Fix another mojibake print message.- print("�� Make sure your API key is correct and you have sufficient credits.") + print("Make sure your API key is correct and you have sufficient credits.")
542-556
: Clear executed outputs and execution_count before committing notebooks.
Keeps diffs small and avoids committing runtime artifacts.Use this to strip outputs locally before commit:
#!/bin/bash pip install -q nbstripout nbstripout --install git diff --name-only --cached -z | xargs -0 -I{} bash -lc '[[ "{}" == *.ipynb ]] && nbstripout "{}" || true'Or one-off:
jupyter nbconvert --ClearOutputPreprocessor.enabled=True --inplace examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
61-62
: Optional: if you do want a Streamlit UI, add it; otherwise remove Streamlit mentions entirely.
Here’s a minimal Streamlit cell you can add (or keep it CLI-only and drop Streamlit references):# Minimal Streamlit UI (run via: streamlit run this_notebook_converted.py) import streamlit as st st.title("PraisonAI Agent") q = st.text_input("Ask a question") if q: try: agent = create_agent() st.markdown(agent.start(q)) except Exception as e: st.error(f"{type(e).__name__}: {e}")Also applies to: 108-109, 112-123, 479-486
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
(1 hunks)
🧰 Additional context used
🪛 Ruff (0.12.2)
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
13-13: streamlit
imported but unused
Remove unused import: streamlit
(F401)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: quick-test
- GitHub Check: Run tests and collect coverage
- GitHub Check: test-core (3.11)
🔇 Additional comments (2)
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb (2)
143-151
: Agent factory looks fine.
No issues spotted; simple pass-through from config.
112-123
: Use an environment variable for the model with a broadly available default
Replace the hard-coded"gpt-5-nano"
with anOPENAI_MODEL
override defaulting togpt-4o
:- "llm": "gpt-5-nano", + "llm": os.getenv("OPENAI_MODEL", "gpt-4o"),Ensure you
import os
at the top of the notebook.
"# Agentic RAG with GPT-5 - Colab Notebook" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Title claims RAG but notebook implements a simple CLI agent (no retrieval). Rename or implement RAG.
The current code has no KB ingestion, retriever, or web search. Avoid misleading users.
Apply this diff to align the title now (implement RAG later in a separate PR or notebook):
-# Agentic RAG with GPT-5 - Colab Notebook
+# PraisonAI Agent (CLI demo) — no RAG
Committable suggestion skipped: line range outside the PR's diff.
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 9 to 10, the notebook title claims "Agentic RAG" but the notebook
contains only a simple CLI agent with no knowledge-base ingestion, retriever, or
web search; update the title to remove "RAG" (e.g., "Agentic GPT-5 CLI
Notebook") or, if you prefer to keep "RAG", implement KB ingestion and retrieval
components (add code cells for creating/importing a datastore, ingesting
documents, initializing a retriever, and integrating retrieval into the agent
pipeline) — pick one approach and make the change so the title accurately
reflects the notebook contents.
"This Colab notebook sets up a Streamlit app using PraisonAI Agents framework.\n", | ||
"It allows you to interact with an AI agent powered by GPT-5 for Q&A.\n", | ||
"Currently, the knowledge base functionality is disabled due to compatibility issues." | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Markdown copy is inconsistent (mentions Streamlit + RAG/KB disabled). Fix description and features.
The notebook doesn’t use Streamlit or any KB. Update copy to reflect a CLI demo.
-This Colab notebook sets up a Streamlit app using PraisonAI Agents framework.
-It allows you to interact with an AI agent powered by GPT-5 for Q&A.
-Currently, the knowledge base functionality is disabled due to compatibility issues.
+This Colab notebook demonstrates a CLI-style PraisonAI Agent for Q&A.
+It runs entirely in a cell with input()/print() and does not include a knowledge base (no RAG).
+For a full RAG + web-search example, see the Thai recipes cookbook in this PR.
@@
-- Streamlit Web App
-- Agent Framework: PraisonAI Agents
+- CLI Demo (input/print loop)
+- Agent Framework: PraisonAI Agents
Also applies to: 29-33
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 18-21 and 29-33, the markdown incorrectly describes the demo as a
Streamlit app and mentions RAG/KB being disabled; update the notebook text to
accurately describe the example as a CLI/demo that runs PraisonAI Agents with
GPT-5 and that it does not use Streamlit or a knowledge base, and adjust
features list to only list CLI interaction, agent capabilities, and any external
dependency notes.
"[](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/Qwen2.5_InstructionAgent.ipynb)\n" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix the “Open in Colab” badge URL.
It points to a different repo/notebook. Link to this notebook in the current repo.
-[](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/Qwen2.5_InstructionAgent.ipynb)
+[](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"[](https://colab.research.google.com/github/Dhivya-Bharathy/PraisonAI/blob/main/examples/cookbooks/Qwen2.5_InstructionAgent.ipynb)\n" | |
] | |
"[](https://colab.research.google.com/github/MervinPraison/PraisonAI/blob/main/examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb)\n" |
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 41-42, the "Open in Colab" badge points to a different notebook;
replace the existing badge URL with a Colab link that points to this notebook in
the current repository (e.g.
https://colab.research.google.com/github/<ORG_OR_USER>/<REPO>/blob/main/examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb)
and ensure the markdown badge remains unchanged except for the URL so users open
this exact notebook in Colab.
"!pip install praisonaiagents python-dotenv streamlit" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Dependencies: remove Streamlit (unused) and add openai/requests per project README.
Aligns with PR getting-started steps and avoids unnecessary install.
-!pip install praisonaiagents python-dotenv streamlit
+!pip install -q praisonaiagents openai requests python-dotenv
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"!pip install praisonaiagents python-dotenv streamlit" | |
] | |
"!pip install -q praisonaiagents openai requests python-dotenv" | |
] |
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 61-62, the pip install list includes an unused dependency
(streamlit) and is missing required packages per the project README; update the
install command to remove "streamlit" and add "openai" and "requests" while
keeping "praisonaiagents" and "python-dotenv" so the notebook installs only
needed dependencies.
"import os\n", | ||
"from dotenv import load_dotenv\n", | ||
"\n", | ||
"load_dotenv()\n", | ||
"\n", | ||
"OPENAI_API_KEY = \"Enter your api key here\"\n", | ||
"\n", | ||
"os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n" | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don’t hardcode API keys; load from env and optionally prompt (never overwrite a valid env).
Hardcoding encourages accidental commits and your sentinel doesn’t match the check later.
-import os
-from dotenv import load_dotenv
-
-load_dotenv()
-
-OPENAI_API_KEY = "Enter your api key here"
-
-os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
+import os
+from getpass import getpass
+from dotenv import load_dotenv
+
+load_dotenv()
+# Prefer existing env; only prompt if missing (not stored in notebook).
+if not os.getenv("OPENAI_API_KEY"):
+ entered = getpass("Enter your OpenAI API key (input hidden, not saved): ").strip()
+ if entered:
+ os.environ["OPENAI_API_KEY"] = entered
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"import os\n", | |
"from dotenv import load_dotenv\n", | |
"\n", | |
"load_dotenv()\n", | |
"\n", | |
"OPENAI_API_KEY = \"Enter your api key here\"\n", | |
"\n", | |
"os.environ[\"OPENAI_API_KEY\"] = OPENAI_API_KEY\n" | |
] | |
import os | |
from getpass import getpass | |
from dotenv import load_dotenv | |
load_dotenv() | |
# Prefer existing env; only prompt if missing (not stored in notebook). | |
if not os.getenv("OPENAI_API_KEY"): | |
entered = getpass("Enter your OpenAI API key (input hidden, not saved): ").strip() | |
if entered: | |
os.environ["OPENAI_API_KEY"] = entered |
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 81 to 89, the notebook currently hardcodes OPENAI_API_KEY and then
overwrites os.environ which risks accidental commits and breaks later sentinel
checks; instead, read the key from the environment with os.getenv (after
load_dotenv), do not overwrite an existing os.environ value, and if the key is
missing optionally prompt the user or raise a clear error—replace the hardcoded
assignment with a getenv call, only set os.environ if a non-empty key is
provided and the env var is not already set, and remove any sentinel string
usage so downstream checks use the real environment value.
"import streamlit as st\n", | ||
"from praisonaiagents import Agent\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Remove unused Streamlit import (Ruff F401) or actually use it.
Currently unused; simplest fix is removal.
-import streamlit as st
from praisonaiagents import Agent
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"import streamlit as st\n", | |
"from praisonaiagents import Agent\n", | |
"from praisonaiagents import Agent\n", |
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 108 to 109, the import "import streamlit as st" is unused (Ruff
F401); remove that import line from the notebook (or replace it with actual
usage if Streamlit is intended), ensuring only necessary imports remain to
satisfy linting.
"def main():\n", | ||
" print(\"�� Initializing Agentic RAG with GPT-5...\")\n", | ||
"\n", | ||
" # Check if API key is set\n", | ||
" if not OPENAI_API_KEY or OPENAI_API_KEY == \"your_openai_api_key_here\":\n", | ||
" print(\"❌ Please set your OpenAI API key first!\")\n", | ||
" print(\"�� Get your key from: https://platform.openai.com/\")\n", | ||
" return\n", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix encoding garble and API-key check logic.
The “��” glyphs are mojibake. Also the check compares to a different sentinel and can pass with an invalid placeholder.
-def main():
- print("�� Initializing Agentic RAG with GPT-5...")
+def main():
+ print("Initializing PraisonAI Agent (CLI)...")
@@
- # Check if API key is set
- if not OPENAI_API_KEY or OPENAI_API_KEY == "your_openai_api_key_here":
- print("❌ Please set your OpenAI API key first!")
- print("�� Get your key from: https://platform.openai.com/")
+ # Check if API key is set (env is the source of truth)
+ if not os.getenv("OPENAI_API_KEY"):
+ print("❌ Please set your OPENAI_API_KEY environment variable.")
+ print("Get a key from: https://platform.openai.com/")
return
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
"def main():\n", | |
" print(\"�� Initializing Agentic RAG with GPT-5...\")\n", | |
"\n", | |
" # Check if API key is set\n", | |
" if not OPENAI_API_KEY or OPENAI_API_KEY == \"your_openai_api_key_here\":\n", | |
" print(\"❌ Please set your OpenAI API key first!\")\n", | |
" print(\"�� Get your key from: https://platform.openai.com/\")\n", | |
" return\n", | |
def main(): | |
print("Initializing PraisonAI Agent (CLI)...") | |
# Check if API key is set (env is the source of truth) | |
if not os.getenv("OPENAI_API_KEY"): | |
print("❌ Please set your OPENAI_API_KEY environment variable.") | |
print("Get a key from: https://platform.openai.com/") | |
return |
🤖 Prompt for AI Agents
In
examples/cookbooks/rag_examples/agentic_rag/agentic_rag_gpt5_praisonai_agents.ipynb
around lines 479 to 486, replace the mojibake "��" characters with the intended
readable emoji/text (e.g., a rocket or initializing message like "🚀
Initializing Agentic RAG with GPT-5...") and fix the API key validation to
reject empty/whitespace and the actual placeholder used in the repo (trim the
OPENAI_API_KEY, check if it's falsy or equals "your_openai_api_key" (or the
correct placeholder string used elsewhere) and treat that as invalid), then
update the guidance print line to a clear message (e.g., "❌ Please set your
OpenAI API key first!" and "🔑 Get your key from:
https://platform.openai.com/").
User description
🗃️ Add Agentic RAG Example to Cookbooks
📋 Description
This PR adds a comprehensive RAG (Retrieval-Augmented Generation) agent example to the PraisonAI cookbooks. The example demonstrates how to build an AI agent specialized in Thai recipes with web search capabilities using PraisonAI framework.
✨ Features
��️ What's Included
rag_agent.py
- Main RAG agent implementationREADME.md
- Comprehensive documentationrequirements.txt
- Dependencies listPraisonAI_RecipeAgent.ipynb
- Google Colab notebook.praison/
- PraisonAI configuration🎯 Use Cases
�� Technical Details
�� Example Questions
The agent can answer questions about:
�� Getting Started
pip install praisonaiagents openai requests
python rag_agent.py
🔗 Related
Ready for review! 🚀
PR Type
Enhancement
Description
Add comprehensive Jupyter notebook for Thai recipe RAG agent
Demonstrate PraisonAI agent with web search capabilities
Include interactive cooking assistant with PDF knowledge base
Provide step-by-step tutorial with error handling
Diagram Walkthrough
File Walkthrough
PraisonAI_RecipeAgent.ipynb
Thai Recipe RAG Agent Jupyter Notebook
examples/cookbooks/rag_examples/agentic_rag/PraisonAI_RecipeAgent.ipynb
Summary by CodeRabbit