Pydantic error in v0.19
from crewai import Agent, Task, Crew, Process
from langchain.agents import load_tools
from langchain.tools import BaseTool, StructuredTool, tool
from langchain.pydantic_v1 import BaseModel, Field
from langchain_openai import AzureChatOpenAI
import config
llm = AzureChatOpenAI(
openai_api_key=config.azure_openai_api_key,
openai_api_version=config.azure_openai_api_version,
azure_endpoint=config.azure_openai_endpoint,
azure_deployment=config.model_name,
temperature=0
)
class WeatherInput(BaseModel):
search_string: str = Field(description="the search string for the weather status")
def get_weather(search_string: str) -> str:
"""Look up the weather status"""
return "It's raining season with typhoons."
weather_search = StructuredTool.from_function(
func=get_weather,
name="weather_search",
description="search for the weather status",
args_schema=WeatherInput,
return_direct=True,
)
weather_reporter = Agent(
role='Weather_reporter',
goal="""provide historical weather
overall status based on the dates and location user provided.""",
backstory="""You are a weather reporter who provides weather
overall status based on the dates and location user provided.
You are using historical data from your own experience. Make your response short.""",
verbose=True,
allow_delegation=False,
tools=[weather_search],
llm=llm,
)
activity_agent = Agent(
role='activity_agent',
goal="""responsible for activities
recommendation considering the weather situation from weather_reporter.""",
backstory="""You are an activity agent who recommends
activities considering the weather situation from weather_reporter.
Don't ask questions. Make your response short.""",
verbose=True,
allow_delegation=False,
llm=llm,
)
travel_advisor = Agent(
role='travel_advisor',
goal="""responsible for making a travel plan by consolidating
the activities and require human input for approval.""",
backstory="""After activities recommendation generated
by activity_agent, You generate a concise travel plan
by consolidating the activities.""",
verbose=True,
allow_delegation=False,
# tools=load_tools(["human"]),
llm=llm,
)
insure_agent = Agent(
role='Insure_agent',
goal="""responsible for listing the travel plan from advisor and giving the short
insurance items based on the travel plan""",
backstory="""You are an Insure agent who gives
the short insurance items based on the travel plan.
Don't ask questions. Make your response short.""",
verbose=True,
allow_delegation=False,
llm=llm,
)
task_weather = Task(
description="""Provide weather
overall status in Bohol Island in Sept.""",
agent=weather_reporter
)
task_activity = Task(
description="""Make a research for suitable and up-to-date activities
recommendation considering the weather situation""",
agent=activity_agent
)
task_insure = Task(
description="""1. Copy and list the travel plan from task_advisor. 2. giving the short
insurance items based on the travel plan considering its activities type and intensity.""",
agent=insure_agent
)
task_advisor = Task(
description="""Make a travel plan which includes all the recommended activities, and weather,
Make sure to check with the human if the draft is good
before returning your Final Answer.""",
agent=travel_advisor
)
crew = Crew(
agents=[weather_reporter, activity_agent, travel_advisor, insure_agent, ],
tasks=[task_weather, task_activity, task_advisor, task_insure, ],
verbose=2
)
result = crew.kickoff()
print(result)
Traceback (most recent call last): File "D:\Projects\dataCopilot-web\crewAI.py", line 84, in
task_weather = Task( ^^^^^ File "D:\Projects\dataCopilot-web\venv\Lib\site-packages\pydantic\main.py", line 171, in init self.pydantic_validator.validate_python(data, self_instance=self) pydantic_core._pydantic_core.ValidationError: 1 validation error for Task expected_output Field required [type=missing, input_value= , input_type=dict] For further information visit https://errors.pydantic.dev/2.6/v/missing
Same error for Task expected output
Same problem with a modified version of Instagram Post
Traceback (most recent call last):
File "/home/workspace/logiciels/crewAI-examples/instagram_post_local_tools/main.py", line 24, in <module>
website_analysis = tasks.product_analysis(product_competitor_agent, product_website, product_details)
File "/home/workspace/logiciels/crewAI-examples/instagram_post_local_tools/tasks.py", line 6, in product_analysis
return Task(description=dedent(f"""
File "/home/workspace/.local/lib/python3.10/site-packages/pydantic/main.py", line 171, in __init__
self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Task
expected_output
Field required [type=missing, input_value=<unprintable dict object>, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/missing
Before new version of crewai (v0.19.0), the code function.
Extract of task.py
from crewai import Task
from textwrap import dedent
class MarketingAnalysisTasks:
def product_analysis(self, agent, product_website, product_details):
return Task(description=dedent(f"""\
Analyze the given product website: {product_website}.
Extra details provided by the customer: {product_details}.
Focus on identifying unique features, benefits,
and the overall narrative presented.
Your final report should clearly articulate the
product's key selling points, its market appeal,
and suggestions for enhancement or positioning.
Emphasize the aspects that make the product stand out.
Keep in mind, attention to detail is crucial for
a comprehensive analysis. It's currenlty 2024.
"""),
agent=agent
)
I read the updated docs, Is "Expected Output" mandatory now ?
Got the same error:
main.py", line 192, in <module>
task_researcher = Task(
^^^^^
File "/home/pi5/social/.venv/lib/python3.11/site-packages/pydantic/main.py", line 171, in __init__
self.__pydantic_validator__.validate_python(data, self_instance=self)
pydantic_core._pydantic_core.ValidationError: 1 validation error for Task
expected_output
Field required [type=missing, input_value=<unprintable dict object>, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/missing
I have 3 tasks, last one with a expected_output = " ....", so I added a expected_output = "AI latest news" to the first one, and seems running fine now. Waiting for everything to finish.
Now I am getting this error:
Action: duckduckgo_search Action Input: { "q": "AI latest news" }
I encountered an error while trying to use the tool. This was the error: DuckDuckGoSearchRun._run() got an unexpected keyword argument 'q'. Tool duckduckgo_search accepts there inputs: A wrapper around DuckDuckGo Search. Useful for when you need to answer questions about current events. Input should be a search query.
Check out https://discord.com/channels/1192246288507474000/1213512407712800778/1214042852917510154 There is some latest update on there about using duckduck.
don't have discord. I search on google but not much info. Is the DuckDuck go api got update, so I need to update the package?
@joaomdmoura Check it please.
found this thread but the issue still remain even following the downgrade of duckduckgo-search to 4.4.2. I updated to the latest 4.4.5 and issue still there.
In this version (0.19.0) Expected Output is mandatory for each task.
I have 3 tasks, first and 3rd have expected_output and if I set the second task an expected_output I get this error:
python main.py
File "/home/pi5/social/shorts/main.py", line 201
expected_output = f"A text script about {source_material}"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: keyword argument repeated: expected_output
I am having a similar problem as OP. Using GPT4, no problems, but using GPT 3.5 I get the following. This code uses the SerperDev search and then references validation error for InstructorToolCalling
It seems we encountered an unexpected error while trying to use the tool. This was the error: 1 validation error for InstructorToolCalling
arguments
Field required [type=missing, input_value={'tool_name': 'delegate work to co-worker'}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.6/v/missing
'str' object has no attribute 'tool_name'
Nice of you to open this issue ,I was stuck like for 1 days use expected_output parameter
I solved this by modifying the task to include expected_output.
task = Task(
description='Edit the blog post draft, improving its clarity, coherence, and engagement.',
agent=content_editor,
expected_output='A refined finalized version of the blog post in markdown format'
)
This error happened to me when I accidentally passed my Task class into the crew tasks instead of the task method it describes
tasks = TheTasks()
crew = Crew(
agents=[agent],
tasks=[tasks], # oops
process=Process.sequential
)
I read the updated docs, Is "Expected Output" mandatory now ? File : task.py Line : 18 Each task must have a description, an expected output and an agent responisble for execution.
Yup "Expected Output" is mandatory now as it forces people to be specific about the expected result and get better resutls :D
I solved this by modifying the task to include
expected_output.task = Task( description='Edit the blog post draft, improving its clarity, coherence, and engagement.', agent=content_editor, expected_output='A refined finalized version of the blog post in markdown format' )
Yeh, I was trying to get this example (https://help.crewai.com/how-to-use-output-pydantic-in-a-task) to run but had similar issues. Ended up implementing as below
from pydantic import BaseModel, Field from crewai import Task, Crew, Agent
class User(BaseModel): name: str = Field(title="Name", description="User name") dob: str = Field(title="Date of Birth", description="User date of birth in format dd/mm/yyyy")
agent = Agent( role='User Creator', goal='Create user details', backstory='I am skilled in creating user accounts', verbose=True )
task = Task( description="Create a User object", expected_output="A User object", # Without this line it does not work agent=agent, output_pydantic=User, # Pydantic model verbose=True )
crew = Crew(agents=[agent], tasks=[task], verbose=True)
result = crew.kickoff()
print(result.pydantic)