mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-29 01:58:14 +00:00
Encountering issues with callback. Need to test on main. WIP
This commit is contained in:
@@ -431,7 +431,7 @@ def test_agents_rpm_is_never_set_if_crew_max_RPM_is_not_set():
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Future tests:
|
Future tests:
|
||||||
TODO: 1 async task, 1 sync task. Make sure sync task waits for async to finish before starting.
|
TODO: 1 async task, 1 sync task. Make sure sync task waits for async to finish before starting.[]
|
||||||
TODO: 3 async tasks, 1 sync task. Make sure sync task waits for async to finish before starting.
|
TODO: 3 async tasks, 1 sync task. Make sure sync task waits for async to finish before starting.
|
||||||
TODO: 1 sync task, 1 async task. Make sure we wait for result from async before finishing crew.
|
TODO: 1 sync task, 1 async task. Make sure we wait for result from async before finishing crew.
|
||||||
|
|
||||||
@@ -619,10 +619,6 @@ def test_wait_for_async_execution_before_sync_execution():
|
|||||||
tasks=[bullet_list, article_writer],
|
tasks=[bullet_list, article_writer],
|
||||||
)
|
)
|
||||||
|
|
||||||
# Expected output is that the sync task will wait for the async task to finish before starting.
|
|
||||||
# TODO: Mock the output of the async task
|
|
||||||
# TODO: Mocke the `execute_sync` Task to check that it was passed the context from the async task
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
def test_async_task_execution_call_count():
|
def test_async_task_execution_call_count():
|
||||||
@@ -678,77 +674,73 @@ def test_async_task_execution_call_count():
|
|||||||
assert mock_execute_sync.call_count == 1
|
assert mock_execute_sync.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
# ---- TEST FOR HIERARCHICAL --- #
|
def test_set_agents_step_callback():
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
researcher_agent = 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,
|
||||||
|
)
|
||||||
|
|
||||||
|
list_ideas = Task(
|
||||||
|
description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
||||||
|
expected_output="Bullet point list of 5 important events.",
|
||||||
|
agent=researcher_agent,
|
||||||
|
async_execution=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
crew = Crew(
|
||||||
|
agents=[researcher_agent],
|
||||||
|
process=Process.sequential,
|
||||||
|
tasks=[list_ideas],
|
||||||
|
step_callback=lambda: None,
|
||||||
|
)
|
||||||
|
|
||||||
|
with patch.object(Agent, "execute_task") as execute:
|
||||||
|
execute.return_value = "ok"
|
||||||
|
crew.kickoff()
|
||||||
|
assert researcher_agent.step_callback is not None
|
||||||
|
assert False
|
||||||
|
|
||||||
|
|
||||||
# TODO: Add back in
|
def test_dont_set_agents_step_callback_if_already_set():
|
||||||
# def test_set_agents_step_callback():
|
from unittest.mock import patch
|
||||||
# from unittest.mock import patch
|
|
||||||
|
|
||||||
# researcher_agent = Agent(
|
def agent_callback(_):
|
||||||
# role="Researcher",
|
pass
|
||||||
# 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,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# list_ideas = Task(
|
def crew_callback(_):
|
||||||
# description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
pass
|
||||||
# expected_output="Bullet point list of 5 important events.",
|
|
||||||
# agent=researcher_agent,
|
|
||||||
# async_execution=True,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# crew = Crew(
|
researcher_agent = Agent(
|
||||||
# agents=[researcher_agent],
|
role="Researcher",
|
||||||
# process=Process.sequential,
|
goal="Make the best research and analysis on content about AI and AI agents",
|
||||||
# tasks=[list_ideas],
|
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.",
|
||||||
# step_callback=lambda: None,
|
allow_delegation=False,
|
||||||
# )
|
step_callback=agent_callback,
|
||||||
|
)
|
||||||
|
|
||||||
# with patch.object(Agent, "execute_task") as execute:
|
list_ideas = Task(
|
||||||
# execute.return_value = "ok"
|
description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
||||||
# crew.kickoff()
|
expected_output="Bullet point list of 5 important events.",
|
||||||
# assert researcher_agent.step_callback is not None
|
agent=researcher_agent,
|
||||||
|
async_execution=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
crew = Crew(
|
||||||
|
agents=[researcher_agent],
|
||||||
|
process=Process.sequential,
|
||||||
|
tasks=[list_ideas],
|
||||||
|
step_callback=crew_callback,
|
||||||
|
)
|
||||||
|
|
||||||
# TODO: Add back in
|
with patch.object(Agent, "execute_task") as execute:
|
||||||
# def test_dont_set_agents_step_callback_if_already_set():
|
execute.return_value = "ok"
|
||||||
# from unittest.mock import patch
|
crew.kickoff()
|
||||||
|
assert researcher_agent.step_callback is not crew_callback
|
||||||
# def agent_callback(_):
|
assert researcher_agent.step_callback is agent_callback
|
||||||
# pass
|
|
||||||
|
|
||||||
# def crew_callback(_):
|
|
||||||
# pass
|
|
||||||
|
|
||||||
# researcher_agent = 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,
|
|
||||||
# step_callback=agent_callback,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# list_ideas = Task(
|
|
||||||
# description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
|
||||||
# expected_output="Bullet point list of 5 important events.",
|
|
||||||
# agent=researcher_agent,
|
|
||||||
# async_execution=True,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# crew = Crew(
|
|
||||||
# agents=[researcher_agent],
|
|
||||||
# process=Process.sequential,
|
|
||||||
# tasks=[list_ideas],
|
|
||||||
# step_callback=crew_callback,
|
|
||||||
# )
|
|
||||||
|
|
||||||
# with patch.object(Agent, "execute_task") as execute:
|
|
||||||
# execute.return_value = "ok"
|
|
||||||
# crew.kickoff()
|
|
||||||
# assert researcher_agent.step_callback is not crew_callback
|
|
||||||
# assert researcher_agent.step_callback is agent_callback
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
@@ -1044,35 +1036,34 @@ def test_crew_does_not_interpolate_without_inputs():
|
|||||||
# assert crew.agents[0].backstory == "You have a lot of experience with {topic}."
|
# assert crew.agents[0].backstory == "You have a lot of experience with {topic}."
|
||||||
|
|
||||||
|
|
||||||
# TODO: Add back in
|
def test_task_callback_on_crew():
|
||||||
# def test_task_callback_on_crew():
|
from unittest.mock import patch
|
||||||
# from unittest.mock import patch
|
|
||||||
|
|
||||||
# researcher_agent = Agent(
|
researcher_agent = Agent(
|
||||||
# role="Researcher",
|
role="Researcher",
|
||||||
# goal="Make the best research and analysis on content about AI and AI agents",
|
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.",
|
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,
|
allow_delegation=False,
|
||||||
# )
|
)
|
||||||
|
|
||||||
# list_ideas = Task(
|
list_ideas = Task(
|
||||||
# description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
description="Give me a list of 5 interesting ideas to explore for na article, what makes them unique and interesting.",
|
||||||
# expected_output="Bullet point list of 5 important events.",
|
expected_output="Bullet point list of 5 important events.",
|
||||||
# agent=researcher_agent,
|
agent=researcher_agent,
|
||||||
# async_execution=True,
|
async_execution=True,
|
||||||
# )
|
)
|
||||||
|
|
||||||
# crew = Crew(
|
crew = Crew(
|
||||||
# agents=[researcher_agent],
|
agents=[researcher_agent],
|
||||||
# process=Process.sequential,
|
process=Process.sequential,
|
||||||
# tasks=[list_ideas],
|
tasks=[list_ideas],
|
||||||
# task_callback=lambda: None,
|
task_callback=lambda: None,
|
||||||
# )
|
)
|
||||||
|
|
||||||
# with patch.object(Agent, "execute_task") as execute:
|
with patch.object(Agent, "execute_task") as execute:
|
||||||
# execute.return_value = "ok"
|
execute.return_value = "ok"
|
||||||
# crew.kickoff()
|
crew.kickoff()
|
||||||
# assert list_ideas.callback is not None
|
assert list_ideas.callback is not None
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||||
|
|||||||
Reference in New Issue
Block a user