crewAIInc / crewAI

Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewAI empowers agents to work together seamlessly, tackling complex tasks.
https://crewai.com
MIT License
21.93k stars 3.04k forks source link

How to better use max_iter paramer in Agent class? #874

Closed Chriszhangmw closed 4 months ago

Chriszhangmw commented 5 months ago

Hi, thank to Crewai team for this amazing work. I was running one samll experiment and found that some agent will repeat working even I found the initial response is good enough, the initial response here is that the first time running ourput of the agent. Insipred by your documents, I set max_iter is 1 to control that. Agent: def retrieval_agent(self): return Agent( role='Retrieval similar cases agent', goal="""provide the most similar cases to the user input""", backstory='the agent can retrieve the information from the database', verbose=True, max_iter=1, llm=azure_llm )

However, the agent final out put and internal ourput of the agents response: Agent stopped due to iteration limit or time limit. All the output: {'final_output': 'Agent stopped due to iteration limit or time limit.', 'tasks_outputs': [TaskOutput(description='write one paragraph about the hydration ingredient:hydration sugar', summary='write one paragraph about the hydration ingredient:hydration sugar...', result="Hydration sugar, scientifically known as trehalose, is a unique ingredient that boosts hydration levels in skin and body. This natural sugar is found in certain types of desert plants and microorganisms that can survive in extremely dry conditions. It works by retaining moisture within cells, preventing dehydration and promoting overall health. Furthermore, in skincare, it helps maintain the skin's barrier function, enhancing its ability to lock in moisture. Therefore, products containing hydration sugar are ideal for individuals seeking optimal hydration and improved skin health."), TaskOutput(description='write one paragraph about the company culture:coco-cola', summary='write one paragraph about the company culture:coco-cola...', result="Coca-Cola's company culture is centered around leadership, collaboration, integrity, accountability, passion, diversity, and quality. The company is committed to creating a workplace environment that fosters these values, encouraging employees to lead, be accountable, and bring their passion to work. Coca-Cola values diversity, recognizing that it drives innovation and growth. It also prioritizes quality in everything it does, from its products to its relationships with stakeholders. The company culture at Coca-Cola is designed to inspire and motivate employees while driving the company's success."), TaskOutput(description='retrieval the related cases from the database based on the input data, the input are hydration sugar , coco-cola', summary='retrieval the related cases from the database based on the...', result='Agent stopped due to iteration limit or time limit.'),

My question:

  1. Could you help to clarify how to use this paramerter?
  2. I did not change the inputs, so the initial response should be good enough, but now it response the limitation, how to avoid that?
fatmind commented 5 months ago

When the agent runs via the LLM, it relies on stop_words to determine whether to stop, or it limits the number of iterations with max_iter. Why does it repeat? Your agent example is inherently ambiguous and unclear.

Chriszhangmw commented 5 months ago

Thanks for your comments, could you give me more hints based on my Agent? I mean how to set role, goal and backstory for my Agent.

theCyberTech commented 4 months ago

Only you can improve the Role, Goal, Back story based on your use case. This issue is better placed in our Discord server where we can assist you better - https://discord.gg/6pMt4WuD