Skip to content

Commit cbc6939

Browse files
Merge pull request #428 from asiffarhankhan/main
Add .py files for all existing .mdx tools, Add .mdx, .py for the new AgentQL tool
2 parents 1926f5c + 8d2deef commit cbc6939

15 files changed

Lines changed: 222 additions & 0 deletions
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
title: "AgentQL structured data extraction Tool"
3+
description: "Guide for using the AgentQL structured data extraction with PraisonAI agents."
4+
icon: "code"
5+
---
6+
7+
## Overview
8+
9+
AgentQL is a tool that allows you to extract structured data from webpages using AI Agents.
10+
11+
```bash
12+
pip install langchain_agentql langchain-community
13+
```
14+
15+
```bash
16+
os.environ["AGENTQL_API_KEY"] = "your_api_key_here"
17+
```
18+
19+
```python
20+
from praisonaiagents import Agent, PraisonAIAgents
21+
from langchain_agentql.tools import ExtractWebDataTool
22+
from dotenv import load_dotenv
23+
24+
import os
25+
26+
os.environ["AGENTQL_API_KEY"] = os.getenv('AGENTQL_API_KEY')
27+
28+
def extract_web_data_tool(url, query):
29+
agentql_tool = ExtractWebDataTool().invoke(
30+
{
31+
"url": url,
32+
"prompt": query,
33+
},)
34+
return agentql_tool
35+
36+
# Create agent with web extraction instructions
37+
orchestration_agent = Agent(
38+
instructions="""Extract All 37 products from the url https://www.colorbarcosmetics.com/bestsellers along with its name, overview, description, price and additional information by recursively clicking on each product""",
39+
tools=[extract_web_data_tool]
40+
)
41+
42+
# Initialize and run agents
43+
agents = PraisonAIAgents(agents=[orchestration_agent])
44+
agents.start()
45+
```
46+
47+
## Getting Started
48+
49+
1. Get your AgentQL API key from [AgentQL Dashboard](https://agentql.com)
50+
2. Set the API key in your environment variables
51+
3. Install the required dependencies
52+
4. Use the example code to start extracting structured data
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from langchain_agentql.tools import ExtractWebDataTool
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
import os
7+
8+
os.environ["AGENTQL_API_KEY"] = os.getenv('AGENTQL_API_KEY')
9+
10+
def extract_web_data_tool(url, query):
11+
agentql_tool = ExtractWebDataTool().invoke(
12+
{
13+
"url": url,
14+
"prompt": query,
15+
},)
16+
return agentql_tool
17+
18+
19+
# Create agent with web extraction instructions
20+
orchestration_agent = Agent(
21+
instructions="""Extract All 37 products from the url https://www.colorbarcosmetics.com/bestsellers along with its name, overview, description, price and additional information by recursively clicking on each product""",
22+
tools=[extract_web_data_tool]
23+
)
24+
25+
# Initialize and run agents
26+
agents = PraisonAIAgents(agents=[orchestration_agent])
27+
agents.start()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
import getpass
3+
from langchain_azure_dynamic_sessions import SessionsPythonREPLTool
4+
5+
POOL_MANAGEMENT_ENDPOINT = getpass.getpass()
6+
7+
coder_agent = Agent(instructions="""word = "strawberry"
8+
count = word.count("r")
9+
print(f"There are {count}'R's in the word 'Strawberry'")""", tools=[SessionsPythonREPLTool])
10+
11+
agents = PraisonAIAgents(agents=[coder_agent])
12+
agents.start()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from langchain_community.tools import BearlyInterpreterTool
3+
4+
coder_agent = Agent(instructions="""for i in range(0,10):
5+
print(f'The number is {i}')""", tools=[BearlyInterpreterTool])
6+
7+
agents = PraisonAIAgents(agents=[coder_agent])
8+
agents.start()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from praisonaiagents.tools import duckduckgo
3+
4+
data_agent = Agent(instructions="Search and Read Research Papers on DNA Mutation", tools=[duckduckgo])
5+
editor_agent = Agent(instructions="Write a scientifically researched outcome and findings about DNA Mutation")
6+
agents = PraisonAIAgents(agents=[data_agent, editor_agent])
7+
agents.start()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from exa_py import Exa
3+
import os
4+
5+
exa = Exa(api_key=os.environ["EXA_API_KEY"])
6+
7+
def search_and_contents(query: str):
8+
"""Search for webpages based on the query and retrieve their contents."""
9+
# This combines two API endpoints: search and contents retrieval
10+
return str(exa.search_and_contents(
11+
query, use_autoprompt=False, num_results=5, text=True, highlights=True
12+
))
13+
14+
data_agent = Agent(instructions="Find the latest jobs for Video Editor in New York at startups", tools=[search_and_contents])
15+
editor_agent = Agent(instructions="Curate the available jobs at startups and their email for the candidate to apply based on his skills on Canva, Adobe Premiere Pro, and Adobe After Effects")
16+
agents = PraisonAIAgents(agents=[data_agent, editor_agent], process='hierarchical')
17+
agents.start()
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
from langchain_google_community import GoogleSearchAPIWrapper
3+
from praisonaiagents import Agent, PraisonAIAgents
4+
5+
data_agent = Agent(instructions="Search about best places to visit in India during Summer", tools=[GoogleSearchAPIWrapper])
6+
editor_agent = Agent(instructions="Write a blog article")
7+
agents = PraisonAIAgents(agents=[data_agent, editor_agent], process='hierarchical')
8+
agents.start()
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from langchain_community.utilities import GoogleSerperAPIWrapper
3+
import os
4+
from dotenv import load_dotenv
5+
6+
load_dotenv()
7+
8+
os.environ['SERPER_API_KEY'] = os.getenv('SERPER_API_KEY')
9+
10+
search = GoogleSerperAPIWrapper()
11+
12+
data_agent = Agent(instructions="Suggest me top 5 most visited websites for Dosa Recipe", tools=[search])
13+
editor_agent = Agent(instructions="List out the websites with their url and a short description")
14+
agents = PraisonAIAgents(agents=[data_agent, editor_agent])
15+
agents.start()
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from langchain_community.tools.riza.command import ExecPython
3+
4+
coder_agent = Agent(instructions="""word = "strawberry"
5+
count = word.count("r")
6+
print(f"There are {count}'R's in the word 'Strawberry'")""", tools=[ExecPython])
7+
8+
agents = PraisonAIAgents(agents=[coder_agent])
9+
agents.start()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from praisonaiagents import Agent, PraisonAIAgents
2+
from langchain_community.tools import JinaSearch
3+
import os
4+
5+
def invoke_jina_search(query: str):
6+
JinaSearchTool = JinaSearch()
7+
model_generated_tool_call = {
8+
"args": {"query": query},
9+
"id": "1",
10+
"name": JinaSearchTool.name,
11+
"type": "tool_call",
12+
}
13+
tool_msg = JinaSearchTool.invoke(model_generated_tool_call)
14+
return(tool_msg.content[:1000])
15+
16+
data_agent = Agent(instructions="Find 10 websites where I can learn coding for free", tools=[invoke_jina_search])
17+
editor_agent = Agent(instructions="write a listicle blog ranking the best websites. The blog should contain a proper intro and conclusion")
18+
agents = PraisonAIAgents(agents=[data_agent, editor_agent], process='hierarchical')
19+
agents.start()

0 commit comments

Comments
 (0)