Code Monkey home page Code Monkey logo

crewai's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

crewai's Issues

Add support of gpt4free!

Hello, it's a feature request and a call for help also.

I cant find a place where the api call is made, so that i could replace it with my own POST request. If you could guide to this place it would help a lot.
I know its unethical, but i'm from russia and have no 'legal' access to OpenAI API anyway.
Please help, i really like the framework and want to use it with g4f library, i would totally understand if you don't want to associate with it though.

[FEATURE REQUEST] Pls. add Hugging Face inference as option

For us, who use Windows machines without decent HW / GPU, so using better local LLMs via Ollama is not a really good option, a good option would be using eg. Huggin Face's inference, so - as I see CrewAI uses Langchain - it should not be an issue, since LCh has HF integration:
https://python.langchain.com/docs/integrations/platforms/huggingface
So pls. add this option ( so we should only add our HF API key ) and testing your code would not break our OpenAI budget :)

Error running README example with version 0.1.14

Sorry if this is a dumb issue. I am just trying to play with example from getting started readme.

!pip install crewai

Requirement already satisfied: crewai in /usr/local/lib/python3.10/dist-packages (0.1.14)
Requirement already satisfied: langchain<0.0.352,>=0.0.351 in /usr/local/lib/python3.10/dist-packages (from crewai) (0.0.351)
...

from crewai import Agent, Task, Crew, Process

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
[<ipython-input-12-87dde7b0a3c0>](https://localhost:8080/#) in <cell line: 1>()
----> 1 from crewai import Agent, Task, Crew, Process

5 frames
[/usr/local/lib/python3.10/dist-packages/langchain/callbacks/__init__.py](https://localhost:8080/#) in <module>
     43     StreamingStdOutCallbackHandler,
     44 )
---> 45 from langchain_core.tracers.context import (
     46     collect_runs,
     47     tracing_enabled,

ImportError: cannot import name 'tracing_enabled' from 'langchain_core.tracers.context' (/usr/local/lib/python3.10/dist-packages/langchain_core/tracers/context.py)

---------------------------------------------------------------------------

It appears to me that this library uses langchain version 0.0.351 but in that version langchain tracing flag was renamed from tracing_enabled to tracing_v2_enabled.

Request: Ability to limit the amount of LLM API calls per minute

When using CrewAI with the Free Gemini Pro API that has a limit of 60 API calls per minute. It would be incredibly helpful to have a simple way to define the max LLM API calls that can take place per minute, so people can use free LLM API's without going over the max threshold which blocks access for an hour or more.

Much thanks in advance!

Example is incomplete

I set up your Readme example with Ollama and things seemed to work. But it was looking for a 'latest trends' tool which isn't available.

python crew.py 

Working Agent: Researcher
Starting Task: Investigate the latest AI trends ...


> Entering new AgentExecutor chain...

Thought: Do I need to use a tool? Yes
Action: Use the "Latest Trends" tool to gather information on the latest AI trends.
Action Input: NoneUse the "Latest Trends" tool to gather information on the latest AI trends. is not a valid tool, try one of [].
Thought: Do I need to use a tool? No
Final Answer: The "Latest Trends" tool is not available. You can investigate the latest AI trends by researching online, reading industry publications, and attending conferences and webinars related to AI.

> Finished chain.
Task output: The "Latest Trends" tool is not available. You can investigate the latest AI trends by researching online, reading industry publications, and attending conferences and webinars related to AI.

Working Agent: Writer
Starting Task: Write a blog post on AI advancements ...


> Entering new AgentExecutor chain...

Thought: Do I need to use a tool? Yes
Action: Use the "Latest Trends" tool to find out about the latest AI trends
Action Input: The Latest Trends toolUse the "Latest Trends" tool to find out about the latest AI trends is not a valid tool, try one of [].
Thought: Do I need to use a tool? No
Final Answer: There is no Latest Trends tool available, you can research the latest AI trends by reading industry publications, attending conferences and webinars related to AI, or using other tools such as Google Trends or social media monitoring tools.

> Finished chain.
Task output: There is no Latest Trends tool available, you can research the latest AI trends by reading industry publications, attending conferences and webinars related to AI, or using other tools such as Google Trends or social media monitoring tools.

The example doesn't talk about this so I'm not sure where to go now.

Running on Google colab with local models ?

Hi thanks for the ollama integration for local models . I was wondering if it's possible to use local models in the colab environment? The reason being not everyone has access to good processing computers . If I understand correctly ollama is just downloading a model is it not ? A notebook example would be great.

I think for creative purposes for example there are some good Mistral 7b models .

Thanks in advance .

I get an error when model is got-3.5-tubo

I keep getting Do I need to use a tool? No Invalid Format: Missing 'Action:' after 'Thought in the logs when I set the model to gap-3.5-tubo.

This error does not exist when model is set to gpt-4.

The error does not seem to affect the results and the agent finishes the job.

I am using the following agent:

researcher = Agent(
  role='Researcher',
  goal='Discover new insights about Tesla Inc. and its stock',
  backstory="You're a world class reporter and researcher who is an expert in discovering news about Tesla Inc.",
  verbose=True,
  allow_delegation=False,
  tools=[SearchTools.search_news],
  llm=OpenAI(temperature=0.7, model_name="gpt-3.5-turbo")
  # llm=OpenAI(temperature=0.7, model_name="gpt-4")
)

Not finding a useful Ollama model for stock example

Im running the stock example with open source models on Ollama. I have tried various open models (did not write my own modelfile) and it always ended up either delivering bad outputs, generating syntax errors in python or no meaningfull results at all.

Some models I have tried (directly from Ollama hub, I have tried even more, varying parametersize and precision):

  • Openhermes 2.5
  • Llama 2
  • Mixtral
  • nous-hermes2
  • even ChatGPT 3.5 (delivered a useless report at the end)
  • GPT 4 when exectuing yahoofinancenews it came up with syntax error in python keyerror 'description' any ideas?

Did anyone have success with open source models yet for the stock recommendation task? If yes what model is it, did you use a modelfile or directly pulled from ollama?

Was the Youtube example run on GPT-4? Because the results seemed quite impressive and I cant imagine a open source model (especially smaller ones) to achieve equally pleasant results.

Thanks in advance.

Two new Wiki addition suggestions. Configuring with LLM providers and Local model quality/experiences.

A feature request for the wiki

  1. A section on configuring CrewAI with different LLM providers, as well as local model providers such as LM-Studio, llama.cpp etc. So far, I have been able to get local models working with Ollama, mistral-medium on the Mistral AI platform and mistral-small with Anyscale. Nevertheless, I had to search through the Discord community to get hints to configure the later.

  2. A section on local models, which ones work, how well they work. Which models to avoid, and so forth. In my limited testing so far, it's obvious some open source models punch way above their weight. A section like this could shorten the time to develop a useful implementation and potentially hasten adoption.

Successful implementation of D & D host and player game

Decided to try an experiment that didn't need tools (since that seems to be problematic) so for our simulation we are running a d&d game.

import os
from crewai import Agent, Task, Crew, Process
from langchain.agents import AgentType, initialize_agent, load_tools
from langchain.llms import OpenAI

#os.environ["OPENAI_API_KEY"] = "Your Key"

from langchain.llms import Ollama
ollama_openhermes = Ollama(model="mistral")
# Pass Ollama Model to Agents: When creating your agents within the CrewAI framework, you can pass the Ollama model as an argument to the Agent constructor. For instance:

dm = Agent(
  role='Dungeon Master',
  goal='Host a short Dungeons and Dragons Session to do with raider goblins stealing the village food.',
  backstory="You're a world class Dungeon Master.",
#  tools=[
#    SearchTools.search_internet,
#    BrowserTools.scrape_and_summarize_website,
#  ],
  llm=ollama_openhermes, # Ollama model passed here
  verbose=False,
  allow_delegation=False
  # llm=OpenAI(temperature=0.7, model_name="gpt-4"). It uses langchain.chat_models, default is GPT4
)

ranger = Agent(
  role='ranger',
  goal='Role play your character. Be brave and lead the party to complete the quest.',
  backstory="You're a famous Level 3 Human Ranger, specialized on Hunting, Tracking, and Bowmanship.",
  llm=ollama_openhermes, # Ollama model passed here
  verbose=False,
  allow_delegation=False
)

fighter = Agent(
  role='fighter',
  goal='Role play your character and assist the party in completing the objective.',
  backstory="You're a newly recruited Level 1 Human Fighter with a shortsword.",
  llm=ollama_openhermes, # Ollama model passed here
  verbose=False,
  allow_delegation=False
)


# Create tasks for your agents
task1 = Task(description='Create a short Quest.', agent=dm)
task2 = Task(description='Explain the beginning scene of the quest. Only give details as the players unveil them.', agent=dm)

task3 = Task(description='Choose your action and the direction for the party.', agent=ranger)
task4 = Task(description='Choose your action and what you would like to do.', agent=fighter)
task5 = Task(description='Continue the quest accordingly making it unique and interesting.', agent=dm)
task6 = Task(description='If the players have successfully completed the quest, write "YOU WON".', agent=dm)

# Instantiate your crew with a sequential process
crew = Crew(
  agents=[dm, ranger, fighter],
  tasks=[task1, task2, task3, task4, task5, task6],
  verbose=True, # Crew verbose more will let you know what tasks are being worked on
  process=Process.sequential # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)

# Get your crew to work!
result = crew.kickoff()
crew.tasks.remove(task1)
crew.tasks.remove(task2)
while "YOU WON" not in result:
  result = crew.kickoff()

The characters interact with the host and each other and comes up with a pretty decent story.
This works, but there were some problems:

  1. The working agent, Starting Task and Task output are all displayed. We really only want Working agent and Task output.
  2. The hack to keep iterating seems wrong. there must be a better way.
  3. It would reference itself as AI instead of ranger or dm etc.

Pretty cool!

How can I specify to use GPT-3.5?

Running the example from the README cost 34 cents, using GPT-4.

Was wondering what the cost differential would be between GPT-3.5 and GPT-4, but I can't find where to put that in the code.

Thank you, for this tool and the support! Feliz ano novo. :)

Ollama and ReadMe Example Documentation

You are doing some very interesting work. Thanks!

A couple of issues with the ReadMe Example.

  1. ollama_openhermes = Ollama(model="agent"). "agent" is not a valid Ollama model. Did you mean openhermes here?

  2. tools=[] is not well explained.
    Running Ollama openhermes, I get a lot of errors like,
    Research current AI trends is not a valid tool, try one of []

This does not happen with an OpenAI key.

I'm guessing that when you use OpenAI, there is a "fallback tool" that takes over. It may be that with Ollama, the developer needs to create some tools. Or something else better explains the problem. That's my question.

This tripped me up when I was looking at your project, so I thought I would contribute by explaining what happened.

ollama_openhermes = Ollama(model="agent")
# Pass Ollama Model to Agents: When creating your agents within the CrewAI framework, you can pass the Ollama model as an argument to the Agent constructor. For instance:

local_expert = Agent(
  role='Local Expert at this city',
  goal='Provide the BEST insights about the selected city',
  backstory="""A knowledgeable local guide with extensive information
  about the city, it's attractions and customs""",
  tools=[
    SearchTools.search_internet,
    BrowserTools.scrape_and_summarize_website,
  ],
  llm=ollama_openhermes, # Ollama model passed here

Who's thoughts are those?

I've got code with two agents, one can delegate to the other.
I'm getting results like


> Entering new AgentExecutor chain...

Thought: Do I need to use a tool? Yes
Action: Search the internet - Trends in AI
Action Input: NoneSearch the internet - Trends in AI is not a valid tool, try one of [Search the internet].Thought: Do I need to use a tool? Yes
Action: Search the internet - Trends in AI
Action Input: NoneSearch the internet - Trends in AI is not a valid tool, try one of [Search the internet].

It would be very useful to have the Role before the thought, so like
'Writer:Thought"
or
"Researcher:Thought"

Basic example with a remote LiteLLM

Hi,

I'm trying to run the basic example using LiteLLM with ollama2 model running in a container pulling from: https://hub.docker.com/r/litellm/ollama but I don't get the to reach the LLM. It seems the request is created as http://127.0.0.1:8000/api/generate but the LLM is not reached properly and returns 404.

See more details below.

Any idea?

Thanks!

More details:

container is started with: docker run -p 8000:8000 --name ollama litellm/ollama

I ran a part of an autogen demo and the litellm container seems to work, I mean the server is reached and the llm server replies. Then autogen fails in another step, so I am trying CrewAI instead.

I am trying to run the CrewAI example as described in the README.md, these are the changes I made:


from crewai import Agent, Task, Crew, Process
from langchain.schema import HumanMessage
from langchain_community.chat_models import ChatLiteLLM
from litellm import litellm


ollama_chatlitellm = ChatLiteLLM(model="ollama/ollama2",api_base="http://127.0.0.1:8000", api_type="open_ai", api_key="")


researcher = Agent(
  role='Researcher',
  goal='Discover new insights',
  backstory="You're a world class researcher working on a major data science company",
  verbose=True,
  allow_delegation=False,
  llm=ollama_chatlitellm,
  debug_mode=True
)

#  ... the rest is the same as in the README.md


Client logs:

Working Agent: Researcher
Starting Task: Investigate the latest AI trends ...


> Entering new AgentExecutor chain...
kwargs[caching]: False; litellm.cache: None

LiteLLM completion() model= ollama2; provider = ollama

LiteLLM: Params passed to completion() {'functions': None, 'function_call': None, 'temperature': 1, 'top_p': None, 'stream': False, 'max_tokens': 256, 'presence_penalty': None, 'frequency_penalty': None, 'logit_bias': None, 'user': None, 'response_format': None, 'seed': None, 'tools': None, 'tool_choice': None, 'max_retries': None, 'logprobs': None, 'top_logprobs': None, 'custom_llm_provider': 'ollama', 'model': 'ollama2', 'n': 1, 'stop': ['\nObservation']}

LiteLLM: Non-Default params passed to completion() {'temperature': 1, 'stream': False, 'max_tokens': 256, 'n': 1, 'stop': ['\nObservation']}
self.optional_params: {'num_predict': 256, 'temperature': 1, 'stop_sequences': ['\nObservation']}
PRE-API-CALL ADDITIONAL ARGS: {'api_base': 'http://127.0.0.1:8000/api/generate', 'complete_input_dict': {'model': 'ollama2', 'prompt': "You are Researcher.\nYou're a world class researcher working on a major data science company\n\nYour personal goal is: Discover new insights\n\nTOOLS:\n------\nYou have access to the following tools:\n\n\n\nTo use a tool, please use the exact following format:\n\n```\nThought: Do I need to use a tool? Yes\nAction: the action to take, should be one of [], just the name.\nAction Input: the input to the action\nObservation: the result of the action\n```\n\nWhen you have a response for your task, or if you do not need to use a tool, you MUST use the format:\n\n```\nThought: Do I need to use a tool? No\nFinal Answer: [your response here]\n```This is the summary of your work so far:\nBegin! This is VERY important to you, your job depends on it!\n\nCurrent Task: Investigate the latest AI trends\n", 'num_predict': 256, 'temperature': 1, 'stop_sequences': ['\nObservation'], 'stream': False}, 'headers': {}, 'acompletion': False}


POST Request Sent from LiteLLM:
curl -X POST \
http://127.0.0.1:8000/api/generate \
-d '{'model': 'ollama2', 'prompt': "You are Researcher.\nYou're a world class researcher working on a major data science company\n\nYour personal goal is: Discover new insights\n\nTOOLS:\n------\nYou have access to the following tools:\n\n\n\nTo use a tool, please use the exact following format:\n\n```\nThought: Do I need to use a tool? Yes\nAction: the action to take, should be one of [], just the name.\nAction Input: the input to the action\nObservation: the result of the action\n```\n\nWhen you have a response for your task, or if you do not need to use a tool, you MUST use the format:\n\n```\nThought: Do I need to use a tool? No\nFinal Answer: [your response here]\n```This is the summary of your work so far:\nBegin! This is VERY important to you, your job depends on it!\n\nCurrent Task: Investigate the latest AI trends\n", 'num_predict': 256, 'temperature': 1, 'stop_sequences': ['\nObservation'], 'stream': False}'



Give Feedback / Get Help: https://github.com/BerriAI/litellm/issues/new
LiteLLM.Info: If you need to debug this error, use `litellm.set_verbose=True'.

Logging Details: logger_fn - None | callable(logger_fn) - False
Logging Details LiteLLM-Failure Call
self.failure_callback: []
Retrying langchain_community.chat_models.litellm.ChatLiteLLM.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised APIConnectionError: {"detail":"Not Found"}.
kwargs[caching]: False; litellm.cache: None

LiteLLM completion() model= ollama2; provider = ollama

LiteLLM: Params passed to completion() {'functions': None, 'function_call': None, 'temperature': 1, 'top_p': None, 'stream': False, 'max_tokens': 256, 'presence_penalty': None, 'frequency_penalty': None, 'logit_bias': None, 'user': None, 'response_format': None, 'seed': None, 'tools': None, 'tool_choice': None, 'max_retries': None, 'logprobs': None, 'top_logprobs': None, 'custom_llm_provider': 'ollama', 'model': 'ollama2', 'n': 1, 'stop': ['\nObservation']}

LiteLLM: Non-Default params passed to completion() {'temperature': 1, 'stream': False, 'max_tokens': 256, 'n': 1, 'stop': ['\nObservation']}
self.optional_params: {'num_predict': 256, 'temperature': 1, 'stop_sequences': ['\nObservation']}
PRE-API-CALL ADDITIONAL ARGS: {'api_base': 'http://127.0.0.1:8000/api/generate', 'complete_input_dict': {'model': 'ollama2', 'prompt': "You are Researcher.\nYou're a world class researcher working on a major data science company\n\nYour personal goal is: Discover new insights\n\nTOOLS:\n------\nYou have access to the following tools:\n\n\n\nTo use a tool, please use the exact following format:\n\n```\nThought: Do I need to use a tool? Yes\nAction: the action to take, should be one of [], just the name.\nAction Input: the input to the action\nObservation: the result of the action\n```\n\nWhen you have a response for your task, or if you do not need to use a tool, you MUST use the format:\n\n```\nThought: Do I need to use a tool? No\nFinal Answer: [your response here]\n```This is the summary of your work so far:\nBegin! This is VERY important to you, your job depends on it!\n\nCurrent Task: Investigate the latest AI trends\n", 'num_predict': 256, 'temperature': 1, 'stop_sequences': ['\nObservation'], 'stream': False}, 'headers': {}, 'acompletion': False}

Server Logs

INFO:     172.17.0.1:61256 - "POST /api/generate HTTP/1.1" 404 Not Found
INFO:     172.17.0.1:61258 - "POST /api/generate HTTP/1.1" 404 Not Found
INFO:     172.17.0.1:61260 - "POST /api/generate HTTP/1.1" 404 Not Found

...

Project Roadmap

@joaomdmoura Is there a project roadmap or anything similar ? I'd like to sync up on this so I can contribute more efficiently.

Did not find openai_api_key

Using .env file and a key named "OPENAI_API_KEY" in it ( with valid value),
I still got:

Traceback (most recent call last):
  File "D:\Projects\AI_testing\CrewAI\sample_app.py", line 5, in <module>
    researcher = Agent(
                 ^^^^^^
  File "D:\Projects\AI_testing\CrewAI\CrewAI-venv\Lib\site-packages\crewai\agent.py", line 49, in __init__
    super().__init__(**data)
  File "D:\Projects\AI_testing\CrewAI\CrewAI-venv\Lib\site-packages\pydantic\v1\main.py", line 341, in __init__
    raise validation_error
pydantic.v1.error_wrappers.ValidationError: 1 validation error for Agent
__root__ -> __root__
  Did not find openai_api_key, please add an environment variable `OPENAI_API_KEY` which contains it, or pass  `openai_api_key` as a named parameter. (type=value_error)

error.

ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'

I installed crewAI via pip on WSL and tried importing the Agents via from crewai import Agent

I am getting the below error.

/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/urllib3/init.py:34: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'GraalVM JSSE'. See: urllib3/urllib3#3020
warnings.warn(
Traceback (most recent call last):
File "", line 1, in
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/crewai/init.py", line 1, in
from crewai.agent import Agent
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/crewai/agent.py", line 3, in
from langchain.agents import AgentExecutor
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langchain/agents/init.py", line 36, in
from langchain.agents.agent import (
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langchain/agents/agent.py", line 26, in
from langchain_core.language_models import BaseLanguageModel
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langchain_core/language_models/init.py", line 8, in
from langchain_core.language_models.chat_models import BaseChatModel, SimpleChatModel
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langchain_core/language_models/chat_models.py", line 20, in
from langchain_core.callbacks import (
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langchain_core/callbacks/init.py", line 13, in
from langchain_core.callbacks.manager import (
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langchain_core/callbacks/manager.py", line 27, in
from langsmith.run_helpers import get_run_tree_context
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langsmith/init.py", line 10, in
from langsmith.client import Client
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langsmith/client.py", line 43, in
from langsmith.evaluation import evaluator as ls_evaluator
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langsmith/evaluation/init.py", line 4, in
from langsmith.evaluation.string_evaluator import StringEvaluator
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/langsmith/evaluation/string_evaluator.py", line 3, in
from pydantic import BaseModel
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/pydantic/init.py", line 372, in getattr
module = import_module(module_name, package=package)
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/pydantic/main.py", line 11, in
import pydantic_core
File "/home/chukypedro15/miniconda3/envs/rfp_env/lib/jvm/languages/python/lib/python3.10/site-packages/pydantic_core/init.py", line 6, in
from ._pydantic_core import (
ModuleNotFoundError: No module named 'pydantic_core._pydantic_core'

Sandboxed?

Hello,

AutoGPT has an option to execute code inside a Docker Container. Does CrewAI have some sort of sandbox implemented to help protect against malicious code execution?

mistral API

is there a way to use mistrals AP instead of openai

Load_tools missing in Human as a Tool

import os
from crewai import Agent, Task, Crew, Process
from langchain.tools import DuckDuckGoSearchRun

search_tool = DuckDuckGoSearchRun()

we have to add

from langchain.agents import load_tools

research example doesn't generate a final blog post.

I have been trying the example on the landing page using Ollama and TextGen-Webui's OpenAI API wrapper. I followed all the steps, but the writer doesn't write the summary at the end. The conversation ends with the steps and advice on how to write the blog post, not the actual blog post. Is there a way we can control the conversation by telling the agents that the task is not done yet? I saw in Matt Berman's video that the conversation ended with a summary of the blog post, but it doesn't work for some reason when I try it.
image

And when I read LangChain's output, I see the following errors:
Invalid Format: Missing 'Action:' after 'Thought:
image

Running CrewAI on a web app with Pyodide

Issue with Dependencies when Installing crewai with Pyodide

Description

I'm encountering an issue when trying to install the crewai package using Pyodide in a web environment. It appears that Pyodide is unable to find compatible Python wheels for several dependencies required by crewai.

Steps to Reproduce

  1. Set up a Pyodide environment in an HTML file.
  2. Attempt to install crewai using micropip.install.
  3. Encounter errors indicating missing Python wheels for specific dependencies.

Expected Behavior

I expected crewai to install successfully along with its dependencies.

Actual Behavior

The installation process failed with the following error messages, indicating missing Python wheels for these dependencies:

  • pydantic-core==2.14.6
  • aiohttp<4.0.0,>=3.8.3
  • langchain-core<0.2,>=0.1

These dependencies seem to be related to langchain, which crewai relies on.

Potential Causes

It's likely that these dependencies either:

  • Do not have pure Python wheels available that are compatible with Pyodide.
  • Require specific versions that are not yet supported in the Pyodide environment.

Code

<!doctype html>
<html>
  <head>
      <script src="https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.js"></script>
  </head>
  <body>
    <script type="text/javascript">
      async function main(){
        let pyodide = await loadPyodide();
        await pyodide.loadPackage("micropip");
        const micropip = pyodide.pyimport("micropip");
        await micropip.install("crewai", keep_going="True");
      }
      main();
    </script>
  </body>
</html>

Suggested Solutions or Workarounds

I am looking for guidance on whether there are any known workarounds or if there are alternative versions of these dependencies that are compatible with Pyodide.

OpenAI Rate Limit Error

For those with limited OpenAI access, the rate limit is hit in the "stock_analysis" example at: https://github.com/joaomdmoura/crewAI-examples?tab=readme-ov-file

*Error: *

Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for gpt-4 in organization org-XXXX on tokens_usage_based per min: Limit 10000, Used 7760, Requested 2270. Please try again in 180ms. Visit https://platform.openai.com/account/rate-limits to learn more..
Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for gpt-4 in organization org-XXXX on tokens_usage_based per min: Limit 10000, Used 8208, Requested 2276. Please try again in 2.904s. Visit https://platform.openai.com/account/rate-limits to learn more..
Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for gpt-4 in organization org-XXXX on tokens_usage_based per min: Limit 10000, Used 8137, Requested 2500. Please try again in 3.822s. Visit https://platform.openai.com/account/rate-limits to learn more..
Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for gpt-4 in organization org-XXXX on tokens_usage_based per min: Limit 10000, Used 8440, Requested 2281. Please try again in 4.326s. Visit https://platform.openai.com/account/rate-limits to learn more..

Is there a good place within crewAI to add handling for this? If so, please link to the class/function and I will give it a shot. Thanks!

AgentExecutor chain loop looks stucked

When running a tweaked version of the sample code it looks the AgentExecutor chain loop stucked, repeating itself ( in Action and Action Input ):

Entering new AgentExecutor chain...
Thought: Do I need to use a tool? Yes
Action: Delegate Work to Co-Worker
Action Input: Researcher|Compile list of IDEs|Please compile a comprehensive list of all Integrated Development Environments (IDEs) that support AI/LLM assisted programming with extensive search capabilities across project code files and console/terminal messages. Include both mainstream and lesser-known options, as well as any relevant plugins or extensions that enhance these functionalities.

repeated multiple times, so it'll break my OpenAI budget :)

The modified sample code is:

from crewai import Agent, Task, Crew, Process
from langchain.llms import OpenAI

from dotenv import load_dotenv

load_result = load_dotenv(override=True)

# Define your agents with roles and goals
researcher = Agent(
    role="Researcher",
    goal="Discover new trends, ideas, insights",
    backstory="You're a world class researcher working in a major LLM based app developer company",
    verbose=True,
    llm=OpenAI(
        temperature=0.7, model_name="gpt-4-1106-preview"
    ),  # It uses langchain.chat_models, default is GPT4
)
writer = Agent(
    role="Writer",
    goal="Create engaging content",
    backstory="You're a famous technical writer, specialized on writing AI, ML and LLM related content",
    verbose=True,
    llm=OpenAI(
        temperature=0.7, model_name="gpt-4-1106-preview"
    ),  # It uses langchain.chat_models, default is GPT4
)

# Create tasks for your agents
task1 = Task(
    description="Investigate which AI / LLM assisted programming IDE assistant can search not only the selected code or the opened file, but all the project code files, the console and terminal messages",
    agent=researcher,
)
task2 = Task(
    description="Write a short summary about the different AI assistant options found",
    agent=writer,
)

# Instantiate your crew with a sequential process
crew = Crew(
    agents=[researcher, writer],
    tasks=[task1, task2],
    verbose=True,  # Crew verbose more will let you know what tasks are being worked on
    process=Process.sequential,  # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)

# Get your crew to work!
result = crew.kickoff()

Can't connect with LM Studio (0.1.14 still defaulting to OpenAI API, 401 error)

Great project! I'm really excited to see where this goes.

I want to be able to connect with LM Studio's APIs, so I put this script together quickly

local_model_api_tool.py

`from langchain.tools import tool
from openai import OpenAI

Define the tool
@tool
def local_model_api_tool(input_content: str) -> str:
    """
    This tool interfaces with a local model API using OpenAI client.
    The input is a string, which is sent to the API, and the response is returned.
    """
    # Configure the OpenAI client to use the local server
    client = OpenAI(base_url="http://localhost:8000/v1", api_key="NULL")

    # Sending the request to the local model
    response = client.chat.completions.create(
        model="local-model",  # Model field (unused in this setup)
        messages=[
            {"role": "system", "content": "Always answer in rhymes."},
            {"role": "user", "content": input_content}
        ],
        temperature=0.7,
    )

    # Extracting the message from the response
    return response.choices[0].message
`

Then put it in as a tool for the agent:

`import os
from crewai import Agent, Task, Crew, Process
from local_model_api_tool import local_model_api_tool  # Import the custom tool

os.environ["OPENAI_API_KEY"] = "NULL"

# Define your agents with roles and goals
researcher = Agent(
    role='Researcher',
    goal='Discover new insights',
    backstory="You're a world class researcher working on a major data science company",
    verbose=True,
    allow_delegation=False,
    tools=[local_model_api_tool]  #Tool assignment`
Still getting the 401 error though:

openai.AuthenticationError: Error code: 401 - {'error': {'message': 'Incorrect API key provided: NULL. You can find your API key at https://platform.openai.com/account/api-keys.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_api_key'}}


Any ideas on how to fix this? It'd be great to be able to to test many different models through LM Studio, and even assign a specialized model to different agents. 

Thank you!

example model file for ollama openhermes2.5-mistral

would this be a correct modelfile to use for ollama openhermes2.5-mistral?

TEMPLATE """<|im_start|>system
{{ .System }}<|im_end|>
<|im_start|>user
{{ .Prompt }}<|im_end|>
<|im_start|>assistant
"""
PARAMETER num_ctx 4096
PARAMETER top_p 0.5
PARAMETER temperature 0
PARAMETER stop "<|im_start|>"
PARAMETER stop "<|im_end|>"
PARAMETER stop "Observation"

Adding human input example to README and docs

One can easily use human input as tool by using the langchain tool but would be nice to add proper docs around it as it seem a usual use case

from langchain.agents import load_tool
tools = load_tools(["human"])

Weird behavior on how the parameters are passed or processed by an Agent that uses a custom Tool

I have defined a custom tool that fetches a local API as this search_api_tool.py:

import json
from langchain.tools import tool
from dotenv import load_dotenv
import requests
import os

load_dotenv()  # This loads the environment variables from .env

@tool
def search_api_tool(input_string: str) -> dict:
    """
    Tool to fetch conversation counts from the Search API.
    Expects 'input_string' as a JSON string containing 'start_date', 'end_date', and 'symbol'.
    """
    try:
        params = json.loads(input_string)
    except json.JSONDecodeError:
        return {"error": "Invalid input format. Expected JSON string."}


    # Check for either 'keyword' or 'symbol' and use whichever is available
    symbol = params.get("symbol") or params.get("keyword")
    start_date = params.get("start_date")
    end_date = params.get("end_date")

    if not all([symbol, start_date, end_date]):
        return {"error": "Missing required parameters."}

    url = f"http://localhost:3000/api/messages?start_date={start_date}&end_date={end_date}&symbol={symbol}"
    headers = {
        'Authorization': f'Bearer {os.getenv("API_KEY")}'
    }

    try:
        response = requests.get(url, headers=headers)
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        return {"error": str(e)}

In my main.py I've defined my custom tool for the agent as:

# Create a custom tool for the agent
custom_tool = Tool(
    name="SearchAPI",
    func=search_api_tool,  # Directly use the search_api_tool
    description="Tool to fetch conversation counts from the Search API."
)

# Create an agent
market_analyst = Agent(
  role='Market Analyst',
  goal='Analyze market trends based on conversation data.',
  backstory='A skilled analyst with expertise in identifying market trends from conversation data.',
  tools=[custom_tool],
  verbose=True
)


# Function to prompt user for input
def prompt_user_for_input():
    symbol = input("What is the symbol you want to analyze? ")
    start_date = input("What is the start date? (YYYY-MM-DD) ")
    end_date = input("What is the end date? (YYYY-MM-DD) ")
    return symbol, start_date, end_date

# Get user input
symbol, start_date, end_date = prompt_user_for_input()

# Custom method for executing the task with the correct parameters
def execute_market_analysis_task(agent, tool, symbol, start_date, end_date):
    params_str = json.dumps({"symbol": symbol, "start_date": start_date, "end_date": end_date})
    return tool.run(params_str)

# Define a task for the agent with user-provided parameters
market_analysis_task = Task(
    description=f'Analyze market conversations for {symbol} between {start_date} and {end_date}.',
    agent=market_analyst,
    tools=[custom_tool],
    execute=execute_market_analysis_task(market_analyst, custom_tool, symbol, start_date, end_date)
)

I've prepared a test.py file to debug and when passing the correct JSON as input the search_api_tool function outputs the correct stuff:

import json
from search_api_tool import search_api_tool
# Test the search_api_tool directly
test_input = json.dumps({"start_date": "02/02/2021", "end_date": "15/02/2021", "symbol": "AAPL"})
test_output = search_api_tool(test_input)
print("Test output:", test_output)

outputs:

python test.py
Test output: {'2021-02-02': 15, '2021-02-03': 43, '2021-02-04': 80, '2021-02-05': 49, '2021-02-06': 35, '2021-02-07': 36, '2021-02-08': 34, '2021-02-09': 49, '2021-02-10': 43, '2021-02-11': 46, '2021-02-12': 49, '2021-02-13': 43, '2021-02-14': 28}

But when I try to execute my main.py file, on the first call, it always mismatches the parameters and does weird stuff as replacing symbol with keyword. The issue here seems to be with how the input parameters are being formatted and passed to the search_api_tool. Initially, the agent is passing the parameters as a comma-separated list (AAPL, 2020-05-19, 2020-10-18), which leads to an error since the tool expects a JSON string. The agent then self-corrects by formatting the input as a JSON string, but the keys used ("keyword", "start_date", "end_date") might not match what the search_api_tool is expecting.

What am I missing here? I just want the Agent to call the API with the simple JSON as in the test file... Thank you very much for any suggestions!

connecting to lmstudio vllm?

Hi,
would it be possible to add support for these or is it possible at the moment?
I tried combing throught the code with success.

Add list of tools to Wiki / Docs / Readme

People keep asking about tools, I usually point them to langchain tools and toolkits but I think folks would benefit from having those links close to crewAI, we should have a dedicate list linking to some of the most common ones and also link to it form the README

Access to internal files?

I've been exploring this repo as a possible alternative to Autogen, which you rightfully mentioned in your comparison as well.
One of their features I really liked was that we are able to give the agents access to our own files by putting them in the working directory and then the agents are able to modify their content, extract information from them, etc.
I was wondering if CrewAI already has a similar option available or you are planning to add something like that in future?!

How to increase agent max iteration limit

Posted this originally on the examples repo but more visibility here and others may run into same issue.

I run the web search example using an open-source model via a LMStudio server and get the following output at the end:

> Finished chain.
Task output: Agent stopped due to iteration limit or time limit.
######################
Agent stopped due to iteration limit or time limit.

I've seen the Langchain issue, but having difficulty figuring out where I pass this max_iterations argument in the CrewAI codebase.

Here's the code for reference:

import os
from crewai import Agent, Task, Crew, Process
from langchain.chat_models import ChatOpenAI as OpenAI
from langchain.tools import DuckDuckGoSearchRun

local_openai_client = OpenAI(
    base_url="http://localhost:1234/v1", api_key="not-needed", temperature=0.4
)

search_tool = DuckDuckGoSearchRun()

# Define your agents with roles and goals
researcher = Agent(
  role='Senior Research Analyst',
  goal='Uncover cutting-edge developments in AI and data science in',
  backstory="""You are a Senior Research Analyst at a leading tech think tank.
  Your expertise lies in identifying emerging trends and technologies in AI and
  data science. You have a knack for dissecting complex data and presenting
  actionable insights.""",
  verbose=True,
  allow_delegation=False,
  tools=[search_tool],
  llm=local_openai_client
)
writer = Agent(
  role='Tech Content Strategist',
  goal='Craft compelling content on tech advancements',
  backstory="""You are a renowned Tech Content Strategist, known for your insightful
  and engaging articles on technology and innovation. With a deep understanding of
  the tech industry, you transform complex concepts into compelling narratives.""",
  verbose=True,
  llm=local_openai_client,
  allow_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.
  Compile your findings in a detailed report.""",
  agent=researcher
)

task2 = Task(
  description="""Using the insights from the researcher's report, 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.
  Aim for a narrative that captures the essence of these breakthroughs and their
  implications for the future.""",
  agent=writer
)

# Instantiate your crew with a sequential process
crew = Crew(
  agents=[researcher, writer],
  tasks=[task1, task2],
  verbose=2, # Crew verbose more will let you know what tasks are being worked on, you can set it to 1 or 2 to different logging levels
  process=Process.sequential # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)

# Get your crew to work!
result = crew.kickoff()

print("######################")
print(result)

AttributeError: 'NoneType' object has no attribute 'allow_delegation'

import os
from crewai import Agent, Task, Crew, Process

# You can choose to use a local model through Ollama for example.
# In this case we will use OpenHermes 2.5 as an example.
#
from langchain.llms import Ollama
ollama_llm = Ollama(model="dolphin-mistral")

# If you are using an ollama like above you don't need to set OPENAI_API_KEY.
#os.environ["OPENAI_API_KEY"] = "Your Key"

# Define your tools, custom or not.
# Install duckduckgo-search for this example:
#
# !pip install -U duckduckgo-search

from langchain.tools import DuckDuckGoSearchRun
search_tool = DuckDuckGoSearchRun()

# Define your agents with roles and goals
researcher = Agent(
  role='Senior Research Analyst',
  goal='Uncover cutting-edge developments in AI and data science in',
  backstory="""You are a Senior Research Analyst at a leading tech think tank.
  Your expertise lies in identifying emerging trends and technologies in AI and
  data science. You have a knack for dissecting complex data and presenting
  actionable insights.""",
  verbose=True,
  allow_delegation=False,
  tools=[search_tool],
  # (optional)
  llm=ollama_llm,
  #If you wanna use a local modal through Ollama, default is GPT4 with temperature=0.7

)
writer = Agent(
  role='Tech Content Strategist',
  goal='Craft compelling content on tech advancements',
  backstory="""You are a renowned Tech Content Strategist, known for your insightful
  and engaging articles on technology and innovation. With a deep understanding of
  the tech industry, you transform complex concepts into compelling narratives.""",
  verbose=True,
  # (optional)
  llm=ollama_llm,
  #If you wanna use a local modal through Ollama, default is GPT4 with temperature=0.7
  allow_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.
  Compile your findings in a detailed report. Your final answer MUST be a full analysis report""",
  aget=researcher
)

task2 = Task(
        description="""Using the insights from the researcher's report, 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.
  Aim for a narrative that captures the essence of these breakthroughs and their
  implications for the future. Your final answer MUST be the full blog post of at least 3 paragraphs.""",
  agent=writer
)

# Instantiate your crew with a sequential process
crew = Crew(
  agents=[researcher, writer],
  tasks=[task1, task2],
  verbose=2, # Crew verbose more will let you know what tasks are being worked on, you can set it to 1 or 2 to different logging levels
  process=Process.sequential # Sequential process will have tasks executed one after the other and the outcome of the previous one is passed as extra content into this next.
)

# Get your crew to work!
result = crew.kickoff()

print("######################")
print(result)

Add tool groups

A problem I've been having with local llm, is that not all tools work, or I don't know tools that are available.
As an enhancement, Add toolgroups. I'm suggesting that instead of looking up the needed tools, we have predefined functions for common tools.

I envision something like:

from crewai import Agent, Task, Crew, Process, Toolgroups

researchtools = Toolgroups("webtools", "calctools") # webtools is browser stuff, calctools is eval stuff. 
financetools = Toolgroups("finance", "financemath") #yhfinance common math tools used in finance

researcher = agent {....
      tools = reasearchtools
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.