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
Load JSON Config
def load_json_config():
try:
with open(“config.json”, “r”) as file:
return json.load(file)
except FileNotFoundError:
print(“
ERROR: ‘config.json’ not found!”)
exit(1)
except json.JSONDecodeError:
print(“
ERROR: Invalid JSON format in ‘config.json’!”)
exit(1)
config = load_json_config()
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
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
)
)
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.”
)
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)
Create AI Crew (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)
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>