Skip to content

Commit

Permalink
Upload project snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
whimo committed Apr 17, 2024
0 parents commit b0f2804
Show file tree
Hide file tree
Showing 49 changed files with 5,319 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length=88
88 changes: 88 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Editors
.vscode/
.idea/

# Vagrant
.vagrant/

# Mac/OSX
.DS_Store

# Windows
Thumbs.db

# 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/
*.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
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# IPython
profile_default/
ipython_config.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
.python-version

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
*.pyc

scripts/
31 changes: 31 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the OS, Python version and other tools you might need
build:
os: ubuntu-22.04
tools:
python: "3.12"
# You can also specify other tool versions:
# nodejs: "19"
# rust: "1.64"
# golang: "1.19"

# Build documentation in the "docs/" directory with Sphinx
sphinx:
configuration: docs/conf.py

# Optionally build your docs in additional formats such as PDF and ePub
# formats:
# - pdf
# - epub

# Optional but recommended, declare the Python requirements required
# to build your documentation
# See https://docs.readthedocs.io/en/stable/guides/reproducible-builds.html
# python:
# install:
# - requirements: docs/requirements.txt
18 changes: 18 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.PHONY: all
all: clean cov build

.PHONY: clean
clean:
rm -rf dist/

.PHONY: test
test:
poetry run pytest

.PHONY: cov
cov:
poetry run pytest --cov --cov-report=term-missing

.PHONY: build
build:
poetry build
84 changes: 84 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# motleycrew
A lightweight agent interaction framework.

Minimal example with maximum automation (might take a while to build ;) ):

```python
from motleycrew import Task, MotleyCrew

task = Task("""Research arxiv on the latest trends in machine learning
and produce an engaging blog post on the topic""",
documents=["paper1.pdf", "paper2.pdf"])
crew = MotleyCrew(tasks=[task])
crew.run()
```
Come to think of it, might it make sense to make it 2 libraries, one with the interaction
primitives, and the other on top of it with the automation?

Here the MotleyCrew auto-spawns agents to complete the task, and picks additional tools for them.

Short term, more crewAI-style (here some is copy-pasted from crewAI,
will need to edit before going public)
```python
from langchain import hub
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent

from motley_crew import Task, MotleyCrew
from motley_crew.agents import LangchainAgent, MotleyAgent

tools=[DuckDuckGoSearchRun()]
researcher_prompt = hub.pull("hwchase17/openai-tools-agent")
llm = ChatOpenAI(model="gpt-4-0125-preview", temperature=0)

researcher_agent = AgentExecutor(
agent=create_openai_tools_agent(llm, tools, researcher_prompt),
tools=tools,
verbose=True,
)

researcher = LangchainAgent(
agent=researcher_agent,
goal="Research the web and any documents they are given, and summarize the results",
allow_delegation=False
)

writer = MotleyAgent(
goal="Craft compelling content on tech advancements",
description="""You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives.""",
verbose=True,
kind = "crewai",
delegation=True,
)

# Create tasks for your agents
task1 = Task(
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher,
documents = ["paper1.pdf", "paper2.pdf"],
)

task2 = Task(
description="""Using the insights provided, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn't sound like AI.
Your final answer MUST be the full blog post of at least 4 paragraphs.
""",
agent=writer,
depends_on=task1,
)

# Instantiate your crew with a sequential process
crew = MotleyCrew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2, # You can set it to 1 or 2 to different logging levels
)

# Get your crew to work!
result = crew.run()
72 changes: 72 additions & 0 deletions examples/delegation_crewai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from dotenv import load_dotenv
from langchain_community.tools import DuckDuckGoSearchRun

from motleycrew import MotleyCrew, Task
from motleycrew.agent.crewai import CrewAIMotleyAgent

load_dotenv()

search_tool = DuckDuckGoSearchRun()

researcher = CrewAIMotleyAgent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI and data science",
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
verbose=True,
delegation=False,
tools=[search_tool],
)

writer = CrewAIMotleyAgent(
role="Tech Content Strategist",
goal="Craft compelling content on tech advancements",
backstory="""You are a renowned Content Strategist, known for your insightful and engaging articles.
You transform complex concepts into compelling narratives.""",
verbose=True,
delegation=True,
)

# Create tasks for your agents
crew = MotleyCrew()
task1 = Task(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher,
documents=["paper1.pdf", "paper2.pdf"], # will be ignored for now
)

task2 = Task(
crew=crew,
name="provide a literature summary of recent papers on AI",
description="""Conduct a comprehensive literature review of the latest advancements in AI in 2024.
Identify key papers, researchers, and companies in the space.
Your final answer MUST be a full literature review with citations""",
agent=researcher,
)


task3 = Task(
crew=crew,
name="produce blog post on AI advancements",
description="""Using the insights provided by a thorough web search, develop an engaging blog
post that highlights the most significant AI advancements.
Your post should be informative yet accessible, catering to a tech-savvy audience.
Make it sound cool, avoid complex words so it doesn't sound like AI.
Create a blog post of at least 4 paragraphs.""",
agent=writer,
)

[task1, task2] >> task3

# Get your crew to work!
result = crew.run(
agents=[researcher, writer],
verbose=2, # You can set it to 1 or 2 to different logging levels
)

print(list(result._done)[0].outputs)
53 changes: 53 additions & 0 deletions examples/math_crewai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from dotenv import load_dotenv

from motleycrew import MotleyCrew, Task
from motleycrew.agent.crewai import CrewAIMotleyAgent
from motleycrew.tool.python_repl import create_repl_tool

load_dotenv()

repl_tool = create_repl_tool()

# Define your agents with roles and goals
solver1 = CrewAIMotleyAgent(
role="High School Math Teacher",
goal="Generate great solutions to math problems",
backstory="""You are a high school math teacher with a passion for problem-solving.
To solve a math problem, you first reason about it, step by step, then generate the code to solve it exactly,
using sympy, then use the REPL tool to evaluate that code, and then
use the output to generate a human-readable solution.""",
verbose=True,
delegation=False,
tools=[repl_tool],
)

solver = solver1

problems = [
"Problem: If $725x + 727y = 1500$ and $729x+ 731y = 1508$, what are the values of $x$, $y$, and $x - y$ ?",
"Drei Personen erhalten zusammen Fr. 2450. Die erste Person erh\u00e4lt Fr. 70 mehr als die zweite, aber Fr. 60 weniger als die dritte.\nWie viel erh\u00e4lt jede Person? ",
"Find all numbers $a$ for which the graph of $y=x^2+a$ and the graph of $y=ax$ intersect. Express your answer in interval notation.",
]

# Create tasks for your agents
crew = MotleyCrew()
task1 = Task(
crew=crew,
name="solve math problem",
description=f"""Create a nice human-readable solution to the following problem:
{problems[1]}
IN THE SAME LANGUAGE AS THE PROBLEM""",
agent=solver,
)


# Instantiate your crew with a sequential process
result = crew.run(
agents=[solver],
verbose=True, # You can set it to 1 or 2 to different logging levels
)

# Get your crew to work!
print(list(result._done)[0].outputs)

print("######################")
44 changes: 44 additions & 0 deletions examples/single_crewai.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from dotenv import load_dotenv
from langchain_community.tools import DuckDuckGoSearchRun

from motleycrew import MotleyCrew, Task
from motleycrew.agent.crewai import CrewAIMotleyAgent

load_dotenv()

search_tool = DuckDuckGoSearchRun()

researcher = CrewAIMotleyAgent(
role="Senior Research Analyst",
goal="Uncover cutting-edge developments in AI and data science",
backstory="""You work at a leading tech think tank.
Your expertise lies in identifying emerging trends.
You have a knack for dissecting complex data and presenting actionable insights.""",
verbose=True,
delegation=False,
tools=[search_tool],
)


# Create tasks for your agents
crew = MotleyCrew()
task1 = Task(
crew=crew,
name="produce comprehensive analysis report on AI advancements",
description="""Conduct a comprehensive analysis of the latest advancements in AI in 2024.
Identify key trends, breakthrough technologies, and potential industry impacts.
Your final answer MUST be a full analysis report""",
agent=researcher,
documents=["paper1.pdf", "paper2.pdf"],
)

# Instantiate your crew with a sequential process
result = crew.run(
agents=[researcher],
verbose=2, # You can set it to 1 or 2 to different logging levels
)

# Get your crew to work!
print(list(result._done)[0].outputs)

print("######################")
Loading

0 comments on commit b0f2804

Please sign in to comment.