Skip to content
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

fix breakage when cloning agent/crew using knowledge_sources and enable custom knowledge_storage #1927

Merged
merged 40 commits into from
Jan 29, 2025
Merged
Changes from 1 commit
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
f3004ff
fix breakage when cloning agent/crew using knowledge_sources
lorenzejay Jan 19, 2025
dc9d1d6
fixed typo
lorenzejay Jan 20, 2025
c67f75d
better
lorenzejay Jan 24, 2025
591c4a5
ensure use of other knowledge storage works
lorenzejay Jan 24, 2025
71246e9
fix copy and custom storage
lorenzejay Jan 24, 2025
f34f53f
added tests
lorenzejay Jan 24, 2025
e3e62c1
normalized name
lorenzejay Jan 24, 2025
65d3837
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
lorenzejay Jan 24, 2025
79aaab9
updated cassette
lorenzejay Jan 24, 2025
ab8d56d
fix test
lorenzejay Jan 24, 2025
849908c
remove fixture
lorenzejay Jan 24, 2025
c6d8c75
fixed test
lorenzejay Jan 24, 2025
b87c908
fix
lorenzejay Jan 24, 2025
27e4930
add fixture to this
lorenzejay Jan 24, 2025
e4b97e3
add fixture to this
lorenzejay Jan 24, 2025
24dbdd5
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
lorenzejay Jan 24, 2025
4008ba7
patch twice since
lorenzejay Jan 24, 2025
65b6ff1
fix again
lorenzejay Jan 24, 2025
079692d
with fixtures
lorenzejay Jan 24, 2025
4ff9d49
better mocks
lorenzejay Jan 24, 2025
d438f5a
fix
lorenzejay Jan 24, 2025
0675a2f
simple
lorenzejay Jan 24, 2025
6fb654c
try
lorenzejay Jan 25, 2025
319128c
another
lorenzejay Jan 27, 2025
d506bdb
hopefully fixes test
lorenzejay Jan 27, 2025
cb3865a
hopefully fixes test
lorenzejay Jan 27, 2025
adec089
this should fix it !
lorenzejay Jan 27, 2025
1cc9c98
WIP: test check with prints
lorenzejay Jan 27, 2025
f4b7cff
try this
lorenzejay Jan 27, 2025
1de204e
exclude knowledge
lorenzejay Jan 27, 2025
9b88bcd
fixes
lorenzejay Jan 27, 2025
ac28f7f
just drop clone for now
lorenzejay Jan 27, 2025
42769e8
rm print statements
lorenzejay Jan 27, 2025
b92253b
printing agent_copy
lorenzejay Jan 27, 2025
8570461
checker
lorenzejay Jan 27, 2025
b183aaf
linted
lorenzejay Jan 27, 2025
fd89c3b
cleanup
lorenzejay Jan 27, 2025
6617db7
better docs
lorenzejay Jan 27, 2025
c4da244
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
lorenzejay Jan 27, 2025
2816e97
Merge branch 'main' into fix/clone_when_using_knowledge
bhancockio Jan 28, 2025
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
Prev Previous commit
Next Next commit
Merge branch 'main' of github.com:crewAIInc/crewAI into fix/clone_whe…
…n_using_knowledge
  • Loading branch information
lorenzejay committed Jan 24, 2025
commit 65d3837c0d459ec66507ce3727c9bc1ff824c30e
100 changes: 100 additions & 0 deletions tests/agent_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1622,3 +1622,103 @@ def test_agent_with_knowledge_sources_works_with_test():
assert agent_copy.backstory == agent.backstory
assert agent_copy.knowledge_sources == agent.knowledge_sources
assert isinstance(agent_copy.llm, LLM)


@pytest.mark.vcr(filter_headers=["authorization"])
def test_litellm_auth_error_handling():
"""Test that LiteLLM authentication errors are handled correctly and not retried."""
from litellm import AuthenticationError as LiteLLMAuthenticationError

# Create an agent with a mocked LLM and max_retry_limit=0
agent = Agent(
role="test role",
goal="test goal",
backstory="test backstory",
llm=LLM(model="gpt-4"),
max_retry_limit=0, # Disable retries for authentication errors
)

# Create a task
task = Task(
description="Test task",
expected_output="Test output",
agent=agent,
)

# Mock the LLM call to raise LiteLLMAuthenticationError
with (
patch.object(LLM, "call") as mock_llm_call,
pytest.raises(LiteLLMAuthenticationError, match="Invalid API key"),
):
mock_llm_call.side_effect = LiteLLMAuthenticationError(
message="Invalid API key", llm_provider="openai", model="gpt-4"
)
agent.execute_task(task)

# Verify the call was only made once (no retries)
mock_llm_call.assert_called_once()


def test_crew_agent_executor_litellm_auth_error():
"""Test that CrewAgentExecutor handles LiteLLM authentication errors by raising them."""
from litellm import AuthenticationError as LiteLLMAuthenticationError

from crewai.agents.tools_handler import ToolsHandler
from crewai.utilities import Printer

# Create an agent and executor
agent = Agent(
role="test role",
goal="test goal",
backstory="test backstory",
llm=LLM(model="gpt-4", api_key="invalid_api_key"),
)
task = Task(
description="Test task",
expected_output="Test output",
agent=agent,
)

# Create executor with all required parameters
executor = CrewAgentExecutor(
agent=agent,
task=task,
llm=agent.llm,
crew=None,
prompt={"system": "You are a test agent", "user": "Execute the task: {input}"},
max_iter=5,
tools=[],
tools_names="",
stop_words=[],
tools_description="",
tools_handler=ToolsHandler(),
)

# Mock the LLM call to raise LiteLLMAuthenticationError
with (
patch.object(LLM, "call") as mock_llm_call,
patch.object(Printer, "print") as mock_printer,
pytest.raises(LiteLLMAuthenticationError, match="Invalid API key"),
):
mock_llm_call.side_effect = LiteLLMAuthenticationError(
message="Invalid API key", llm_provider="openai", model="gpt-4"
)
executor.invoke(
{
"input": "test input",
"tool_names": "",
"tools": "",
}
)

# Verify error handling
mock_printer.assert_any_call(
content="An unknown error occurred. Please check the details below.",
color="red",
)
mock_printer.assert_any_call(
content="Error details: litellm.AuthenticationError: Invalid API key",
color="red",
)
# Verify the call was only made once (no retries)
mock_llm_call.assert_called_once()
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.