Skip to content

Commit

Permalink
Fix logging types to bool (#1051)
Browse files Browse the repository at this point in the history
* fixes pydantic validations hierarchical

* more tests

* logger logs everything or not

* verbose rm levels to bool

* updated readme verbose levels
  • Loading branch information
lorenzejay authored Aug 7, 2024
1 parent 498e96a commit 86c6760
Show file tree
Hide file tree
Showing 17 changed files with 15,857 additions and 62 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ task2 = Task(
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2, # You can set it to 1 or 2 to different logging levels
verbose=True,
process = Process.sequential
)

Expand Down
2 changes: 1 addition & 1 deletion docs/core-concepts/Crews.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Once a crew has been executed, its output can be accessed through the `output` a
crew = Crew(
agents=[research_agent, writer_agent],
tasks=[research_task, write_article_task],
verbose=2
verbose=True
)

crew_output = crew.kickoff()
Expand Down
6 changes: 3 additions & 3 deletions docs/core-concepts/Tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ task = Task(
crew = Crew(
agents=[research_agent],
tasks=[task],
verbose=2
verbose=True
)

result = crew.kickoff()
Expand Down Expand Up @@ -142,7 +142,7 @@ task = Task(
crew = Crew(
agents=[research_agent],
tasks=[task],
verbose=2
verbose=True
)

result = crew.kickoff()
Expand Down Expand Up @@ -264,7 +264,7 @@ task1 = Task(
crew = Crew(
agents=[research_agent],
tasks=[task1, task2, task3],
verbose=2
verbose=True
)

result = crew.kickoff()
Expand Down
2 changes: 1 addition & 1 deletion docs/core-concepts/Tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ write = Task(
crew = Crew(
agents=[researcher, writer],
tasks=[research, write],
verbose=2
verbose=True
)

# Execute tasks
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/Conditional-Tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ task3 = Task(
crew = Crew(
agents=[data_fetcher_agent, data_processor_agent, summary_generator_agent],
tasks=[task1, conditional_task, task3],
verbose=2,
verbose=True,
)

result = crew.kickoff()
Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/Human-Input-on-Execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ task2 = Task(
crew = Crew(
agents=[researcher, writer],
tasks=[task1, task2],
verbose=2,
verbose=True,
memory=True,
)

Expand Down
2 changes: 1 addition & 1 deletion docs/how-to/LLM-Connections.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ task = Task(description="""what is 3 + 5""",
crew = Crew(
agents=[general_agent],
tasks=[task],
verbose=2
verbose=True
)
result = crew.kickoff()
Expand Down
2 changes: 1 addition & 1 deletion src/crewai/agents/agent_builder/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def set_attributes_based_on_config(self) -> "BaseAgent":
@model_validator(mode="after")
def set_private_attrs(self):
"""Set private attributes."""
self._logger = Logger(self.verbose)
self._logger = Logger(verbose=self.verbose)
if self.max_rpm and not self._rpm_controller:
self._rpm_controller = RPMController(
max_rpm=self.max_rpm, logger=self._logger
Expand Down
2 changes: 1 addition & 1 deletion src/crewai/agents/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CrewAgentExecutor(AgentExecutor, CrewAgentExecutorMixin):
system_template: Optional[str] = None
prompt_template: Optional[str] = None
response_template: Optional[str] = None
_logger: Logger = Logger(verbose_level=2)
_logger: Logger = Logger()
_fit_context_window_strategy: Optional[Literal["summarize"]] = "summarize"

def _call(
Expand Down
2 changes: 1 addition & 1 deletion src/crewai/cli/templates/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ def crew(self) -> Crew:
agents=self.agents, # Automatically created by the @agent decorator
tasks=self.tasks, # Automatically created by the @task decorator
process=Process.sequential,
verbose=2,
verbose=True,
# process=Process.hierarchical, # In case you wanna use that instead https://docs.crewai.com/how-to/Hierarchical/
)
4 changes: 2 additions & 2 deletions src/crewai/crew.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Crew(BaseModel):
tasks: List[Task] = Field(default_factory=list)
agents: List[BaseAgent] = Field(default_factory=list)
process: Process = Field(default=Process.sequential)
verbose: Union[int, bool] = Field(default=0)
verbose: bool = Field(default=False)
memory: bool = Field(
default=False,
description="Whether the crew should use memory to store memories of it's execution",
Expand Down Expand Up @@ -196,7 +196,7 @@ def check_config_type(
def set_private_attrs(self) -> "Crew":
"""Set private attributes."""
self._cache_handler = CacheHandler()
self._logger = Logger(self.verbose)
self._logger = Logger(verbose=self.verbose)
if self.output_log_file:
self._file_handler = FileHandler(self.output_log_file)
self._rpm_controller = RPMController(max_rpm=self.max_rpm, logger=self._logger)
Expand Down
10 changes: 3 additions & 7 deletions src/crewai/utilities/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@
class Logger:
_printer = Printer()

def __init__(self, verbose_level=0):
verbose_level = (
2 if isinstance(verbose_level, bool) and verbose_level else verbose_level
)
self.verbose_level = verbose_level
def __init__(self, verbose=False):
self.verbose = verbose

def log(self, level, message, color="bold_green"):
level_map = {"debug": 1, "info": 2}
if self.verbose_level and level_map.get(level, 0) <= self.verbose_level:
if self.verbose:
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
self._printer.print(
f"[{timestamp}][{level.upper()}]: {message}", color=color
Expand Down
8 changes: 4 additions & 4 deletions tests/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ def get_final_answer(numbers) -> float:
agent=agent,
)

crew = Crew(agents=[agent], tasks=[task], max_rpm=1, verbose=2)
crew = Crew(agents=[agent], tasks=[task], max_rpm=1, verbose=True)

with patch.object(RPMController, "_wait_for_next_minute") as moveon:
moveon.return_value = True
Expand Down Expand Up @@ -522,7 +522,7 @@ def get_final_answer(numbers) -> float:
),
]

crew = Crew(agents=[agent1, agent2], tasks=tasks, max_rpm=1, verbose=2)
crew = Crew(agents=[agent1, agent2], tasks=tasks, max_rpm=1, verbose=True)

with patch.object(RPMController, "_wait_for_next_minute") as moveon:
moveon.return_value = True
Expand Down Expand Up @@ -563,7 +563,7 @@ def get_final_answer() -> float:
crew = Crew(
agents=[agent1],
tasks=tasks,
verbose=2,
verbose=True,
function_calling_llm=ChatOpenAI(model="gpt-4-0125-preview"),
)

Expand Down Expand Up @@ -602,7 +602,7 @@ def get_final_answer(anything: str) -> float:
)
]

crew = Crew(agents=[agent1], tasks=tasks, verbose=2)
crew = Crew(agents=[agent1], tasks=tasks, verbose=True)

with patch.object(ToolUsage, "_remember_format") as remember_format:
crew.kickoff()
Expand Down
Loading

0 comments on commit 86c6760

Please sign in to comment.