Repository: crewAIInc/crewAI
File: tests/agents/test_agent.py (Python)

Code before:
    mock_settings_instance.org_name = None
    mock_settings.return_value = mock_settings_instance

    mock_get_response = MagicMock()
    mock_get_response.status_code = 401
    mock_get_response.text = "Unauthorized access"
    mock_get_agent.return_value = mock_get_response

    with pytest.raises(
        AgentRepositoryError,
        match="Agent test_agent could not be loaded: Unauthorized access",
    ):
        Agent(from_repository="test_agent")

    mock_console.print.assert_any_call(
        "No organization currently set. We recommend setting one before using: `crewai org switch <org_id>` command.",
        style="yellow",
    )

def test_agent_actions_basic_functionality():
    # Test with valid actions
    agent = Agent(
        role="Platform Agent",
        goal="Use platform tools",
        backstory="Platform specialist",
        actions=["gmail/create_task", "slack/update_status", "customer_support/send_notification"]
    )
    assert set(agent.actions) == {"gmail/create_task", "slack/update_status", "customer_support/send_notification"}

    agent_default = Agent(
        role="Regular Agent",
        goal="Regular tasks",
        backstory="Regular agent"
    )
    assert agent_default.actions is None


@patch.object(Agent, 'get_platform_tools')
def test_actions_propagated_to_platform_tools(mock_get_platform_tools):
    from crewai.tools import tool

    @tool
    def action_tool() -> str:
        """Mock action platform tool."""
        return "action tool result"

    mock_get_platform_tools.return_value = [action_tool]

    agent = Agent(
        role="Action Agent",
        goal="Execute actions",

Review comment (suggestion):
i thought we are consolidating it to apps. but two ways of setting based on one attribute:

`Agent(apps=["gmail"])`
and
`Agent(apps=["gmail/action"])`

Code after:
    mock_console.print.assert_any_call(
        "Fetching agent from organization: Test Organization (test-org-uuid)",
        style="bold blue",
    )

    assert agent.role == "test role"
    assert agent.goal == "test goal"
    assert agent.backstory == "test backstory"


@patch("crewai.cli.plus_api.PlusAPI.get_agent")
@patch("crewai.utilities.agent_utils.Settings")
@patch("crewai.utilities.agent_utils.console")
def test_agent_from_repository_without_org_set(
    mock_console, mock_settings, mock_get_agent, mock_get_auth_token
):
    mock_settings_instance = MagicMock()
    mock_settings_instance.org_uuid = None
    mock_settings_instance.org_name = None
    mock_settings.return_value = mock_settings_instance

    mock_get_response = MagicMock()
    mock_get_response.status_code = 401
    mock_get_response.text = "Unauthorized access"
    mock_get_agent.return_value = mock_get_response

    with pytest.raises(
        AgentRepositoryError,
        match="Agent test_agent could not be loaded: Unauthorized access",
    ):
        Agent(from_repository="test_agent")

    mock_console.print.assert_any_call(
        "No organization currently set. We recommend setting one before using: `crewai org switch <org_id>` command.",
        style="yellow",
    )

def test_agent_apps_consolidated_functionality():
    agent = Agent(
        role="Platform Agent",
        goal="Use platform tools",
        backstory="Platform specialist",
        apps=["gmail/create_task", "slack/update_status", "hubspot"]
    )
    expected = {"gmail/create_task", "slack/update_status", "hubspot"}
    assert set(agent.apps) == expected

    agent_apps_only = Agent(
        role="App Agent",
        goal="Use apps",
        backstory="App specialist",