Issue with From crewai.tools import Tool

from crewai.tools import Tool

Define tools using BaseTool

resource_tool = Tool(
name=“Azure Resource Group Creator”,
description=“Creates an Azure Resource Group in the specified region.”,
func=lambda: create_resource_group(config[‘subscription_id’], config[‘resource_group’], config[‘region’])
)

app_service_tool = Tool(
name=“Azure App Service Plan Creator”,
description=“Creates an Azure App Service Plan with the specified name and tier.”,
func=lambda: create_app_service_plan(config[‘subscription_id’], config[‘resource_group’], config[‘app_service_plan_name’], config[‘region’])
)

                                                                                                                    Error    PS C:\AgenticAIfeatures\Azureautomation> python azure_agents.py

Traceback (most recent call last):
File “C:\AgenticAIfeatures\Azureautomation\azure_agents.py”, line 3, in
from crewai.tools import Tool
ImportError: cannot import name ‘Tool’ from ‘crewai.tools’ (C:\Python311\Lib\site-packages\crewai\tools_init_.py)

The way you are creating the tools is not supported. You can either use BaseTool class or the tool decorator.

from crewai.tools import BaseTool, tool

You can find more details on the tools docs Tools - CrewAI

from crewai import Agent, Task, Crew

from crewai_tools import Tool

from crewai.tools import BaseTool

Use BaseTool instead of Tool

from azure_helper import create_resource_group, create_web_app, create_app_service_plan, create_container_registry
import json

Load JSON Config

def load_json_config():
try:
with open(“config.json”, “r”) as file:
return json.load(file)
except FileNotFoundError:
print(“:cross_mark: ERROR: ‘config.json’ not found! Make sure it exists in the script directory.”)
exit(1)
except json.JSONDecodeError:
print(“:cross_mark: ERROR: ‘config.json’ contains invalid JSON! Fix the formatting.”)
exit(1)

config = load_json_config()

Define tools using BaseTool

resource_tool = BaseTool(
name=“Azure Resource Group Creator”,
description=“Creates an Azure Resource Group in the specified region.”,
func=lambda: create_resource_group(config[‘subscription_id’], config[‘resource_group’], config[‘region’])
)

app_service_tool = BaseTool(
name=“Azure App Service Plan Creator”,
description=“Creates an Azure App Service Plan with the specified name and tier.”,
func=lambda: create_app_service_plan(config[‘subscription_id’], config[‘resource_group’], config[‘app_service_plan_name’], config[‘region’])
)

web_app_tool = BaseTool(
name=“Azure Web App Creator”,
description=“Creates an Azure Web App and links it to an App Service Plan.”,
func=lambda: create_web_app(config[‘subscription_id’], config[‘resource_group’], config[‘web_app_name’], config[‘app_service_plan_name’], config[‘region’])
)

acr_tool = BaseTool(
name=“Azure Container Registry Creator”,
description=“Creates an Azure Container Registry for storing container images.”,
func=lambda: create_container_registry(config[‘subscription_id’], config[‘resource_group’], config[‘container_registry_name’], config[‘region’])
)

Agents with backstories

resource_agent = Agent(
role=“Resource Manager”,
goal=“Create a Resource Group”,
tools=[resource_tool],
backstory=“An experienced Azure cloud architect responsible for provisioning and managing cloud resources efficiently.”
)

app_service_agent = Agent(
role=“App Service Manager”,
goal=“Create an App Service Plan”,
tools=[app_service_tool],
backstory=“A cloud infrastructure specialist ensuring optimal deployment of web applications through scalable App Service Plans.”
)

web_app_agent = Agent(
role=“Web App Creator”,
goal=“Deploy a Web App”,
tools=[web_app_tool],
backstory=“A seasoned DevOps engineer dedicated to deploying and maintaining high-performance web applications on Azure.”
)

acr_agent = Agent(
role=“Container Registry Manager”,
goal=“Create a Container Registry”,
tools=[acr_tool],
backstory=“A containerization expert managing secure and scalable container image storage within Azure’s ecosystem.”
)

Tasks

task1 = Task(description=“Create Resource Group”, agent=resource_agent)
task2 = Task(description=“Create App Service Plan”, agent=app_service_agent)
task3 = Task(description=“Create Web App”, agent=web_app_agent)
task4 = Task(description=“Create Container Registry”, agent=acr_agent)

Crew (AI Team)

azure_crew = Crew(
agents=[resource_agent, app_service_agent, web_app_agent, acr_agent],
tasks=[task1, task2, task3, task4]
)

Execute AI Agents

if name == “main”:
results = azure_crew.kickoff()
print(results)

Still same issue

Error :- File “C:\Python311\Lib\site-packages\crewai_init_.py”, line 3, in
from crewai.agent import Agent
File “C:\Python311\Lib\site-packages\crewai\agent.py”, line 9, in
from crewai.agents.agent_builder.base_agent import BaseAgent
File “C:\Python311\Lib\site-packages\crewai\agents\agent_builder\base_agent.py”, line 23, in
from crewai.tools import BaseTool
ImportError: cannot import name ‘BaseTool’ from ‘crewai.tools’ (C:\Python311\Lib\site-packages\crewai\tools_init_.py)

My code
from crewai import Agent, Task, Crew

from crewai_tools import Tool

from crewai.tools import BaseTool

Use BaseTool instead of Tool

from azure_helper import create_resource_group, create_web_app, create_app_service_plan, create_container_registry
import json

Load JSON Config

def load_json_config():
try:
with open(“config.json”, “r”) as file:
return json.load(file)
except FileNotFoundError:
print(“:cross_mark: ERROR: ‘config.json’ not found! Make sure it exists in the script directory.”)
exit(1)
except json.JSONDecodeError:
print(“:cross_mark: ERROR: ‘config.json’ contains invalid JSON! Fix the formatting.”)
exit(1)

config = load_json_config()

Define tools using BaseTool

resource_tool = BaseTool(
name=“Azure Resource Group Creator”,
description=“Creates an Azure Resource Group in the specified region.”,
func=lambda: create_resource_group(config[‘subscription_id’], config[‘resource_group’], config[‘region’])
)

app_service_tool = BaseTool(
name=“Azure App Service Plan Creator”,
description=“Creates an Azure App Service Plan with the specified name and tier.”,
func=lambda: create_app_service_plan(config[‘subscription_id’], config[‘resource_group’], config[‘app_service_plan_name’], config[‘region’])
)

web_app_tool = BaseTool(
name=“Azure Web App Creator”,
description=“Creates an Azure Web App and links it to an App Service Plan.”,
func=lambda: create_web_app(config[‘subscription_id’], config[‘resource_group’], config[‘web_app_name’], config[‘app_service_plan_name’], config[‘region’])
)

acr_tool = BaseTool(
name=“Azure Container Registry Creator”,
description=“Creates an Azure Container Registry for storing container images.”,
func=lambda: create_container_registry(config[‘subscription_id’], config[‘resource_group’], config[‘container_registry_name’], config[‘region’])
)

Agents with backstories

resource_agent = Agent(
role=“Resource Manager”,
goal=“Create a Resource Group”,
tools=[resource_tool],
backstory=“An experienced Azure cloud architect responsible for provisioning and managing cloud resources efficiently.”
)

app_service_agent = Agent(
role=“App Service Manager”,
goal=“Create an App Service Plan”,
tools=[app_service_tool],
backstory=“A cloud infrastructure specialist ensuring optimal deployment of web applications through scalable App Service Plans.”
)

web_app_agent = Agent(
role=“Web App Creator”,
goal=“Deploy a Web App”,
tools=[web_app_tool],
backstory=“A seasoned DevOps engineer dedicated to deploying and maintaining high-performance web applications on Azure.”
)

acr_agent = Agent(
role=“Container Registry Manager”,
goal=“Create a Container Registry”,
tools=[acr_tool],
backstory=“A containerization expert managing secure and scalable container image storage within Azure’s ecosystem.”
)

Tasks

task1 = Task(description=“Create Resource Group”, agent=resource_agent)
task2 = Task(description=“Create App Service Plan”, agent=app_service_agent)
task3 = Task(description=“Create Web App”, agent=web_app_agent)
task4 = Task(description=“Create Container Registry”, agent=acr_agent)

Crew (AI Team)

azure_crew = Crew(
agents=[resource_agent, app_service_agent, web_app_agent, acr_agent],
tasks=[task1, task2, task3, task4]
)

Execute AI Agents

if name == “main”:
results = azure_crew.kickoff()
print(results)

Did you run crewai install in your project root?

How did you initialise your project? Are you using the CLI via crewai create crew my_crew?

this is my project folder
image i ran crewai install and i dont know how to initialise project

You seem new to CrewAI, I suggest you create a new project via the CLI CLI - CrewAI and use that project structure for your application. You might run into fewer issues that way. Take a look at the quick start to get started Quickstart - CrewAI

Then for your tools define them in the way outlined in the guides and not how you are doing now Tools - CrewAI

you are right i am very new here are all files
Azure_helper.py
from azure.identity import DefaultAzureCredential
from azure.mgmt.resource import ResourceManagementClient
from azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.containerregistry import ContainerRegistryManagementClient
from azure.mgmt.sql import SqlManagementClient

Authenticate with Azure

credential = DefaultAzureCredential()

Function to create a Resource Group

def create_resource_group(subscription_id, resource_group, region):
resource_client = ResourceManagementClient(credential, subscription_id)
resource_client.resource_groups.create_or_update(resource_group, {“location”: region})
return f"Resource Group ‘{resource_group}’ created successfully!"

Function to create an App Service Plan

def create_app_service_plan(subscription_id, resource_group, plan_name, region):
web_client = WebSiteManagementClient(credential, subscription_id)
web_client.app_service_plans.begin_create_or_update(
resource_group, plan_name,
{“location”: region, “sku”: {“name”: “B1”, “tier”: “Basic”}}
).result()
return f"App Service Plan ‘{plan_name}’ created successfully!"

Function to create a Web App

def create_web_app(subscription_id, resource_group, app_name, plan_name, region):
web_client = WebSiteManagementClient(credential, subscription_id)
web_client.web_apps.begin_create_or_update(
resource_group, app_name,
{“location”: region, “server_farm_id”: plan_name, “kind”: “app”}
).result()
return f"Web App ‘{app_name}’ created successfully!"

Function to create a Container Registry

def create_container_registry(subscription_id, resource_group, registry_name, region):
acr_client = ContainerRegistryManagementClient(credential, subscription_id)
acr_client.registries.begin_create(
resource_group, registry_name,
{“location”: region, “sku”: {“name”: “Basic”}, “admin_user_enabled”: True}
).result()
return f"Container Registry ‘{registry_name}’ created successfully!"

Function to create an Azure SQL Database

def create_database(subscription_id, resource_group, server_name, database_name, region):

sql_client = SqlManagementClient(credential, subscription_id)

sql_client.servers.begin_create_or_update(

resource_group, server_name,

{“location”: region, “administrator_login”: “adminuser”, “administrator_login_password”: “Password@123”}

).result()

sql_client.databases.begin_create_or_update(

resource_group, server_name, database_name,

{“location”: region, “sku”: {“name”: “S0”, “tier”: “Standard”}}

).result()

return f"Database ‘{database_name}’ created successfully on server ‘{server_name}’!"

azure_agents.py

from crewai import Agent, Task, Crew
from crewai_tools import CrewTool
from pydantic import BaseModel
import json

Import Azure helper functions

from azure_helper import create_resource_group, create_web_app, create_app_service_plan, create_container_registry

:white_check_mark: Load JSON Config

def load_json_config():
try:
with open(“config.json”, “r”) as file:
return json.load(file)
except FileNotFoundError:
print(“:cross_mark: ERROR: ‘config.json’ not found!”)
exit(1)
except json.JSONDecodeError:
print(“:cross_mark: ERROR: Invalid JSON format in ‘config.json’!”)
exit(1)

config = load_json_config()

:white_check_mark: Define Input Schemas

class ResourceGroupInput(BaseModel):
subscription_id: str
resource_group: str
region: str

class AppServicePlanInput(BaseModel):
subscription_id: str
resource_group: str
app_service_plan_name: str
region: str

class WebAppInput(BaseModel):
subscription_id: str
resource_group: str
web_app_name: str
app_service_plan_name: str
region: str

class ContainerRegistryInput(BaseModel):
subscription_id: str
resource_group: str
container_registry_name: str
region: str

:white_check_mark: Define Crew Tools

resource_tool = CrewTool.from_function(
name=“Azure Resource Group Creator”,
description=“Creates an Azure Resource Group in the specified region.”,
args_schema=ResourceGroupInput,
func=lambda subscription_id, resource_group, region: create_resource_group(subscription_id, resource_group, region)
)

app_service_tool = CrewTool.from_function(
name=“Azure App Service Plan Creator”,
description=“Creates an Azure App Service Plan with the specified name and tier.”,
args_schema=AppServicePlanInput,
func=lambda subscription_id, resource_group, app_service_plan_name, region: create_app_service_plan(
subscription_id, resource_group, app_service_plan_name, region
)
)

web_app_tool = CrewTool.from_function(
name=“Azure Web App Creator”,
description=“Creates an Azure Web App and links it to an App Service Plan.”,
args_schema=WebAppInput,
func=lambda subscription_id, resource_group, web_app_name, app_service_plan_name, region: create_web_app(
subscription_id, resource_group, web_app_name, app_service_plan_name, region
)
)

acr_tool = CrewTool.from_function(
name=“Azure Container Registry Creator”,
description=“Creates an Azure Container Registry for storing container images.”,
args_schema=ContainerRegistryInput,
func=lambda subscription_id, resource_group, container_registry_name, region: create_container_registry(
subscription_id, resource_group, container_registry_name, region
)
)

:white_check_mark: Define AI Agents

resource_agent = Agent(
role=“Resource Manager”,
goal=“Create a Resource Group”,
tools=[resource_tool],
backstory=“An experienced Azure cloud architect managing cloud resources.”
)

app_service_agent = Agent(
role=“App Service Manager”,
goal=“Create an App Service Plan”,
tools=[app_service_tool],
backstory=“A cloud infrastructure specialist ensuring optimal deployments.”
)

web_app_agent = Agent(
role=“Web App Creator”,
goal=“Deploy a Web App”,
tools=[web_app_tool],
backstory=“A DevOps engineer managing high-performance web applications.”
)

acr_agent = Agent(
role=“Container Registry Manager”,
goal=“Create a Container Registry”,
tools=[acr_tool],
backstory=“A containerization expert managing secure image storage.”
)

:white_check_mark: Define Tasks

task1 = Task(description=“Create Resource Group”, agent=resource_agent)
task2 = Task(description=“Create App Service Plan”, agent=app_service_agent)
task3 = Task(description=“Create Web App”, agent=web_app_agent)
task4 = Task(description=“Create Container Registry”, agent=acr_agent)

:white_check_mark: Create AI Crew (Team)

azure_crew = Crew(
agents=[resource_agent, app_service_agent, web_app_agent, acr_agent],
tasks=[task1, task2, task3, task4]
)

:white_check_mark: Execute AI Agents

if name == “main”:
results = azure_crew.kickoff()
print(results)

the above are my two files I am facing the below error
Traceback (most recent call last):
File “C:\AgenticAIfeatures\Azureautomation\azure_agents.py”, line 1, in
from crewai import Agent, Task, Crew
File “C:\Python311\Lib\site-packages\crewai_init_.py”, line 3, in
from crewai.agent import Agent
File “C:\Python311\Lib\site-packages\crewai\agent.py”, line 9, in
from crewai.agents.agent_builder.base_agent import BaseAgent
File “C:\Python311\Lib\site-packages\crewai\agents\agent_builder\base_agent.py”, line 23, in
from crewai.tools import BaseTool
ImportError: cannot import name ‘BaseTool’ from ‘crewai.tools’ (C:\Python311\Lib\site-packages\crewai\tools_init_.py)
PS C:\AgenticAIfeatures\Azureautomation>

pleae help me on this