Quick Start
Let’s build your first langcrew application! In this tutorial, we’ll create a simple content creation crew with two agents working together.
Prerequisites
Section titled “Prerequisites”- Python 3.10+
- An LLM API key (OpenAI, Anthropic, DashScope, or Google)
Installation
Section titled “Installation”Quick installation with pip:
pip install langcrewexport OPENAI_API_KEY=your_openai_keyWhat We’ll Build
Section titled “What We’ll Build”A content creation system where:
- A Researcher agent gathers information on a topic
- A Writer agent creates an article based on the research
Step 1: Import Required Components
Section titled “Step 1: Import Required Components”from langcrew import Agent, Task, Crewfrom langchain_openai import ChatOpenAI
# Configure LLMllm = ChatOpenAI(model="gpt-4o")Step 2: Create Your Agents
Section titled “Step 2: Create Your Agents”Research Agent
Section titled “Research Agent”researcher = Agent( role="Senior Research Analyst", goal="Gather comprehensive information on the given topic", backstory="""You are an experienced researcher with a keen eye for credible sources and relevant information. You excel at finding and synthesizing data from multiple sources.""", tools=["web_search", "web_fetch"], # Built-in tools llm=llm, verbose=True)Writer Agent
Section titled “Writer Agent”writer = Agent( role="Content Writer", goal="Create engaging and informative content based on research", backstory="""You are a skilled writer who transforms research into compelling narratives. You have a talent for making complex topics accessible to readers.""", llm=llm, verbose=True)Step 3: Define Tasks
Section titled “Step 3: Define Tasks”Research Task
Section titled “Research Task”research_task = Task( description="""Research the topic: 'The Impact of AI on Healthcare'
Your research should include: - Current applications of AI in healthcare - Benefits and challenges - Future possibilities - Real-world examples and case studies
Provide a comprehensive research summary.""", agent=researcher, expected_output="A detailed research report on AI in healthcare")Writing Task
Section titled “Writing Task”writing_task = Task( description="""Using the research provided, write an engaging article about 'The Impact of AI on Healthcare'.
The article should: - Have a compelling introduction - Cover key points from the research - Include specific examples - Be approximately 500 words - End with a thought-provoking conclusion""", agent=writer, context=[research_task], # This task depends on research_task expected_output="A well-written article on AI in healthcare")Step 4: Assemble Your Crew
Section titled “Step 4: Assemble Your Crew”crew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task], verbose=True)Step 5: Execute the Crew
Section titled “Step 5: Execute the Crew”# Start the crew's workresult = crew.kickoff()
# Display the final resultprint("=" * 50)print("FINAL ARTICLE:")print("=" * 50)print(result)Complete Example
Section titled “Complete Example”from langcrew import Agent, Task, Crewfrom langchain_openai import ChatOpenAI
# Configure LLMllm = ChatOpenAI(model="gpt-4o")
# Create agentsresearcher = Agent( role="Senior Research Analyst", goal="Gather comprehensive information on the given topic", backstory="""You are an experienced researcher with a keen eye for credible sources and relevant information.""", tools=["web_search", "web_fetch"], llm=llm, verbose=True)
writer = Agent( role="Content Writer", goal="Create engaging and informative content", backstory="""You are a skilled writer who transforms research into compelling narratives.""", llm=llm, verbose=True)
# Define tasksresearch_task = Task( description="Research the topic: 'The Impact of AI on Healthcare'", agent=researcher, expected_output="A detailed research report")
writing_task = Task( description="Write an engaging article based on the research", agent=writer, context=[research_task], expected_output="A well-written article")
# Create and run crewcrew = Crew( agents=[researcher, writer], tasks=[research_task, writing_task], verbose=True)
result = crew.kickoff()print(result)Customization Options
Section titled “Customization Options”Adding Human Input
Section titled “Adding Human Input”from langcrew_tools.hitl import UserInputTool
agent = Agent( role="Interactive Agent", tools=[UserInputTool()], # ... other parameters)Custom Tools
Section titled “Custom Tools”from langcrew.tools import tool
@tooldef custom_calculator(expression: str) -> str: """Evaluate a mathematical expression.""" try: result = eval(expression) return f"The result is: {result}" except Exception as e: return f"Error: {str(e)}"
agent = Agent( tools=[custom_calculator], # ... other parameters)Tips for Success
Section titled “Tips for Success”- Start Simple: Begin with 2-3 agents and gradually add complexity
- Clear Roles: Give each agent a specific, well-defined role
- Task Dependencies: Use context to share information between tasks
- Iterate: Refine agent prompts and task descriptions based on results
- Monitor Output: Use verbose mode during development to understand agent behavior
Ready to build more complex crews? Check out our advanced examples!