from crewai import Agent, Crew, Task
from stackone_ai import StackOneToolSet
def create_hr_crew(account_id: str):
"""
Create multi-agent crew with tools for a specific account.
In production, account_id comes from:
- User/tenant context
- Authentication middleware
- Database lookup
"""
# Initialize toolset
toolset = StackOneToolSet()
# Fetch tools dynamically for this account
tools = toolset.fetch_tools(
account_ids=[account_id]
).to_langchain()
# Optional: Filter by operation type for security
# read_only_tools = toolset.fetch_tools(
# account_ids=[account_id],
# actions=["*_list_*", "*_get_*"] # Only list and get operations
# ).to_langchain()
# Create specialized agents
hr_manager = Agent(
role="HR Manager",
goal="Manage employee data and handle HR requests",
backstory="Expert in human resources with experience in employee management",
tools=tools,
verbose=True
)
recruiter = Agent(
role="Recruiter",
goal="Find and evaluate candidates for open positions",
backstory="Experienced recruiter with talent acquisition expertise",
tools=tools,
verbose=True
)
# Create collaborative tasks
employee_analysis_task = Task(
description="Analyze current employee distribution by department",
agent=hr_manager,
expected_output="Employee distribution report with staffing recommendations"
)
# Execute multi-agent crew
crew = Crew(
agents=[hr_manager, recruiter],
tasks=[employee_analysis_task],
verbose=True
)
return crew
# Usage: Get account from user context
account_id = get_current_user_account() # Your function
crew = create_hr_crew(account_id)
result = crew.kickoff()
print(result)