8000 Improve Logs by joaomdmoura · Pull Request #2975 · crewAIInc/crewAI · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Improve Logs #2975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ dev-dependencies = [
"pytest-timeout>=2.3.1",
]

[tool.pytest.ini_options]
filterwarnings = [
# Suppress Pydantic field conflict warnings from StagehandTool in crewai_tools
"ignore:Field \"model_api_key\" in StagehandTool has conflict with protected namespace \"model_\".:UserWarning",
"ignore:Field \"model_name\" in StagehandTool has conflict with protected namespace \"model_\".:UserWarning",
# Suppress Pydantic V2 deprecation warning for json_encoders
"ignore:`json_encoders` is deprecated.*:pydantic.warnings.PydanticDeprecatedSince20",
# Suppress pytest-asyncio configuration warning
"ignore:The configuration option \"asyncio_default_fixture_loop_scope\" is unset.*:pytest.PytestDeprecationWarning",
]
asyncio_default_fixture_loop_scope = "function"

[project.scripts]
crewai = "crewai.cli.cli:crewai"

Expand Down
3 changes: 1 addition & 2 deletions src/crewai/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Agent(BaseAgent):
description="Whether the agent is multimodal.",
)
inject_date: bool = Field(
default=False,
default=True,
description="Whether to automatically inject the current date into tasks.",
)
date_format: str = Field(
Expand Down Expand Up @@ -254,7 +254,6 @@ def execute_task(
reasoning_handler.handle_agent_reasoning()
)

# Add the reasoning plan to the task description
task.description += f"\n\nReasoning Plan:\n{reasoning_output.plan.plan}"
except Exception as e:
if hasattr(self, "_logger"):
Expand Down
7 changes: 6 additions & 1 deletion src/crewai/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,17 @@ def _prepare_completion_params(
"base_url": self.base_url,
"api_version": self.api_version,
"api_key": self.api_key,
"stream": self.stream,
"tools": tools,
"reasoning_effort": self.reasoning_effort,
**self.additional_params,
}

# Only include stream parameter if we're actually streaming
# This maintains backward compatibility with VCR cassettes
# that were recorded without the stream parameter
if self.stream:
params["stream"] = True

# Remove None values from params
return {k: v for k, v in params.items() if v is not None}

Expand Down
42 changes: 41 additions & 1 deletion src/crewai/utilities/agent_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,10 @@ def show_agent_logs(
content=f"\033[1m\033[95m# Agent:\033[00m \033[1m\033[92m{agent_role}\033[00m"
)
if task_description:
# Filter out reasoning plan from display (but keep it in actual task for LLM)
display_description = _filter_auxiliary_from_display(task_description)
printer.print(
content=f"\033[95m## Task:\033[00m \033[92m{task_description}\033[00m"
content=f"\033[95m## Task:\033[00m \033[92m{display_description}\033[00m"
)
else:
# Execution logs
Expand Down Expand Up @@ -435,6 +437,44 @@ def show_agent_logs(
)


def _filter_auxiliary_from_display(task_description: str) -> str:
"""Remove standard auxiliary sections (e.g., date injection, reasoning plan) from task description for display.

This function standardizes the removal of auxiliary information such as the injected current date
and the reasoning plan from the task description, ensuring that only the core task is shown in display logs.
The actual task description (with all sections) is still used for LLM input.

Args:
task_description (str): The full task description, possibly containing auxiliary sections.

Returns:
str: The task description with auxiliary sections removed for display purposes.

Example:
>>> desc = "Do X\\n\\nCurrent Date: 2024-06-01\\n\\nReasoning Plan:\\nStep 1..."
>>> _filter_auxiliary_from_display(desc)
'Do X'
"""
# Define patterns for auxiliary sections to remove, in order.
auxiliary_patterns = [
(r"\n\nCurrent Date: [^\n]*", "date injection"),
(r"\n\nReasoning Plan:\n.*", "reasoning plan"),
]

cleaned_description = task_description

for pattern, _ in auxiliary_patterns:
# For the reasoning plan, remove everything from the marker to the end.
if "Reasoning Plan" in pattern:
match = re.search(r"\n\nReasoning Plan:\n", cleaned_description)
if match:
cleaned_description = cleaned_description[: match.start()]
else:
cleaned_description = re.sub(pattern, "", cleaned_description)

return cleaned_description.strip()


def load_agent_from_repository(from_repository: str) -> Dict[str, Any]:
attributes: Dict[str, Any] = {}
if from_repository:
Expand Down
1 change: 0 additions & 1 deletion src/crewai/utilities/events/base_event_listener.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from abc import ABC, abstractmethod
from logging import Logger

from crewai.utilities.events.crewai_event_bus import CrewAIEventsBus, crewai_event_bus

Expand Down
19 changes: 18 additions & 1 deletion src/crewai/utilities/events/event_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def on_crew_completed(source, event: CrewKickoffCompletedEvent):
event.crew_name or "Crew",
source.id,
"completed",
event.output,
)

@crewai_event_bus.on(CrewKickoffFailedEvent)
Expand Down Expand Up @@ -150,9 +151,12 @@ def on_crew_test_result(source, event: CrewTestResultEvent):
def on_task_started(source, event: TaskStartedEvent):
span = self._telemetry.task_started(crew=source.agent.crew, task=source)
self.execution_spans[source] = span
self.formatter.create_task_branch(
task_branch = self.formatter.create_task_branch(
self.formatter.current_crew_tree, source.id
)
# Also update current_agent_branch since reasoning happens before agent execution starts
# and the agent branch is the same as the task branch anyway
self.formatter.current_agent_branch = task_branch

@crewai_event_bus.on(TaskCompletedEvent)
def on_task_completed(source, event: TaskCompletedEvent):
Expand All @@ -167,8 +171,15 @@ def on_task_completed(source, event: TaskCompletedEvent):
source.id,
source.agent.role,
"completed",
event.output,
)

# Reset branch pointers for clean state management
self.formatter.current_task_branch = None
self.formatter.current_agent_branch = None
self.formatter.current_tool_branch = None
self.formatter.current_reasoning_branch = None

@crewai_event_bus.on(TaskFailedEvent)
def on_task_failed(source, event: TaskFailedEvent):
span = self.execution_spans.get(source)
Expand All @@ -184,6 +195,12 @@ def on_task_failed(source, event: TaskFailedEvent):
"failed",
)

# Reset branch pointers for clean state management
self.formatter.current_task_branch = None
self.formatter.current_agent_branch = None
self.formatter.current_tool_branch = None
self.formatter.current_reasoning_branch = None

# ----------- AGENT EVENTS -----------

@crewai_event_bus.on(AgentExecutionStartedEvent)
Expand Down
Loading
Loading
0