Skip to content

Began adding Dendrite. #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions agentstack/templates/crewai/tools/dendrite_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from crewai_tools import tool
from dendrite import Dendrite


# This is a tool that allows the agent to ask a question to the browser.
@tool
def ask(url: str, question: str):
"""
Ask a question to any page on the web. E.g "On this page, what is the current temperature?"
"""
browser = Dendrite()
browser.goto(url)
return browser.ask(url, question)
7 changes: 7 additions & 0 deletions agentstack/tools/dendrite.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "dendrite",
"packages": ["dendrite"],
"env": "DENDRITE_API_KEY=...",
"tools": ["get_farm_land"],
"cta": "!!! To install the browser locally, run `dendrite install`. Get a free API key at https://dendrite.systems/"
}
132 changes: 80 additions & 52 deletions agentstack/tools/tools.json
Original file line number Diff line number Diff line change
@@ -1,54 +1,82 @@
{
"browsing": [{
"name": "browserbase",
"url": "https://github.com/browserbase/python-sdk"
}, {
"name": "firecrawl",
"url": "https://www.firecrawl.dev/"
}],
"storage": [{
"name": "mem0",
"url": "https://github.com/mem0ai/mem0"
}],
"code-execution": [{
"name": "open_interpreter",
"url": "https://github.com/OpenInterpreter/open-interpreter"
},{
"name": "code_interpreter",
"url": "AgentStack default tool"
}],
"computer-control": [{
"name": "directory_search",
"url": "https://github.com/crewAIInc/crewAI-tools/tree/main/crewai_tools/tools/directory_search_tool"
},{
"name": "file_read",
"url": "https://github.com/crewAIInc/crewAI-tools/tree/main/crewai_tools/tools/file_read_tool"
},{
"name": "ftp",
"url": "AgentStack default tool"
}],
"network-protocols": [{
"name": "agent_connect",
"url": "https://github.com/chgaowei/AgentConnect"
}],
"unified-apis": [{
"name": "composio",
"url": "https://composio.dev/"
}],
"vision": [{
"name": "vision",
"url": "AgentStack core tool"
}],
"web-retrieval": [{
"name": "exa",
"url": "https://exa.ai"
}],
"search": [{
"name": "perplexity",
"url": "https://perplexity.ai"
}],
"application-specific": [{
"name": "stripe",
"url": "https://github.com/stripe/agent-toolkit"
}]
"browsing": [
{
"name": "browserbase",
"url": "https://github.com/browserbase/python-sdk"
},
{
"name": "dendrite",
"url": "https://dendrite.systems/"
},
{
"name": "firecrawl",
"url": "https://www.firecrawl.dev/"
}
],
"storage": [
{
"name": "mem0",
"url": "https://github.com/mem0ai/mem0"
}
],
"code-execution": [
{
"name": "open_interpreter",
"url": "https://github.com/OpenInterpreter/open-interpreter"
},
{
"name": "code_interpreter",
"url": "AgentStack default tool"
}
],
"computer-control": [
{
"name": "directory_search",
"url": "https://github.com/crewAIInc/crewAI-tools/tree/main/crewai_tools/tools/directory_search_tool"
},
{
"name": "file_read",
"url": "https://github.com/crewAIInc/crewAI-tools/tree/main/crewai_tools/tools/file_read_tool"
},
{
"name": "ftp",
"url": "AgentStack default tool"
}
],
"network-protocols": [
{
"name": "agent_connect",
"url": "https://github.com/chgaowei/AgentConnect"
}
],
"unified-apis": [
{
"name": "composio",
"url": "https://composio.dev/"
}
],
"vision": [
{
"name": "vision",
"url": "AgentStack core tool"
}
],
"web-retrieval": [
{
"name": "exa",
"url": "https://exa.ai"
}
],
"search": [
{
"name": "perplexity",
"url": "https://perplexity.ai"
}
],
"application-specific": [
{
"name": "stripe",
"url": "https://github.com/stripe/agent-toolkit"
}
]
}
6 changes: 6 additions & 0 deletions examples/farm_scout/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
AGENTOPS_API_KEY=...
OPENAI_API_KEY=...

# Tools

DENDRITE_API_KEY=...
164 changes: 164 additions & 0 deletions examples/farm_scout/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.agentops/
10 changes: 10 additions & 0 deletions examples/farm_scout/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

MIT License

Copyright (c) 2024

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:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 changes: 38 additions & 0 deletions examples/farm_scout/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# farm_scout


~~ Built with AgentStack ~~

## How to build your Crew
### With the CLI
Add an agent using AgentStack with the CLI:
`agentstack generate agent <agent_name>`
You can also shorten this to `agentstack g a <agent_name>`
For wizard support use `agentstack g a <agent_name> --wizard`
Finally for creation in the CLI alone, use `agentstack g a <agent_name> --role/-r <role> --goal/-g <goal> --backstory/-b <backstory> --model/-m <provider/model>`

This will automatically create a new agent in the `agents.yaml` config as well as in your code. Either placeholder strings will be used, or data included in the wizard.

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`

## 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`

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

#### Replay Tasks from Latest Crew Kickoff:

CrewAI now includes a replay feature that allows you to list the tasks from the last run and replay from a specific one. To use this feature, run:
`crewai replay <task_id>`
Replace <task_id> with the ID of the task you want to replay.

#### Reset Crew Memory
If you need to reset the memory of your crew before running it again, you can do so by calling the reset memory feature:
`crewai reset-memory`
This will clear the crew's memory, allowing for a fresh start.

6 changes: 6 additions & 0 deletions examples/farm_scout/agentstack.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"framework": "crewai",
"tools": [
"dendrite"
]
}
6,756 changes: 6,756 additions & 0 deletions examples/farm_scout/poetry.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions examples/farm_scout/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[tool.poetry]
name = "farm_scout"
version = "0.1.0"
description = ""
authors = [""]
license = "MIT"

[tool.poetry.dependencies]
python = ">=3.10,<=3.13"
agentops = "^0.3.12"
crewai = "^0.63.6"
crewai-tools= "0.12.1"
python-dotenv="1.0.1"
dendrite = "^0.2.7"

[project.scripts]
farm_scout = "farm_scout.main:run"
run_crew = "farm_scout.main:run"
train = "farm_scout.main:train"
replay = "farm_scout.main:replay"
test = "farm_scout.main:test"
Empty file.
8 changes: 8 additions & 0 deletions examples/farm_scout/src/config/agents.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
scout:
role: >-
Add your role here
goal: >-
Add your goal here
backstory: >-
Add your backstory here
llm: openai/gpt-4o-mini
7 changes: 7 additions & 0 deletions examples/farm_scout/src/config/tasks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
find_farms:
description: >-
Find farms for sale in the USA
expected_output: >-
An array of dicts containing the title, location, see_more_url, price, and acres of the farms
agent: >-
scout
36 changes: 36 additions & 0 deletions examples/farm_scout/src/crew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from crewai import Agent, Crew, Process, Task
from crewai.project import CrewBase, agent, crew, task
import tools


@CrewBase
class FarmscoutCrew:
"""farm_scout crew"""

# Agent definitions
@agent
def scout(self) -> Agent:
return Agent(
config=self.agents_config["scout"],
tools=[
tools.get_farm_land
], # add tools here or use `agentstack tools add <tool_name>
verbose=True,
)

@task
def find_farms(self) -> Task:
return Task(
config=self.tasks_config["find_farms"],
)

@crew
def crew(self) -> Crew:
"""Creates the Test crew"""
return Crew(
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=True,
# process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
)
65 changes: 65 additions & 0 deletions examples/farm_scout/src/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
import sys
from crew import FarmscoutCrew
import agentops
from dotenv import load_dotenv

load_dotenv()

agentops.init()

# This main file is intended to be a way for your to run your
# crew locally, so refrain from adding necessary logic into this file.
# Replace with inputs you want to test with, it will automatically
# interpolate any tasks and agents information


def run():
"""
Run the crew.
"""
inputs = {"topic": "AI LLMs"}
FarmscoutCrew().crew().kickoff(inputs=inputs)


def train():
"""
Train the crew for a given number of iterations.
"""
inputs = {"topic": "AI LLMs"}
try:
FarmscoutCrew().crew().train(
n_iterations=int(sys.argv[1]), filename=sys.argv[2], inputs=inputs
)

except Exception as e:
raise Exception(f"An error occurred while training the crew: {e}")


def replay():
"""
Replay the crew execution from a specific task.
"""
try:
FarmscoutCrew().crew().replay(task_id=sys.argv[1])

except Exception as e:
raise Exception(f"An error occurred while replaying the crew: {e}")


def test():
"""
Test the crew execution and returns the results.
"""
inputs = {"topic": "AI LLMs"}
try:
FarmscoutCrew().crew().test(
n_iterations=int(sys.argv[1]), openai_model_name=sys.argv[2], inputs=inputs
)

except Exception as e:
raise Exception(f"An error occurred while replaying the crew: {e}")


if __name__ == "__main__":
run()
4 changes: 4 additions & 0 deletions examples/farm_scout/src/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

# tool import

from .dendrite_tool import get_farm_land
64 changes: 64 additions & 0 deletions examples/farm_scout/src/tools/dendrite_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
from crewai_tools import tool
from dendrite import Dendrite


# This is a tool that allows the agent to ask a question to the browser.
def ask(url: str, question: str):
"""
Ask a question to any page on the web. E.g "On this page, what is the current temperature?"
"""
browser = Dendrite()
browser.goto(url)
return browser.ask(url, question)


# Obviously, this tool isn't useful for many people. (Unless you're a farmer.)
# It's just an example of how to use Dendrite to extract information from any website by using the SDK.
# Find a whole repo of examples here: https://github.com/dendrite-systems/dendrite-examples
@tool
def get_farm_land(min_price: int, max_price: int, min_acres: int, max_acres: int):
"""
Example tool that uses Dendrite to extract farm land information from land.com to help the agent decide what land to buy.
Args:
min_price: The minimum price of the land to search for
max_price: The maximum price of the land to search for
min_acres: The minimum acres of the land to search for
max_acres: The maximum acres of the land to search for
Returns:
an array of dicts like this [{'title': 'string', 'location': 'string', 'see_more_url': 'string', 'price': 'string', 'acres': 'string'}]
"""

print(min_price, max_price, min_acres, max_acres)

browser = Dendrite()
browser.goto("https://www.land.com/United-States/all-land/")

# Filter by price
browser.click("price dropdown button")
browser.fill_fields(
{
"min_price": min_price,
"max_price": max_price,
}
)
browser.press("Enter")

# Filter by acres
browser.click("acres dropdown button")
browser.fill_fields(
{
"min_acres": min_acres,
"max_acres": max_acres,
}
)
browser.press("Enter")

# Extract the results
results = browser.extract(
"Get all the results as an array of dicts like this [{'title': 'string', 'location': 'string', 'see_more_url': 'string', 'price': 'string', 'acres': 'string'}]"
)
return results


if __name__ == "__main__":
print(get_farm_land(10000, 100000, 100, 1000))
Binary file modified stack.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.