Skip to content

Commit b481072

Browse files
Add LangChain + PraisonAI agents Colab notebook
1 parent 2b619bf commit b481072

1 file changed

Lines changed: 373 additions & 0 deletions

File tree

Lines changed: 373 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,373 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "M_G-1ig6-__z"
7+
},
8+
"source": [
9+
"# LangChain Agent with PraisonAI\n",
10+
"This notebook demonstrates how to use LangChain-compatible tools and PraisonAI agents to research AI-related topics using Wikipedia and YouTube.\n",
11+
"\n",
12+
"---"
13+
],
14+
"id": "M_G-1ig6-__z"
15+
},
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {
19+
"id": "ZVBvL3zK-__3"
20+
},
21+
"source": [
22+
"## Dependencies"
23+
],
24+
"id": "ZVBvL3zK-__3"
25+
},
26+
{
27+
"cell_type": "code",
28+
"execution_count": null,
29+
"metadata": {
30+
"id": "d7aUlkgM-__5"
31+
},
32+
"outputs": [],
33+
"source": [
34+
"!pip install praisonaiagents langchain-community wikipedia youtube-search"
35+
],
36+
"id": "d7aUlkgM-__5"
37+
},
38+
{
39+
"cell_type": "markdown",
40+
"metadata": {
41+
"id": "sHNzy00Q-__6"
42+
},
43+
"source": [
44+
"## Set API Keys"
45+
],
46+
"id": "sHNzy00Q-__6"
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {
52+
"id": "xCQvYxjK-__6"
53+
},
54+
"outputs": [],
55+
"source": [
56+
"import os\n",
57+
"os.environ['OPENAI_API_KEY'] = 'your_api_key_here'"
58+
],
59+
"id": "xCQvYxjK-__6"
60+
},
61+
{
62+
"cell_type": "markdown",
63+
"metadata": {
64+
"id": "1CDN1gXJ-__7"
65+
},
66+
"source": [
67+
"## Tools and Agents Setup"
68+
],
69+
"id": "1CDN1gXJ-__7"
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": null,
74+
"metadata": {
75+
"id": "pj6Djfhd-__7"
76+
},
77+
"outputs": [],
78+
"source": [
79+
"from praisonaiagents import Agent, Task, PraisonAIAgents\n",
80+
"from langchain_community.utilities import WikipediaAPIWrapper\n",
81+
"from langchain_community.tools import YouTubeSearchTool\n",
82+
"\n",
83+
"wiki_agent = Agent(\n",
84+
" name=\"WikiAgent\",\n",
85+
" role=\"Research Assistant\",\n",
86+
" goal=\"Search Wikipedia for accurate information\",\n",
87+
" backstory=\"I am an AI assistant specialized in Wikipedia research\",\n",
88+
" tools=[WikipediaAPIWrapper],\n",
89+
" self_reflect=False\n",
90+
")\n",
91+
"\n",
92+
"youtube_agent = Agent(\n",
93+
" name=\"SearchAgent\",\n",
94+
" role=\"Research Assistant\",\n",
95+
" goal=\"Search for information from YouTube\",\n",
96+
" backstory=\"I am an AI assistant that can search YouTube for relevant videos.\",\n",
97+
" tools=[YouTubeSearchTool],\n",
98+
" self_reflect=False\n",
99+
")"
100+
],
101+
"id": "pj6Djfhd-__7"
102+
},
103+
{
104+
"cell_type": "markdown",
105+
"metadata": {
106+
"id": "X5YJSOPO-__8"
107+
},
108+
"source": [
109+
"## Prompt and Tasks"
110+
],
111+
"id": "X5YJSOPO-__8"
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": null,
116+
"metadata": {
117+
"id": "dC2fi8ZF-__9"
118+
},
119+
"outputs": [],
120+
"source": [
121+
"task1 = Task(\n",
122+
" name=\"wiki_task\",\n",
123+
" description=\"Research 'Artificial Intelligence' on Wikipedia\",\n",
124+
" expected_output=\"Comprehensive information from Wikipedia articles\",\n",
125+
" agent=wiki_agent\n",
126+
")\n",
127+
"\n",
128+
"task2 = Task(\n",
129+
" name=\"search_task\",\n",
130+
" description=\"Search for information about 'AI advancements' on YouTube\",\n",
131+
" expected_output=\"Relevant information from YouTube videos\",\n",
132+
" agent=youtube_agent\n",
133+
")"
134+
],
135+
"id": "dC2fi8ZF-__9"
136+
},
137+
{
138+
"cell_type": "markdown",
139+
"metadata": {
140+
"id": "YMFbVVTF-__-"
141+
},
142+
"source": [
143+
"## Main Agent Execution"
144+
],
145+
"id": "YMFbVVTF-__-"
146+
},
147+
{
148+
"cell_type": "code",
149+
"execution_count": null,
150+
"metadata": {
151+
"id": "80jMkenz-__-"
152+
},
153+
"outputs": [],
154+
"source": [
155+
"agents = PraisonAIAgents(\n",
156+
" agents=[wiki_agent, youtube_agent],\n",
157+
" tasks=[task1, task2],\n",
158+
" verbose=True\n",
159+
")\n",
160+
"agents.start()"
161+
],
162+
"id": "80jMkenz-__-"
163+
},
164+
{
165+
"cell_type": "markdown",
166+
"metadata": {
167+
"id": "O13iiPNE-__-"
168+
},
169+
"source": [
170+
"# LangChain Agent Outputs"
171+
],
172+
"id": "O13iiPNE-__-"
173+
},
174+
{
175+
"cell_type": "markdown",
176+
"metadata": {
177+
"id": "6bL4CxKD-___"
178+
},
179+
"source": [
180+
"## 1. Wikipedia Agent Output\n",
181+
"\n",
182+
"### Artificial Intelligence (AI)\n",
183+
"\n",
184+
"Artificial intelligence (AI) refers to the capability of computational systems to perform tasks typically associated with human intelligence, such as learning, reasoning, problem-solving, perception, and decision-making. It is a field of research in computer science focused on developing methods and software that enable machines to perceive their environment and use learning and intelligence to take actions that maximize their chances of achieving defined goals.\n",
185+
"\n",
186+
"**Applications of AI:**\n",
187+
"- Advanced web search engines (e.g., Google Search)\n",
188+
"- Recommendation systems (e.g., YouTube, Amazon, Netflix)\n",
189+
"- Virtual assistants (e.g., Google Assistant, Siri, Alexa)\n",
190+
"- Autonomous vehicles (e.g., Waymo)\n",
191+
"- Generative and creative tools (e.g., ChatGPT, AI art)\n",
192+
"- Superhuman play and analysis in strategy games (e.g., chess, Go)\n",
193+
"\n",
194+
"**Subfields and Techniques:**\n",
195+
"AI research is centered around goals such as learning, reasoning, knowledge representation, planning, natural language processing, perception, and robotics support. Techniques include search and mathematical optimization, formal logic, artificial neural networks, and methods based on statistics, operations research, and economics. AI also draws from psychology, linguistics, philosophy, neuroscience, and other fields.\n",
196+
"\n",
197+
"**History and Development:**\n",
198+
"AI was founded as an academic discipline in 1956. The field has experienced cycles of optimism and disappointment, known as AI winters. Interest and funding increased significantly after 2012 with the use of graphics processing units to accelerate neural networks and the success of deep learning. The AI boom in the 2020s was marked by advanced generative AI, raising ethical concerns and discussions about regulatory policies.\n",
199+
"\n",
200+
"**Artificial General Intelligence (AGI):**\n",
201+
"AGI, or human-level intelligence AI, would match or surpass human capabilities across virtually all cognitive tasks. Some researchers believe that current large language models show early signs of AGI-level capability, while others argue that genuine AGI has not yet been achieved. AGI is distinct from artificial superintelligence (ASI), which would outperform human abilities across every domain. Unlike artificial narrow intelligence (ANI), AGI can generalize knowledge, transfer skills between domains, and solve novel problems without task-specific reprogramming.\n",
202+
"\n",
203+
"Creating AGI is a major goal for companies like OpenAI, Google DeepMind, and Meta, aiming to develop AI that can complete virtually any cognitive task as well as a human."
204+
],
205+
"id": "6bL4CxKD-___"
206+
},
207+
{
208+
"cell_type": "markdown",
209+
"metadata": {
210+
"id": "lS0gvGjK-___"
211+
},
212+
"source": [
213+
"## 2. Web Search Agent Output\n",
214+
"\n",
215+
"### Latest AI Developments\n",
216+
"\n",
217+
"New Technologies in AI: Chatbots and Virtual Assistants are personalizing user experiences by analyzing user data and behavior, recommending products, content, and services, which increases engagement and sales."
218+
],
219+
"id": "lS0gvGjK-___"
220+
},
221+
{
222+
"cell_type": "markdown",
223+
"metadata": {
224+
"id": "yJqv-2Vf-___"
225+
},
226+
"source": [
227+
"## 3. Agent Interaction Details\n",
228+
"\n",
229+
"**Wikipedia Agent Info:** \n",
230+
"👤 Agent: WikiAgent \n",
231+
"Role: Research Assistant \n",
232+
"Tools: WikipediaAPIWrapper\n",
233+
"\n",
234+
"**Web Search Agent Info:** \n",
235+
"👤 Agent: SearchAgent \n",
236+
"Role: Research Assistant \n",
237+
"Tools: YouTubeSearchTool\n",
238+
"\n",
239+
"**Performance Metrics:**\n",
240+
"- Wikipedia Agent Response Time: 15.4 seconds\n",
241+
"- Web Search Agent Response Time: 5.7 seconds"
242+
],
243+
"id": "yJqv-2Vf-___"
244+
},
245+
{
246+
"cell_type": "markdown",
247+
"metadata": {
248+
"id": "Yv5abx7e-___"
249+
},
250+
"source": [
251+
"## LangChain Tools with Wrappers"
252+
],
253+
"id": "Yv5abx7e-___"
254+
},
255+
{
256+
"cell_type": "code",
257+
"execution_count": null,
258+
"metadata": {
259+
"id": "3UywakPF-___"
260+
},
261+
"outputs": [],
262+
"source": [
263+
"!pip install langchain-community google-search-results"
264+
],
265+
"id": "3UywakPF-___"
266+
},
267+
{
268+
"cell_type": "code",
269+
"execution_count": null,
270+
"metadata": {
271+
"id": "otWS3SV0_AAA"
272+
},
273+
"outputs": [],
274+
"source": [
275+
"os.environ['SERPAPI_API_KEY'] = 'your_serpapi_key_here'"
276+
],
277+
"id": "otWS3SV0_AAA"
278+
},
279+
{
280+
"cell_type": "code",
281+
"execution_count": null,
282+
"metadata": {
283+
"id": "TE46xk8A_AAB"
284+
},
285+
"outputs": [],
286+
"source": [
287+
"from langchain_community.utilities import SerpAPIWrapper\n",
288+
"\n",
289+
"data_agent = Agent(\n",
290+
" instructions=\"Search about AI job trends in 2025\",\n",
291+
" tools=[SerpAPIWrapper]\n",
292+
")\n",
293+
"editor_agent = Agent(instructions=\"Write a blog article\")\n",
294+
"\n",
295+
"agents = PraisonAIAgents(agents=[data_agent, editor_agent])\n",
296+
"agents.start()"
297+
],
298+
"id": "TE46xk8A_AAB"
299+
},
300+
{
301+
"cell_type": "markdown",
302+
"metadata": {
303+
"id": "2BqJBqaU_AAB"
304+
},
305+
"source": [
306+
"## Example Without Wrapper (Brave Search)"
307+
],
308+
"id": "2BqJBqaU_AAB"
309+
},
310+
{
311+
"cell_type": "code",
312+
"execution_count": null,
313+
"metadata": {
314+
"id": "MxGyDSqY_AAC"
315+
},
316+
"outputs": [],
317+
"source": [
318+
"!pip install langchain-community"
319+
],
320+
"id": "MxGyDSqY_AAC"
321+
},
322+
{
323+
"cell_type": "code",
324+
"execution_count": null,
325+
"metadata": {
326+
"id": "ZoD_erO__AAC"
327+
},
328+
"outputs": [],
329+
"source": [
330+
"os.environ['BRAVE_SEARCH_API'] = 'your_brave_api_key_here'"
331+
],
332+
"id": "ZoD_erO__AAC"
333+
},
334+
{
335+
"cell_type": "code",
336+
"execution_count": null,
337+
"metadata": {
338+
"id": "-TQfJWzw_AAC"
339+
},
340+
"outputs": [],
341+
"source": [
342+
"from langchain_community.tools import BraveSearch\n",
343+
"\n",
344+
"def search_brave(query: str):\n",
345+
" api_key = os.environ['BRAVE_SEARCH_API']\n",
346+
" tool = BraveSearch.from_api_key(api_key=api_key, search_kwargs={\"count\": 3})\n",
347+
" return tool.run(query)\n",
348+
"\n",
349+
"data_agent = Agent(instructions=\"Search about AI job trends in 2025\", tools=[search_brave])\n",
350+
"editor_agent = Agent(instructions=\"Write a blog article\")\n",
351+
"\n",
352+
"agents = PraisonAIAgents(agents=[data_agent, editor_agent])\n",
353+
"agents.start()"
354+
],
355+
"id": "-TQfJWzw_AAC"
356+
}
357+
],
358+
"metadata": {
359+
"kernelspec": {
360+
"display_name": "Python 3",
361+
"language": "python",
362+
"name": "python3"
363+
},
364+
"language_info": {
365+
"name": "python"
366+
},
367+
"colab": {
368+
"provenance": []
369+
}
370+
},
371+
"nbformat": 4,
372+
"nbformat_minor": 5
373+
}

0 commit comments

Comments
 (0)