Skip to content

Commit 8e95391

Browse files
authored
Merge pull request #219 from AgentOps-AI/fix-agentql
migrate agentql to new tool format
2 parents 5e72bfd + 413aec1 commit 8e95391

File tree

15 files changed

+123
-6925
lines changed

15 files changed

+123
-6925
lines changed
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import os
2+
import httpx
3+
4+
from typing import Optional
5+
6+
QUERY_DATA_ENDPOINT = "https://api.agentql.com/v1/query-data"
7+
API_TIMEOUT_SECONDS = 900
8+
9+
API_KEY = os.getenv("AGENTQL_API_KEY")
10+
11+
def query_data(url: str, query: Optional[str], prompt: Optional[str]) -> dict:
12+
"""
13+
url: url of website to scrape
14+
query: described below
15+
prompt: Natural language description of the data you want to scrape
16+
17+
18+
AgentQL query to scrape the url.
19+
20+
Here is a guide on AgentQL query syntax:
21+
22+
Enclose all AgentQL query terms within curly braces `{}`. The following query structure isn't valid because the term "social\_media\_links" is wrongly enclosed within parenthesis `()`.
23+
24+
```
25+
( # Should be {
26+
social_media_links(The icons that lead to Facebook, Snapchat, etc.)[]
27+
) # Should be }
28+
```
29+
30+
The following query is also invalid since its missing the curly braces `{}`
31+
32+
```
33+
# should include {
34+
social_media_links(The icons that lead to Facebook, Snapchat, etc.)[]
35+
# should include }
36+
```
37+
38+
You can't include new lines in your semantic context. The following query structure isn't valid because the semantic context isn't contained within one line.
39+
40+
```
41+
{
42+
social_media_links(The icons that lead
43+
to Facebook, Snapchat, etc.)[]
44+
}
45+
```
46+
"""
47+
payload = {
48+
"url": url,
49+
"query": query,
50+
"prompt": prompt
51+
}
52+
53+
headers = {
54+
"X-API-Key": f"{API_KEY}",
55+
"Content-Type": "application/json"
56+
}
57+
58+
try:
59+
response = httpx.post(
60+
QUERY_DATA_ENDPOINT,
61+
headers=headers,
62+
json=payload,
63+
timeout=API_TIMEOUT_SECONDS
64+
)
65+
response.raise_for_status()
66+
67+
except httpx.HTTPStatusError as e:
68+
response = e.response
69+
if response.status_code in [401, 403]:
70+
raise ValueError("Please, provide a valid API Key. You can create one at https://dev.agentql.com.") from e
71+
else:
72+
try:
73+
error_json = response.json()
74+
msg = error_json["error_info"] if "error_info" in error_json else error_json["detail"]
75+
except (ValueError, TypeError):
76+
msg = f"HTTP {e}."
77+
raise ValueError(msg) from e
78+
else:
79+
json = response.json()
80+
return json["data"]

agentstack/templates/crewai/tools/agentql_tool.py

Lines changed: 0 additions & 113 deletions
This file was deleted.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
AGENTOPS_API_KEY=...
2-
OPENAI_API_KEY=...
1+
#AGENTOPS_API_KEY=...
2+
#OPENAI_API_KEY=...
33

4-
# Tools
5-
AGENTQL_API_KEY=...
4+
# Tools

examples/sentiment_analyser/LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
MIT License
33

4-
Copyright (c) 2024 Name <Email>
4+
Copyright (c) 2025 Name <Email>
55

66
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
77

examples/sentiment_analyser/README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# sentiment_analyser
2-
New agentstack project
3-
4-
~~ Built with AgentStack ~~
2+
This is the start of your AgentStack project.
53

64
## How to build your Crew
75
### With the CLI
@@ -15,13 +13,13 @@ This will automatically create a new agent in the `agents.yaml` config as well a
1513

1614
Similarly, tasks can be created with `agentstack g t <tool_name>`
1715

18-
Add tools with `agentstack tools add <tool_name>` and view tools available with `agentstack tools list`
16+
Add tools with `agentstack tools add` and view tools available with `agentstack tools list`
1917

2018
## How to use your Crew
2119
In this directory, run `poetry install`
2220

2321
To run your project, use the following command:
24-
`crewai run` or `python src/main.py`
22+
`agentstack run`
2523

2624
This will initialize your crew of AI agents and begin task execution as defined in your configuration in the main.py file.
2725

@@ -36,3 +34,4 @@ If you need to reset the memory of your crew before running it again, you can do
3634
`crewai reset-memory`
3735
This will clear the crew's memory, allowing for a fresh start.
3836

37+
> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack)
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"framework": "crewai",
33
"tools": [
4-
"agentql"
4+
"file_read"
55
],
6-
"default_model": "openai/gpt-4o",
7-
"agentstack_version": "0.2.2.1",
6+
"agentstack_version": "0.2.5.1",
87
"template": "none",
98
"template_version": "0"
109
}

0 commit comments

Comments
 (0)