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
19.62k stars 2.72k forks source link

'str' object has no attribute 'tool_name' #253

Closed artzuros closed 1 month ago

artzuros commented 7 months ago

When using a custom tool in version 0.11.2 it always throws this error. Downgrading to v0.11.1 works.

I have attached the code for anyone to reproduce this.

    'Page 1: Introduction - Introduce the topic of big data and its relevance in todays business world.',
'Page 2: Q&A Session - Reserve a slide for a question and answer session with the audience.',
'Page 3: Definition of Big Data - Provide a clear definition of big data and its key characteristics.',
'Page 4: Applications of Big Data - Discuss the various industries and sectors where big data is being successfully applied.',
'Page 5: Advantages of Big Data - Highlight the advantages and benefits of utilizing big data in business decision-making.',
'Page 6: Leveraging Advanced Technologies - Emphasize the importance of leveraging advanced technologies and tools to unlock the full potential of big data.',
'Page 7: Strategies for Managing Big Data - Provide strategies and best practices for effectively handling and managing big data.',
'Page 8: Challenges of Handling Big Data - Present the challenges and obstacles faced when dealing with large volumes of data.',
'Page 9: Conclusion - Summarize the key points discussed in the presentation and highlight the importance of utilizing big data in business.',
"""
slide_reorder_task = """A suggested reordering of slides to enhance the presentation's flow:

1. Page 1: Introduction - Introduce the topic of big data and its relevance in today's business world.
2. Page 3: Definition of Big Data - Provide a clear definition of big data and its key characteristics.
3. Page 4: Applications of Big Data - Discuss the various industries and sectors where big data is being successfully applied.
4. Page 5: Advantages of Big Data - Highlight the advantages and benefits of utilizing big data in business decision-making.
5. Page 10: Case Studies - Present real-world case studies showcasing the successful implementation of big data solutions in different companies and industries.
6. Page 11: Future Trends in Big Data - Explore the upcoming trends and innovations in the field of big data, including emerging technologies and their potential impact on business strategies.
7. Page 6: Leveraging Advanced Technologies - Emphasize the importance of leveraging advanced technologies and tools to unlock the full potential of big data.
8. Page 7: Strategies for Managing Big Data - Provide strategies and best practices for effectively handling and managing big data.
9. Page 8: Challenges of Handling Big Data - Present the challenges and obstacles faced when dealing with large volumes of data.
10. Page 9: Conclusion - Summarize the key points discussed in the presentation and highlight the importance of utilizing big data in business."""
from crewai import Agent, Task, Crew, Process
from textwrap import dedent

from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
import PyPDF2

load_dotenv()

input_path = "demo1_test.pdf"
output_path = "output_path.pdf"
from langchain.tools import tool

@tool("Insert blank pages at the end of the pdf file")
def insert_blank_pages_last( input_path: str, output_path: str, no_of_pages: int) -> str:
    """
    Insert blank pages at the end of a PDF file.
    Args:
    input_path (str): The file path of the input PDF.
    output_path (str): The file path of the output PDF.
    no_of_pages (int): The number of blank pages to be added at the end of the PDF.

    Returns: str: A message indicating the success or failure of the operation.
    """
    with open(input_path, 'rb') as input_file:
        pdf_reader = PyPDF2.PdfReader(input_file)
        num_pages = len(pdf_reader.pages)
        pdf_writer = PyPDF2.PdfWriter()
        for page in range(num_pages):
            pdf_writer.add_page(pdf_reader.pages[page])
        for i in range(no_of_pages):
            pdf_writer.add_blank_page()
        with open(output_path, 'wb') as output_file:
            pdf_writer.write(output_file)
    return f"{no_of_pages} blank pages added to the last of the {input_path} PDF and saved in {output_path}."
def blank_page_agent(insert_blank_pages_last):
    return Agent(
        role='PDF Pages Adder',
        goal='Add a specific number of blank pages to the end of a PDF file. using the tool insert_blank_pages_last',
        backstory="Handles PDF modifications efficiently using the PDFPageAdder tool.",
        llm=ChatOpenAI(model="gpt-3.5-turbo"),
        tools=[insert_blank_pages_last],
        verbose=True
    )

def blank_page_task(blank_page_agent, result_list, reorder_slides_task, input_path, output_path) :
    return Task(
    description=f'Add the difference of no. of slides/pages in result of {str(result_list)} and {(reorder_slides_task)} blank pages to the end of the given PDF and save it. Input pdf path is {input_path} and the save pdf path is {output_path}.',
    expected_output = "Agent output",
    agent = blank_page_agent,
)
blank_page_agent = blank_page_agent(insert_blank_pages_last)
blank_page_task = blank_page_task(blank_page_agent, result_list, slide_reorder_task, input_path, output_path)

crew_blank = Crew(
    agents = [blank_page_agent],
    tasks = [blank_page_task],
    verbose=True,
    process=Process.sequential,
    # full_output=True
)
result = crew_blank.kickoff()
print(result) 
Ricka7x commented 7 months ago

getting the same error

mattflo commented 7 months ago

I just ran into this too. It appears something is going wrong here. https://github.com/joaomdmoura/crewAI/blob/21667bc7e10addc02e565ae6749fbc093cfbcde5/src/crewai/tools/tool_usage.py#L190

I'm not familiar with the instructor package, but digging into it a bit.

slavakurilyak commented 7 months ago

Related issue #248

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 month ago

This issue was closed because it has been stalled for 5 days with no activity.