From 9989edb6711c608854cd2b752244e8605661d6a4 Mon Sep 17 00:00:00 2001 From: Desiree Sng Date: Thu, 6 Mar 2025 16:59:56 -0800 Subject: [PATCH 1/3] Add market monitoring example --- examples/market_monitoring/.env.example | 5 + examples/market_monitoring/.gitignore | 166 ++++++++++++++++++ examples/market_monitoring/LICENSE.md | 10 ++ examples/market_monitoring/README.md | 46 +++++ examples/market_monitoring/agentstack.json | 11 ++ examples/market_monitoring/pyproject.toml | 13 ++ examples/market_monitoring/src/__init__.py | 0 .../market_monitoring/src/config/agents.yaml | 16 ++ .../market_monitoring/src/config/inputs.yaml | 1 + .../market_monitoring/src/config/tasks.yaml | 16 ++ examples/market_monitoring/src/crew.py | 48 +++++ examples/market_monitoring/src/main.py | 57 ++++++ .../market_monitoring/src/tools/__init__.py | 2 + 13 files changed, 391 insertions(+) create mode 100644 examples/market_monitoring/.env.example create mode 100644 examples/market_monitoring/.gitignore create mode 100644 examples/market_monitoring/LICENSE.md create mode 100644 examples/market_monitoring/README.md create mode 100644 examples/market_monitoring/agentstack.json create mode 100644 examples/market_monitoring/pyproject.toml create mode 100644 examples/market_monitoring/src/__init__.py create mode 100644 examples/market_monitoring/src/config/agents.yaml create mode 100644 examples/market_monitoring/src/config/inputs.yaml create mode 100644 examples/market_monitoring/src/config/tasks.yaml create mode 100644 examples/market_monitoring/src/crew.py create mode 100644 examples/market_monitoring/src/main.py create mode 100644 examples/market_monitoring/src/tools/__init__.py diff --git a/examples/market_monitoring/.env.example b/examples/market_monitoring/.env.example new file mode 100644 index 00000000..24234ffb --- /dev/null +++ b/examples/market_monitoring/.env.example @@ -0,0 +1,5 @@ +#AGENTOPS_API_KEY=... +#OPENAI_API_KEY=... + +# Tools +AGENTQL_API_KEY=... \ No newline at end of file diff --git a/examples/market_monitoring/.gitignore b/examples/market_monitoring/.gitignore new file mode 100644 index 00000000..7105da50 --- /dev/null +++ b/examples/market_monitoring/.gitignore @@ -0,0 +1,166 @@ +# 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/ +agentstack.log +.agentstack* \ No newline at end of file diff --git a/examples/market_monitoring/LICENSE.md b/examples/market_monitoring/LICENSE.md new file mode 100644 index 00000000..41752f3b --- /dev/null +++ b/examples/market_monitoring/LICENSE.md @@ -0,0 +1,10 @@ + +MIT License + +Copyright (c) 2025 Name + +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. \ No newline at end of file diff --git a/examples/market_monitoring/README.md b/examples/market_monitoring/README.md new file mode 100644 index 00000000..0366544e --- /dev/null +++ b/examples/market_monitoring/README.md @@ -0,0 +1,46 @@ +# market_monitoring + +Tracks competitor websites for pricing and product updates. + +## How to Build this Project + +### With the CLI + +```bash +agentstack init market_monitoring + +agentstack generate agent web_scraper +agentstack generate task scrape_site + +agentstack generate agent market_reporter +agentstack generate task report + +agentstack tools add agentql +``` + +Add more agents with `agentstack agent ` and more tasks with `agentstack task ` + +Add tools with `agentstack tools add ` and view tools available with `agentstack tools list` + +## How to use your Agent + +In this directory, run `uv pip install --requirements pyproject.toml` + +To run your project, use the following command: +`agentstack run` + +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 ` +Replace 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. + +> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack) diff --git a/examples/market_monitoring/agentstack.json b/examples/market_monitoring/agentstack.json new file mode 100644 index 00000000..cef7dc11 --- /dev/null +++ b/examples/market_monitoring/agentstack.json @@ -0,0 +1,11 @@ +{ + "framework": "crewai", + "tools": [ + "agentql" + ], + "default_model": "openai/gpt-4o", + "agentstack_version": "0.3.5", + "template": "market_monitoring", + "template_version": "4", + "use_git": false +} \ No newline at end of file diff --git a/examples/market_monitoring/pyproject.toml b/examples/market_monitoring/pyproject.toml new file mode 100644 index 00000000..ee38e178 --- /dev/null +++ b/examples/market_monitoring/pyproject.toml @@ -0,0 +1,13 @@ +[project] +name = "market_monitoring" +version = "0.0.1" +description = "" +authors = [ + { name = "Name " } +] +license = { text = "MIT" } +requires-python = ">=3.10" + +dependencies = [ + "agentstack[crewai]>=0.3.5", +] \ No newline at end of file diff --git a/examples/market_monitoring/src/__init__.py b/examples/market_monitoring/src/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/examples/market_monitoring/src/config/agents.yaml b/examples/market_monitoring/src/config/agents.yaml new file mode 100644 index 00000000..fec5e257 --- /dev/null +++ b/examples/market_monitoring/src/config/agents.yaml @@ -0,0 +1,16 @@ +web_scraper: + role: >- + web scraper + goal: >- + Access the website and extract all relevant information about the product in a structured format. + backstory: >- + You are an expert web scraper and data extractor. + llm: openai/gpt-4o +market_reporter: + role: >- + market monitoring reporter + goal: >- + Track competitor websites for pricing and product updates, delivering insights into the dashboard. + backstory: >- + You are an expert in reporting and tracking competitor's websites. + llm: openai/gpt-4o diff --git a/examples/market_monitoring/src/config/inputs.yaml b/examples/market_monitoring/src/config/inputs.yaml new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/examples/market_monitoring/src/config/inputs.yaml @@ -0,0 +1 @@ + diff --git a/examples/market_monitoring/src/config/tasks.yaml b/examples/market_monitoring/src/config/tasks.yaml new file mode 100644 index 00000000..19c4a87d --- /dev/null +++ b/examples/market_monitoring/src/config/tasks.yaml @@ -0,0 +1,16 @@ +scrape_site: + description: >- + Extract all the data about each electronic product from the following URL links: + https://www.amazon.com/gp/browse.html?node=541966&ref_=nav_em__pc_ce_0_2_18_4 + https://www.bestbuy.com/site/computers-pcs/laptop-computers/abcat0502000.c?id=abcat0502000 + expected_output: >- + A json file. + agent: >- + web_scraper +report: + description: >- + Compare products and their prices between the competitor websites and give a report on their performances. + expected_output: >- + A few paragraphs about the market products. + agent: >- + market_reporter diff --git a/examples/market_monitoring/src/crew.py b/examples/market_monitoring/src/crew.py new file mode 100644 index 00000000..f3abf1d1 --- /dev/null +++ b/examples/market_monitoring/src/crew.py @@ -0,0 +1,48 @@ +from crewai import Agent, Crew, Process, Task +from crewai.project import CrewBase, agent, crew, task +import agentstack + + +@CrewBase +class MarketmonitoringCrew: + """market_monitoring crew""" + + @agent + def web_scraper(self) -> Agent: + return Agent( + config=self.agents_config["web_scraper"], + tools=[ + *agentstack.tools["agentql"] + ], # add tools here or use `agentstack tools add + verbose=True, + ) + + @agent + def market_reporter(self) -> Agent: + return Agent( + config=self.agents_config["market_reporter"], + tools=[], # add tools here or use `agentstack tools add + verbose=True, + ) + + @task + def scrape_site(self) -> Task: + return Task( + config=self.tasks_config["scrape_site"], + ) + + @task + def report(self) -> Task: + return Task( + config=self.tasks_config["report"], + ) + + @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, + ) diff --git a/examples/market_monitoring/src/main.py b/examples/market_monitoring/src/main.py new file mode 100644 index 00000000..f7b05ebb --- /dev/null +++ b/examples/market_monitoring/src/main.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +import sys +from crew import MarketmonitoringCrew +import agentstack +import agentops + +agentops.init(default_tags=agentstack.get_tags()) + +instance = MarketmonitoringCrew().crew() + +def run(): + """ + Run the agent. + """ + instance.kickoff(inputs=agentstack.get_inputs()) + + +def train(): + """ + Train the crew for a given number of iterations. + """ + try: + instance.train( + n_iterations=int(sys.argv[1]), + filename=sys.argv[2], + inputs=agentstack.get_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: + instance.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. + """ + try: + instance.test( + n_iterations=int(sys.argv[1]), + openai_model_name=sys.argv[2], + inputs=agentstack.get_inputs(), + ) + except Exception as e: + raise Exception(f"An error occurred while replaying the crew: {e}") + + +if __name__ == '__main__': + run() \ No newline at end of file diff --git a/examples/market_monitoring/src/tools/__init__.py b/examples/market_monitoring/src/tools/__init__.py new file mode 100644 index 00000000..ebbad834 --- /dev/null +++ b/examples/market_monitoring/src/tools/__init__.py @@ -0,0 +1,2 @@ + +# tool import \ No newline at end of file From 4fef0f1035e84b26f44106f60e369470907b3b7a Mon Sep 17 00:00:00 2001 From: Desiree Sng Date: Thu, 6 Mar 2025 17:01:08 -0800 Subject: [PATCH 2/3] Update READMEs --- examples/research_assistant/README.md | 33 +++++++++++++++++++-------- examples/sentiment_analyser/README.md | 33 +++++++++++++++++---------- 2 files changed, 44 insertions(+), 22 deletions(-) diff --git a/examples/research_assistant/README.md b/examples/research_assistant/README.md index bd31d632..4900c858 100644 --- a/examples/research_assistant/README.md +++ b/examples/research_assistant/README.md @@ -1,21 +1,33 @@ # research_assistant +Answers research questions by retrieving knowledge from the web and extracting key insights. + +## How to Build this Project -## How to build your Crew Agent ### With the CLI -Add an agent using AgentStack with the CLI: -`agentstack generate agent ` -You can also shorten this to `agentstack g a ` -For wizard support use `agentstack g a --wizard` -Finally for creation in the CLI alone, use `agentstack g a --role/-r --goal/-g --backstory/-b --model/-m ` -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. +```bash +agentstack init research_assistant + +agentstack generate agent web_scraper +agentstack generate task scrape_site + +agentstack generate agent researcher +agentstack generate task research + +agentstack generate agent analyst +agentstack generate task analyze -Similarly, tasks can be created with `agentstack g t ` +agentstack tools add agentql +agentstack tools add firecrawl +``` -Add tools with `agentstack tools add` and view tools available with `agentstack tools list` +Add more agents with `agentstack agent ` and more tasks with `agentstack task ` + +Add tools with `agentstack tools add ` and view tools available with `agentstack tools list` ## How to use your Agent + In this directory, run `uv pip install --requirements pyproject.toml` To run your project, use the following command: @@ -30,8 +42,9 @@ CrewAI now includes a replay feature that allows you to list the tasks from the Replace 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. -> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack) \ No newline at end of file +> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack) diff --git a/examples/sentiment_analyser/README.md b/examples/sentiment_analyser/README.md index 1f41282e..4c527a82 100644 --- a/examples/sentiment_analyser/README.md +++ b/examples/sentiment_analyser/README.md @@ -1,22 +1,30 @@ # sentiment_analyser -This is the start of your AgentStack project. -## How to build your Crew +Conducts a sentimental analysis on a Reddit thread based on its comments. + +## How to Build this Project + ### With the CLI -Add an agent using AgentStack with the CLI: -`agentstack generate agent ` -You can also shorten this to `agentstack g a ` -For wizard support use `agentstack g a --wizard` -Finally for creation in the CLI alone, use `agentstack g a --role/-r --goal/-g --backstory/-b --model/-m ` -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. +```bash +agentstack init sentiment_analyser + +agentstack generate agent web_scraper +agentstack generate task scrape_data + +agentstack generate agent analyser +agentstack generate task sentiment_analysis -Similarly, tasks can be created with `agentstack g t ` +agentstack tools add agentql +``` -Add tools with `agentstack tools add` and view tools available with `agentstack tools list` +Add more agents with `agentstack agent ` and more tasks with `agentstack task ` + +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` + +In this directory, run `poetry install` To run your project, use the following command: `agentstack run` @@ -30,8 +38,9 @@ CrewAI now includes a replay feature that allows you to list the tasks from the Replace 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. -> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack) \ No newline at end of file +> 🪩 Project built with [AgentStack](https://github.com/AgentOps-AI/AgentStack) From ff8a1754917befdf5c5f9dfb20ddf7bb60bf43a4 Mon Sep 17 00:00:00 2001 From: Desiree Sng Date: Thu, 6 Mar 2025 17:17:04 -0800 Subject: [PATCH 3/3] Edit market monitoring example --- examples/market_monitoring/src/config/tasks.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/market_monitoring/src/config/tasks.yaml b/examples/market_monitoring/src/config/tasks.yaml index 19c4a87d..62f7a78e 100644 --- a/examples/market_monitoring/src/config/tasks.yaml +++ b/examples/market_monitoring/src/config/tasks.yaml @@ -1,7 +1,7 @@ scrape_site: description: >- Extract all the data about each electronic product from the following URL links: - https://www.amazon.com/gp/browse.html?node=541966&ref_=nav_em__pc_ce_0_2_18_4 + https://www.amazon.com/gp/browse.html?rw_useCurrentProtocol=1&node=565108&ref_=amb_link_BpW_pJfGS-SH8sCy2LOykw_2 https://www.bestbuy.com/site/computers-pcs/laptop-computers/abcat0502000.c?id=abcat0502000 expected_output: >- A json file.