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

Check warning on line 2 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L1-L2

Added lines #L1 - L2 were not covered by tests

from typing import Optional

Check warning on line 4 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L4

Added line #L4 was not covered by tests

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

Check warning on line 7 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L6-L7

Added lines #L6 - L7 were not covered by tests

API_KEY = os.getenv("AGENTQL_API_KEY")

Check warning on line 9 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L9

Added line #L9 was not covered by tests

def query_data(url: str, query: Optional[str], prompt: Optional[str]) -> dict:

Check warning on line 11 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L11

Added line #L11 was not covered by tests
"""
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 = {

Check warning on line 47 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L47

Added line #L47 was not covered by tests
"url": url,
"query": query,
"prompt": prompt
}

headers = {

Check warning on line 53 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L53

Added line #L53 was not covered by tests
"X-API-Key": f"{API_KEY}",
"Content-Type": "application/json"
}

try:
response = httpx.post(

Check warning on line 59 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L58-L59

Added lines #L58 - L59 were not covered by tests
QUERY_DATA_ENDPOINT,
headers=headers,
json=payload,
timeout=API_TIMEOUT_SECONDS
)
response.raise_for_status()

Check warning on line 65 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L65

Added line #L65 was not covered by tests

except httpx.HTTPStatusError as e:
response = e.response

Check warning on line 68 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L67-L68

Added lines #L67 - L68 were not covered by tests
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

Check warning on line 70 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L70

Added line #L70 was not covered by tests
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

Check warning on line 77 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L72-L77

Added lines #L72 - L77 were not covered by tests
else:
json = response.json()
return json["data"]

Check warning on line 80 in agentstack/_tools/agentql/__init__.py

View check run for this annotation

Codecov / codecov/patch

agentstack/_tools/agentql/__init__.py#L79-L80

Added lines #L79 - L80 were not covered by tests
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
Loading