mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-27 00:58:13 +00:00
Add markdown attribute to Task class for formatting responses in Markdown
Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -135,6 +135,10 @@ class Task(BaseModel):
|
|||||||
description="Whether the task should have a human review the final answer of the agent",
|
description="Whether the task should have a human review the final answer of the agent",
|
||||||
default=False,
|
default=False,
|
||||||
)
|
)
|
||||||
|
markdown: Optional[bool] = Field(
|
||||||
|
description="Whether the task should instruct the agent to return the final answer formatted in Markdown",
|
||||||
|
default=False,
|
||||||
|
)
|
||||||
converter_cls: Optional[Type[Converter]] = Field(
|
converter_cls: Optional[Type[Converter]] = Field(
|
||||||
description="A converter class used to export structured output",
|
description="A converter class used to export structured output",
|
||||||
default=None,
|
default=None,
|
||||||
@@ -533,6 +537,11 @@ class Task(BaseModel):
|
|||||||
expected_output=self.expected_output
|
expected_output=self.expected_output
|
||||||
)
|
)
|
||||||
tasks_slices = [self.description, output]
|
tasks_slices = [self.description, output]
|
||||||
|
|
||||||
|
if self.markdown:
|
||||||
|
markdown_instruction = "Your final answer MUST be formatted in Markdown syntax."
|
||||||
|
tasks_slices.append(markdown_instruction)
|
||||||
|
|
||||||
return "\n".join(tasks_slices)
|
return "\n".join(tasks_slices)
|
||||||
|
|
||||||
def interpolate_inputs_and_add_conversation_history(
|
def interpolate_inputs_and_add_conversation_history(
|
||||||
|
|||||||
53
tests/test_markdown_task.py
Normal file
53
tests/test_markdown_task.py
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
"""Test the markdown attribute in Task class."""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from crewai import Agent, Task
|
||||||
|
|
||||||
|
|
||||||
|
def test_markdown_option_in_task_prompt():
|
||||||
|
"""Test that when markdown=True, the task prompt includes markdown formatting instructions."""
|
||||||
|
|
||||||
|
researcher = Agent(
|
||||||
|
role="Researcher",
|
||||||
|
goal="Research a topic",
|
||||||
|
backstory="You're a researcher specialized in providing well-formatted content.",
|
||||||
|
allow_delegation=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
task = Task(
|
||||||
|
description="Research advances in AI in 2023",
|
||||||
|
expected_output="A summary of key AI advances in 2023",
|
||||||
|
markdown=True,
|
||||||
|
agent=researcher,
|
||||||
|
)
|
||||||
|
|
||||||
|
prompt = task.prompt()
|
||||||
|
|
||||||
|
assert "Research advances in AI in 2023" in prompt
|
||||||
|
assert "A summary of key AI advances in 2023" in prompt
|
||||||
|
assert "Your final answer MUST be formatted in Markdown syntax." in prompt
|
||||||
|
|
||||||
|
|
||||||
|
def test_markdown_option_not_in_task_prompt_by_default():
|
||||||
|
"""Test that by default (markdown=False), the task prompt does not include markdown formatting instructions."""
|
||||||
|
|
||||||
|
researcher = Agent(
|
||||||
|
role="Researcher",
|
||||||
|
goal="Research a topic",
|
||||||
|
backstory="You're a researcher specialized in providing well-formatted content.",
|
||||||
|
allow_delegation=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
task = Task(
|
||||||
|
description="Research advances in AI in 2023",
|
||||||
|
expected_output="A summary of key AI advances in 2023",
|
||||||
|
agent=researcher,
|
||||||
|
)
|
||||||
|
|
||||||
|
prompt = task.prompt()
|
||||||
|
|
||||||
|
assert "Research advances in AI in 2023" in prompt
|
||||||
|
assert "A summary of key AI advances in 2023" in prompt
|
||||||
|
assert "Your final answer MUST be formatted in Markdown syntax." not in prompt
|
||||||
Reference in New Issue
Block a user