You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Start and manage crawl jobs with `CrawlStartTool`, `CrawlStatusTool`, `CrawlStopTool`, and `CrawlResumeTool`:
109
+
110
+
```python
111
+
import time
112
+
from langchain_scrapegraph.tools import CrawlStartTool, CrawlStatusTool
113
+
114
+
start_tool = CrawlStartTool()
115
+
status_tool = CrawlStatusTool()
116
+
117
+
# Start a crawl job
118
+
result = start_tool.invoke({
119
+
"url": "https://example.com",
120
+
"max_depth": 2,
121
+
"max_pages": 5,
122
+
"format": "markdown",
123
+
})
124
+
print("Crawl started:", result)
125
+
126
+
# Check status
127
+
crawl_id = result.get("id")
128
+
if crawl_id:
129
+
time.sleep(5)
130
+
status = status_tool.invoke({"crawl_id": crawl_id})
131
+
print("Crawl status:", status)
132
+
```
133
+
134
+
### Monitor Tools
135
+
136
+
Create and manage monitors (replaces scheduled jobs) with `MonitorCreateTool`, `MonitorListTool`, `MonitorGetTool`, `MonitorPauseTool`, `MonitorResumeTool`, and `MonitorDeleteTool`:
137
+
138
+
```python
139
+
from langchain_scrapegraph.tools import MonitorCreateTool, MonitorListTool
140
+
141
+
create_tool = MonitorCreateTool()
142
+
list_tool = MonitorListTool()
143
+
144
+
# Create a monitor (interval accepts cron expressions or shorthand like "1h", "30m")
145
+
result = create_tool.invoke({
146
+
"url": "https://example.com/products",
147
+
"name": "Price Monitor",
148
+
"interval": "0 9 * * *", # Daily at 9 AM
149
+
"prompt": "Extract current product prices", # optional JSON extraction
150
+
})
151
+
print("Monitor created:", result)
152
+
153
+
# List all monitors
154
+
monitors = list_tool.invoke({})
155
+
print("All monitors:", monitors)
156
+
```
157
+
158
+
### HistoryTool
159
+
160
+
Retrieve request history, optionally filtered by service with pagination:
161
+
162
+
```python
163
+
from langchain_scrapegraph.tools import HistoryTool
164
+
165
+
tool = HistoryTool()
166
+
167
+
# List the most recent requests
168
+
history = tool.invoke({})
169
+
170
+
# Filter to a specific service and page
171
+
history = tool.invoke({"service": "scrape", "page": 1, "limit": 20})
172
+
```
173
+
174
+
### GetCreditsTool
175
+
176
+
Check your remaining API credits:
177
+
178
+
```python
179
+
from langchain_scrapegraph.tools import GetCreditsTool
180
+
181
+
tool = GetCreditsTool()
182
+
credits= tool.invoke({})
183
+
```
184
+
115
185
## Example Agent
116
186
117
187
Create a research agent that can gather and analyze web data:
118
188
119
189
```python
120
-
from langchain.agents import initialize_agent, AgentType
121
-
from langchain_scrapegraph.tools import SmartScraperTool
190
+
from langchain.agents import AgentExecutor, create_openai_functions_agent
191
+
from langchain_core.messages import SystemMessage
192
+
from langchain_core.prompts import ChatPromptTemplate, MessagesPlaceholder
122
193
from langchain_openai import ChatOpenAI
194
+
from langchain_scrapegraph.tools import ExtractTool, GetCreditsTool, SearchTool
123
195
124
-
# Initialize tools
196
+
# Initialize the tools
125
197
tools = [
126
-
SmartScraperTool(),
198
+
ExtractTool(),
199
+
GetCreditsTool(),
200
+
SearchTool(),
127
201
]
128
202
129
-
# Create an agent
130
-
agent = initialize_agent(
131
-
tools=tools,
132
-
llm=ChatOpenAI(temperature=0),
133
-
agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
134
-
verbose=True
135
-
)
136
-
137
-
# Use the agent
138
-
response = agent.run("""
139
-
Visit example.com, make a summary of the content and extract the main heading and first paragraph
140
-
""")
203
+
# Create the prompt template
204
+
prompt = ChatPromptTemplate.from_messages([
205
+
SystemMessage(
206
+
content=(
207
+
"You are a helpful AI assistant that can analyze websites and extract information. "
208
+
"You have access to tools that can help you scrape and process web content. "
209
+
"Always explain what you're doing before using a tool."
0 commit comments