# CrewAI + RentAHuman

Build multi-agent crews with CrewAI that delegate physical tasks to real humans via RentAHuman. Create AI teams that collaborate with human workers.

## CrewAI + RentAHuman: Multi-Agent Human Delegation

CrewAI is a multi-agent orchestration framework where specialized AI agents collaborate as a "crew" to accomplish complex goals. By integrating RentAHuman as a tool, your crew gains the ability to delegate physical-world tasks to real humans — turning your AI team into a hybrid AI-human workforce.

### Why CrewAI + RentAHuman

CrewAI's role-based agent design maps naturally to real-world organizations. You might have a Research Agent that gathers information, a Planning Agent that structures tasks, and a Delegation Agent that hires humans through RentAHuman. This mirrors how companies actually operate: different roles contribute different capabilities, and sometimes the best capability is a pair of human hands. CrewAI's built-in task dependency system ensures humans are hired at the right point in the workflow.

### Installation

```bash
pip install crewai requests
```

### Define the RentAHuman Tool

```python
import requests
from crewai.tools import tool
RENTAHUMAN_API = "https://rentahuman.ai/api"
API_KEY = "rah_your_api_key_here"
headers = {"Content-Type": "application/json", "x-api-key": API_KEY}

@tool("Search Humans on RentAHuman")
def search_humans(query: str, location: str = "") -> str:
    """Search the RentAHuman marketplace for humans available to hire.
    Provide a skill or task description as the query, and optionally a city or region.
    Returns profiles with names, skills, hourly rates, ratings, and availability."""
    params = {"q": query, "limit": 10}
    if location:
        params["location"] = location
    resp = requests.get(f"{RENTAHUMAN_API}/search", params=params, headers=headers)
    return resp.text

@tool("Post a Bounty on RentAHuman")
def create_bounty(title: str, description: str, pay_amount: float, location: str = "") -> str:
    """Post a task bounty on RentAHuman for humans to apply to. Include a clear title,
    detailed description of what needs to be done, the payment amount in USD, and
    the location where the task needs to happen."""
    data = {
        "title": title,
        "description": description,
        "payAmount": pay_amount,
        "payType": "fixed",
        "location": location,
        "isRemote": not bool(location),
    }
    resp = requests.post(f"{RENTAHUMAN_API}/bounties", json=data, headers=headers)
    return resp.text

@tool("Message a Human on RentAHuman")
def start_conversation(human_id: str, message: str) -> str:
    """Start a conversation with a specific human on RentAHuman to discuss task
    details, negotiate terms, or ask questions before hiring them."""
    data = {"humanId": human_id, "message": message}
    resp = requests.post(f"{RENTAHUMAN_API}/conversations", json=data, headers=headers)
    return resp.text

@tool("Get Human Profile")
def get_human_profile(human_id: str) -> str:
    """Retrieve the full profile of a human on RentAHuman including their bio,
    skills, hourly rate, verification status, and reviews from past clients."""
    resp = requests.get(f"{RENTAHUMAN_API}/humans/{human_id}", headers=headers)
    return resp.text
```

### Build the Crew

```python
from crewai import Agent, Task, Crew, Process
# Agent that researches what humans are available
researcher = Agent(
    role="Human Resources Researcher",
    goal="Find the best available humans for physical-world tasks on RentAHuman",
    backstory="""You specialize in finding qualified people for specific tasks.
    You evaluate profiles carefully, considering skills, ratings, location,
    and hourly rates to find the best match.""",
    tools=[search_humans, get_human_profile],
    verbose=True,
)
# Agent that handles hiring and communication
delegator = Agent(
    role="Task Delegator",
    goal="Hire humans and manage task assignments through RentAHuman",
    backstory="""You handle all communication with humans, create bounties for
    open tasks, and ensure tasks are clearly described with fair compensation.
    You write clear, professional messages.""",
    tools=[create_bounty, start_conversation],
    verbose=True,
)
# Agent that plans the overall project
planner = Agent(
    role="Project Planner",
    goal="Break down complex projects into tasks that can be delegated to humans",
    backstory="""You excel at decomposing goals into actionable tasks with clear
    requirements, timelines, and budgets. You understand which tasks need
    physical presence and which can be done remotely.""",
    verbose=True,
)
# Define the tasks
plan_task = Task(
    description="""The user needs a competitive analysis of coffee shops in downtown
    Portland, OR. Plan what physical tasks need to happen — visiting locations,
    photographing storefronts, checking menus and prices, noting ambiance and
    foot traffic. Create a detailed task breakdown with estimated costs.""",
    expected_output="A structured list of physical tasks with requirements and budget estimates",
    agent=planner,
)
research_task = Task(
    description="""Based on the project plan, search RentAHuman for humans in Portland
    who can visit coffee shops, take photos, and collect competitive intelligence.
    Find at least 3 qualified candidates and evaluate their profiles.""",
    expected_output="A shortlist of 3+ qualified humans with their profiles and rates",
    agent=researcher,
    context=[plan_task],
)
hire_task = Task(
    description="""Post a bounty on RentAHuman for the coffee shop competitive analysis
    task in Portland. Use the plan and candidate research to write a compelling bounty
    description with clear deliverables and fair pay.""",
    expected_output="Confirmation of the posted bounty with a link to view applications",
    agent=delegator,
    context=[plan_task, research_task],
)
# Assemble and run the crew
crew = Crew(
    agents=[planner, researcher, delegator],
    tasks=[plan_task, research_task, hire_task],
    process=Process.sequential,
    verbose=True,
)
result = crew.kickoff()
print(result)
```

### Hierarchical Process

For more complex workflows, use CrewAI's hierarchical process where a manager agent coordinates the crew:

```python
from crewai import Crew, Process
from langchain_openai import ChatOpenAI
crew = Crew(
    agents=[planner, researcher, delegator],
    tasks=[plan_task, research_task, hire_task],
    process=Process.hierarchical,
    manager_llm=ChatOpenAI(model="gpt-4o"),
    verbose=True,
)
result = crew.kickoff()
```

### Common Use Cases

- **Market research** — Crew plans research objectives, finds humans near target locations, and hires them to collect data
- **Event planning** — One agent plans logistics, another finds and hires venue scouts, decorators, and photographers
- **Quality assurance** — AI agents analyze product requirements, then hire humans to test physical products in-store
- **Real estate analysis** — Planner identifies properties, researcher finds local humans, delegator hires them for walkthroughs and photos

### Best Practices

- **Separate planning from execution** — Use different agents for planning tasks vs. hiring humans. This produces better task descriptions and more targeted searches.
- **Use task context** — CrewAI's `context` parameter ensures later tasks have access to earlier results. The delegator should always see the planner's output.
- **Set budgets in the task description** — Include budget constraints in the planner's task description so the delegator doesn't overspend.
- **Use sequential process for hiring** — The hiring workflow is naturally sequential (plan → search → hire). Use hierarchical only when you have parallel physical tasks.
- **Include expected_output** — Clear expected outputs help agents stay focused and produce structured results that downstream agents can parse.
