mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 07:42:40 +00:00
feat: expose messages to TaskOutput and LiteAgentOutputs (#3880)
* feat: add messages to task and agent outputs - Introduced a new field in and to capture messages from the last task execution. - Updated the class to store the last messages and provide a property for easy access. - Enhanced the and classes to include messages in their outputs. - Added tests to ensure that messages are correctly included in task outputs and agent outputs during execution. * using typing_extensions for 3.10 compatability * feat: add last_messages attribute to agent for improved task tracking - Introduced a new `last_messages` attribute in the agent class to store messages from the last task execution. - Updated the `Crew` class to handle the new messages attribute in task outputs. - Enhanced existing tests to ensure that the `last_messages` attribute is correctly initialized and utilized across various guardrail scenarios. * fix: add messages field to TaskOutput in tests for consistency - Updated multiple test cases to include the new `messages` field in the `TaskOutput` instances. - Ensured that all relevant tests reflect the latest changes in the TaskOutput structure, maintaining consistency across the test suite. - This change aligns with the recent addition of the `last_messages` attribute in the agent class for improved task tracking. * feat: preserve messages in task outputs during replay - Added functionality to the Crew class to store and retrieve messages in task outputs. - Enhanced the replay mechanism to ensure that messages from stored task outputs are preserved and accessible. - Introduced a new test case to verify that messages are correctly stored and replayed, ensuring consistency in task execution and output handling. - This change improves the overall tracking and context retention of task interactions within the CrewAI framework. * fix original test, prev was debugging
This commit is contained in:
@@ -162,6 +162,7 @@ def test_task_callback_returns_task_output():
|
||||
"name": task.name or task.description,
|
||||
"expected_output": "Bullet point list of 5 interesting ideas.",
|
||||
"output_format": OutputFormat.RAW,
|
||||
"messages": [],
|
||||
}
|
||||
assert output_dict == expected_output
|
||||
|
||||
@@ -1680,3 +1681,44 @@ def test_task_copy_with_list_context():
|
||||
assert isinstance(copied_task2.context, list)
|
||||
assert len(copied_task2.context) == 1
|
||||
assert copied_task2.context[0] is task1
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_task_output_includes_messages():
|
||||
"""Test that TaskOutput includes messages from agent execution."""
|
||||
researcher = Agent(
|
||||
role="Researcher",
|
||||
goal="Make the best research and analysis on content about AI and AI agents",
|
||||
backstory="You're an expert researcher, specialized in technology, software engineering, AI and startups. You work as a freelancer and is now working on doing research and analysis for a new customer.",
|
||||
allow_delegation=False,
|
||||
)
|
||||
|
||||
task1 = Task(
|
||||
description="Give me a list of 3 interesting ideas about AI.",
|
||||
expected_output="Bullet point list of 3 ideas.",
|
||||
agent=researcher,
|
||||
)
|
||||
|
||||
task2 = Task(
|
||||
description="Summarize the ideas from the previous task.",
|
||||
expected_output="A summary of the ideas.",
|
||||
agent=researcher,
|
||||
)
|
||||
|
||||
crew = Crew(agents=[researcher], tasks=[task1, task2], process=Process.sequential)
|
||||
result = crew.kickoff()
|
||||
|
||||
# Verify both tasks have messages
|
||||
assert len(result.tasks_output) == 2
|
||||
|
||||
# Check first task output has messages
|
||||
task1_output = result.tasks_output[0]
|
||||
assert hasattr(task1_output, "messages")
|
||||
assert isinstance(task1_output.messages, list)
|
||||
assert len(task1_output.messages) > 0
|
||||
|
||||
# Check second task output has messages
|
||||
task2_output = result.tasks_output[1]
|
||||
assert hasattr(task2_output, "messages")
|
||||
assert isinstance(task2_output.messages, list)
|
||||
assert len(task2_output.messages) > 0
|
||||
|
||||
Reference in New Issue
Block a user