> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackone.com/llms.txt
> Use this file to discover all available pages before exploring further.

# CrewAI Integration

> Build multi-agent AI workflows with StackOne tools and CrewAI

export const GitHubCode = ({url, lang, title, children}) => {
  const urlMatch = url?.match(/https:\/\/github\.com\/([^\/]+)\/([^\/]+)\/blob\/([^\/]+)\/(.+?)(?:#L(\d+)(?:-L(\d+))?)?$/);
  const owner = urlMatch?.[1];
  const repo = urlMatch?.[2];
  const branch = urlMatch?.[3];
  const filePath = urlMatch?.[4];
  const startLine = urlMatch?.[5];
  const endLine = urlMatch?.[6];
  const getDisplayTitle = () => {
    if (title) return title;
    if (!filePath) return 'source';
    const parts = filePath.split('/');
    if (parts.length >= 2) {
      return parts.slice(-2).join('/');
    }
    return parts[parts.length - 1];
  };
  const displayPath = filePath || 'source';
  const displayTitle = getDisplayTitle();
  const lineInfo = startLine ? endLine ? `#L${startLine}-L${endLine}` : `#L${startLine}` : '';
  const fullUrl = url + (lineInfo && !url.includes('#L') ? lineInfo : '');
  const encodedUrl = encodeURIComponent(fullUrl);
  const iframeSrc = `https://emgithub.com/iframe.html?target=${encodedUrl}&style=github&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on`;
  return <div style={{
    marginTop: '1.5rem',
    marginBottom: '1.5rem',
    border: '1px solid #e5e7eb',
    borderRadius: '0.75rem',
    overflow: 'hidden',
    boxShadow: '0 1px 3px 0 rgb(0 0 0 / 0.1)'
  }}>
      <div style={{
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    padding: '1rem 1.25rem',
    backgroundColor: '#f9fafb',
    borderBottom: '1px solid #e5e7eb'
  }}>
        <div style={{
    display: 'flex',
    alignItems: 'center',
    gap: '0.75rem'
  }}>
          <svg width="22" height="22" viewBox="0 0 24 24" fill="currentColor" style={{
    flexShrink: 0
  }}>
            <path d="M12 0c-6.626 0-12 5.373-12 12 0 5.302 3.438 9.8 8.207 11.387.599.111.793-.261.793-.577v-2.234c-3.338.726-4.033-1.416-4.033-1.416-.546-1.387-1.333-1.756-1.333-1.756-1.089-.745.083-.729.083-.729 1.205.084 1.839 1.237 1.839 1.237 1.07 1.834 2.807 1.304 3.492.997.107-.775.418-1.305.762-1.604-2.665-.305-5.467-1.334-5.467-5.931 0-1.311.469-2.381 1.236-3.221-.124-.303-.535-1.524.117-3.176 0 0 1.008-.322 3.301 1.23.957-.266 1.983-.399 3.003-.404 1.02.005 2.047.138 3.006.404 2.291-1.552 3.297-1.23 3.297-1.23.653 1.653.242 2.874.118 3.176.77.84 1.235 1.911 1.235 3.221 0 4.609-2.807 5.624-5.479 5.921.43.372.823 1.102.823 2.222v3.293c0 .319.192.694.801.576 4.765-1.589 8.199-6.086 8.199-11.386 0-6.627-5.373-12-12-12z" />
          </svg>
          <span style={{
    fontWeight: 600,
    fontSize: '0.9375rem'
  }}>{displayTitle}</span>
        </div>
        {url && <a href={url} target="_blank" rel="noopener noreferrer" style={{
    fontSize: '0.875rem',
    color: '#3b82f6',
    textDecoration: 'none',
    fontWeight: 500
  }}>
            View on GitHub →
          </a>}
      </div>
      <div style={{
    padding: '0.5rem',
    minHeight: '400px',
    backgroundColor: '#ffffff'
  }}>
        {children || <iframe src={iframeSrc} style={{
    width: '100%',
    height: '420px',
    border: 'none',
    borderRadius: '0.25rem'
  }} loading="lazy" />}
      </div>
    </div>;
};

Build sophisticated multi-agent AI systems where specialised agents collaborate to complete complex business tasks using StackOne's infrastructure of thousands of turnkey tools, RPC orchestration, and MCP/A2A entry points.

<Warning>
  CrewAI may have compatibility issues with StackOne's LangChain tools depending on your CrewAI and pydantic versions. If you encounter a `ValidationError` for `BaseTool`, check for version updates or use the [OpenAI integration](/agents/python/frameworks/openai-integration) instead.
</Warning>

## Overview

* **Multi-agent collaboration** with business data access
* **Specialized agents** for different business functions
* **Complex workflow automation** with task dependencies
* **Enhanced error handling** and monitoring

```python theme={null}
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,
        llm="gpt-5.4",
        verbose=True
    )

    recruiter = Agent(
        role="Recruiter",
        goal="Find and evaluate candidates for open positions",
        backstory="Experienced recruiter with talent acquisition expertise",
        tools=tools,
        llm="gpt-5.4",
        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
# Get account ID from your app's auth context or StackOne dashboard
account_id = "your-account-id"
crew = create_hr_crew(account_id)
result = crew.kickoff()
print(result)
```

## Example

<GitHubCode url="https://github.com/StackOneHQ/stackone-ai-python/blob/main/examples/crewai_integration.py" lang="python">
  <iframe src="https://emgithub.com/iframe.html?target=https%3A%2F%2Fgithub.com%2FStackOneHQ%2Fstackone-ai-python%2Fblob%2Fmain%2Fexamples%2Fcrewai_integration.py&style=github&type=code&showBorder=on&showLineNumbers=on&showFileMeta=on" style={{ width: '100%', height: '400px', border: 'none' }} loading="lazy" />
</GitHubCode>
