Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions agentstack/_tools/agentql/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
import httpx

from typing import Optional

QUERY_DATA_ENDPOINT = "https://api.agentql.com/v1/query-data"
API_TIMEOUT_SECONDS = 900

API_KEY = os.getenv("AGENTQL_API_KEY")

def query_data(url: str, query: Optional[str], prompt: Optional[str]) -> dict:
"""
url: url of website to scrape
query: described below
prompt: Natural language description of the data you want to scrape


AgentQL query to scrape the url.

Here is a guide on AgentQL query syntax:

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 `()`.

```
( # Should be {
social_media_links(The icons that lead to Facebook, Snapchat, etc.)[]
) # Should be }
```

The following query is also invalid since its missing the curly braces `{}`

```
# should include {
social_media_links(The icons that lead to Facebook, Snapchat, etc.)[]
# should include }
```

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.

```
{
social_media_links(The icons that lead
to Facebook, Snapchat, etc.)[]
}
```
"""
payload = {
"url": url,
"query": query,
"prompt": prompt
}

headers = {
"X-API-Key": f"{API_KEY}",
"Content-Type": "application/json"
}

try:
response = httpx.post(
QUERY_DATA_ENDPOINT,
headers=headers,
json=payload,
timeout=API_TIMEOUT_SECONDS
)
response.raise_for_status()

except httpx.HTTPStatusError as e:
response = e.response
if response.status_code in [401, 403]:
raise ValueError("Please, provide a valid API Key. You can create one at https://dev.agentql.com.") from e
else:
try:
error_json = response.json()
msg = error_json["error_info"] if "error_info" in error_json else error_json["detail"]
except (ValueError, TypeError):
msg = f"HTTP {e}."
raise ValueError(msg) from e
else:
json = response.json()
return json["data"]
File renamed without changes.
113 changes: 0 additions & 113 deletions agentstack/templates/crewai/tools/agentql_tool.py

This file was deleted.

7 changes: 3 additions & 4 deletions examples/sentiment_analyser/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
AGENTOPS_API_KEY=...
OPENAI_API_KEY=...
#AGENTOPS_API_KEY=...
#OPENAI_API_KEY=...

# Tools
AGENTQL_API_KEY=...
# Tools
2 changes: 1 addition & 1 deletion examples/sentiment_analyser/LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

MIT License

Copyright (c) 2024 Name <Email>
Copyright (c) 2025 Name <Email>

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:

Expand Down
9 changes: 4 additions & 5 deletions examples/sentiment_analyser/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# sentiment_analyser
New agentstack project

~~ Built with AgentStack ~~
This is the start of your AgentStack project.

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

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

Add tools with `agentstack tools add <tool_name>` and view tools available with `agentstack tools list`
Add tools with `agentstack tools add` and view tools available with `agentstack tools list`

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

To run your project, use the following command:
`crewai run` or `python src/main.py`
`agentstack run`

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

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

> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack)
5 changes: 2 additions & 3 deletions examples/sentiment_analyser/agentstack.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"framework": "crewai",
"tools": [
"agentql"
"file_read"
],
"default_model": "openai/gpt-4o",
"agentstack_version": "0.2.2.1",
"agentstack_version": "0.2.5.1",
"template": "none",
"template_version": "0"
}
Loading