crewAI: 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 <module> 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=<unprintable dict object>, input_type=dict] For further information visit https://errors.pydantic.dev/2.6/v/missing
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 12
- Comments: 18 (1 by maintainers)
Commits related to this issue
- Fixed pydantic issue - referring to https://github.com/joaomdmoura/crewAI/issues/308 — committed to NTTLuke/spotify-playlist-old by deleted user 3 years ago
- Update Sequential.md To Resolve : pydantic_core._pydantic_core.ValidationError: 1 validation error for Task expected_output Field required [type=missing, input_value=, input_type=dict] For furth... — committed to stsfaroz/crewAI by stsfaroz 2 years ago
- Update Sequential.md (#849) To Resolve : pydantic_core._pydantic_core.ValidationError: 1 validation error for Task expected_output Field required [type=missing, input_value=, input_type=dict] Fo... — committed to crewAIInc/crewAI by stsfaroz 2 years ago
- Update Sequential.md (#849) To Resolve : pydantic_core._pydantic_core.ValidationError: 1 validation error for Task expected_output Field required [type=missing, input_value=, input_type=dict] Fo... — committed to crewAIInc/crewAI by stsfaroz 2 years ago
I solved this by modifying the task to include
expected_output.In this version (0.19.0) Expected Output is mandatory for each task.
I read the updated docs, Is “Expected Output” mandatory now ?
Yup
"Expected Output"is mandatory now as it forces people to be specific about the expected result and get better resutls 😄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