国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Table of Contents
Introduction
Overview
Table of contents
AI Pair Programmer Capabilities
What is CrewAI?
Prerequisites
Accessing an LLM via API
Example .env File
Required Libraries
Automating Code Creation
Importing Libraries
Defining the Code Writer Agent
Agent Parameters Explained
Defining the Code Writer Task
Task Parameters Explained
Defining the Code Reviewer Agent and Task
Building and Running the Crew
Result Analysis
Automated Code Evaluation
Defining Evaluation Requirements
Using Tools
Setting up Requirement Gathering Agent and Task
Code Evaluation
Building the Evaluation Crew
Output
Conclusion
Frequently Asked Questions
Home Technology peripherals AI Build AI Pair Programmer with CrewAI - Analytics Vidhya

Build AI Pair Programmer with CrewAI - Analytics Vidhya

Apr 09, 2025 am 09:30 AM

Introduction

The demand for efficient software development is driving the adoption of artificial intelligence as a valuable programming partner. AI-powered coding assistants are revolutionizing development by simplifying code writing, debugging, and optimization, much like a human pair programmer. This article demonstrates building an AI pair programmer using CrewAI agents to streamline coding tasks and boost developer productivity.

Overview

This guide covers:

  • Understanding CrewAI's role in assisting coding tasks.
  • Identifying key components: Agents, Tasks, Tools, and Crews, and their interactions.
  • Practical experience setting up AI agents for code generation and review.
  • Configuring multiple AI agents for collaborative coding.
  • Utilizing CrewAI to assess and optimize code quality.

Table of contents

  • Qualitative Examples of NVLM 1.0 D 74B
  • Comparison of NVLM with Other LLMs
  • Limitations of other Multimodal LLMs
  • Addressing those limitations
  • NVLM: Models and Training Methods
  • Training Data
  • Results
  • Accessing NVLM D 72B
    • Importing necessary libraries
    • Model Sharding
    • Image Preprocessing
    • Dynamic image tiling
    • Loading and Preprocessing Images
    • Loading and Using the Model
    • Text and Image Conversations
  • Frequently Asked Questions

AI Pair Programmer Capabilities

An AI pair programmer offers several advantages:

  1. Code generation: Generate code for a given problem using one AI agent and review it with another.
  2. Code improvement: Evaluate existing code based on specified criteria.
  3. Code optimization: Request code enhancements, such as adding comments or docstrings.
  4. Debugging: Receive suggestions for resolving code errors.
  5. Test case generation: Generate test cases for various scenarios, including test-driven development.

This article focuses on the first two capabilities.

What is CrewAI?

CrewAI is a framework for creating AI agents. Its key components are:

  • Agent: An agent uses a large language model (LLM) to produce outputs based on input prompts. It interacts with tools, accepts user input, and communicates with other agents.
  • Task: Defines the agent's objective, including description, agent, and usable tools.
  • Tool: Agents use tools for tasks like web searches, file reading, and code execution.
  • Crew: A group of agents collaborating on tasks, defining interaction, information sharing, and responsibility delegation.

Also Read: Building Collaborative AI Agents With CrewAI

Let's build an agent to illustrate these concepts.

Prerequisites

Before building an AI pair programmer, obtain API keys for LLMs.

Accessing an LLM via API

Generate an API key for your chosen LLM and store it securely in a .env file for project access while maintaining privacy.

Example .env File

A sample .env file:

Build AI Pair Programmer with CrewAI - Analytics Vidhya

Required Libraries

The following library versions are used:

  • crewai – 0.66.0
  • crewai-tools – 0.12.1

Automating Code Creation

This section demonstrates importing libraries and defining agents for code generation and review.

Importing Libraries

from dotenv import load_dotenv
load_dotenv('/.env')

from crewai import Agent, Task, Crew

Defining the Code Writer Agent

One agent generates code, another reviews it.

code_writer_agent = Agent(role="Software Engineer",
                          goal='Write optimized and maintainable code, including docstrings and comments', 
                          backstory="""You are a software engineer writing optimized, maintainable code with docstrings and comments.""",
                          llm='gpt-4o-mini',
                          verbose=True)

Agent Parameters Explained

  • role: Defines the agent's function.
  • goal: Specifies the agent's objective.
  • backstory: Provides context for better interaction.
  • llm: Specifies the LLM used (see LiteLLM documentation for options).
  • verbose: Enables detailed input/output logging.

Defining the Code Writer Task

code_writer_task = Task(description='Write code to solve the problem in {language}. Problem: {problem}',
                        expected_output='Well-formatted code with type hinting',
                        agent=code_writer_agent)

Task Parameters Explained

  • description: Clear task objective with variables ({language}, {problem}).
  • expected_output: Desired output format.
  • agent: The agent assigned to the task.

Defining the Code Reviewer Agent and Task

Similarly, define code_reviewer_agent and code_reviewer_task.

code_reviewer_agent = Agent(role="Senior Software Engineer",
                            goal='Ensure code is optimized and maintainable', 
                            backstory="""You are a senior engineer reviewing code for readability, maintainability, and performance.""",
                            llm='gpt-4o-mini',
                            verbose=True)

code_reviewer_task = Task(description="""Review code written for the problem in {language}. Problem: {problem}""",
                          expected_output='Reviewed code',
                          agent=code_reviewer_agent)

Building and Running the Crew

Create and run the crew:

crew = Crew(agents=[code_writer_agent, code_reviewer_agent], 
            tasks=[code_writer_task, code_reviewer_task], 
            verbose=True)

result = crew.kickoff(inputs={'problem': 'create a tic-tac-toe game', 'language': 'Python'})            

Sample output:

Build AI Pair Programmer with CrewAI - Analytics Vidhya

Build AI Pair Programmer with CrewAI - Analytics Vidhya

Result Analysis

The result object contains:

result.dict().keys()
>>> dict_keys(['raw', 'pydantic', 'json_dict', 'tasks_output', 'token_usage'])

# Token usage
result.dict()['token_usage']
>>> {'total_tokens': 2656, ...}

# Final output
print(result.raw)

The generated code can then be executed.

Build AI Pair Programmer with CrewAI - Analytics Vidhya

Automated Code Evaluation

This section covers evaluating existing code.

Defining Evaluation Requirements

First, gather requirements using an agent, then evaluate the code based on those requirements using another agent.

Using Tools

The FileReadTool reads files. Tools enhance agent capabilities. Tools can be assigned to tasks and agents; task-level assignments override agent-level assignments.

Setting up Requirement Gathering Agent and Task

from crewai_tools import FileReadTool

code_requirements_agent = Agent(role="Data Scientist",
                          goal='Define code requirements for a given problem.', 
                          backstory="""You are a Data Scientist defining requirements for code to solve a problem.""",
                          llm='gpt-4o-mini',
                          verbose=True)

code_requirement_task = Task(description='Write step-by-step requirements. Problem: {problem}',
                            expected_output='Formatted requirements text.',
                            agent=code_requirements_agent,
                            human_input=True)                         

human_input=True allows user input for adjustments.

Code Evaluation

This example uses FileReadTool and gpt-4o for better handling of larger contexts.

file_read_tool = FileReadTool('EDA.py')

code_evaluator_agent = Agent(role="Data Science Evaluator",
                            goal='Evaluate code based on provided requirements', 
                            backstory="""You are a Data Science evaluator reviewing code based on given requirements.""",
                            llm='gpt-4o',
                            verbose=True)

code_evaluator_task = Task(description="""Evaluate the code file based on the requirements.  Provide only the evaluation, not the code.""",
                           expected_output='Detailed evaluation based on requirements.',
                           tools=[file_read_tool],
                           agent=code_evaluator_agent)                            

Building the Evaluation Crew

Create the crew and define the problem:

crew = Crew(agents=[code_requirements_agent, code_evaluator_agent], 
            tasks=[code_requirement_task, code_evaluator_task], 
            verbose=True)

problem = """Perform EDA on the NYC taxi trip duration dataset...""" # (Dataset description omitted for brevity)

result = crew.kickoff(inputs={'problem': problem})

Output

The output shows human input prompts:

Build AI Pair Programmer with CrewAI - Analytics Vidhya

Task outputs can be accessed individually:

print(code_requirement_task.output.raw)
print(result.raw)

Conclusion

CrewAI provides a powerful framework for enhancing software development through AI-driven code generation, review, and evaluation. By defining roles, goals, and tasks, developers can streamline workflows and boost productivity. Integrating an AI pair programmer with CrewAI improves efficiency and code quality. CrewAI's flexibility facilitates seamless AI agent collaboration, resulting in optimized, maintainable, and error-free code. As AI evolves, CrewAI's pair programming capabilities will become increasingly valuable for developers.

Frequently Asked Questions

Q1. What is CrewAI and its role in software development? CrewAI is an AI agent framework assisting developers with code writing, review, and evaluation, boosting productivity.

Q2. What are CrewAI's key components? Agents, Tasks, Tools, and Crews. Agents perform actions; Tasks define objectives; Tools extend agent capabilities; Crews enable agent collaboration.

Q3. How to set up a code-generating AI agent? Define the agent's role, goal, backstory, and LLM, then create a corresponding Task specifying the problem and expected output.

Q4. Can CrewAI agents collaborate? Yes, through "Crews," allowing agents to handle different aspects of a task efficiently.

Q5. What tools are available? Various tools enhance agent capabilities, including file reading, web searches, and code execution.

The above is the detailed content of Build AI Pair Programmer with CrewAI - Analytics Vidhya. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Top 7 NotebookLM Alternatives Top 7 NotebookLM Alternatives Jun 17, 2025 pm 04:32 PM

Google’s NotebookLM is a smart AI note-taking tool powered by Gemini 2.5, which excels at summarizing documents. However, it still has limitations in tool use, like source caps, cloud dependence, and the recent “Discover” feature

From Adoption To Advantage: 10 Trends Shaping Enterprise LLMs In 2025 From Adoption To Advantage: 10 Trends Shaping Enterprise LLMs In 2025 Jun 20, 2025 am 11:13 AM

Here are ten compelling trends reshaping the enterprise AI landscape.Rising Financial Commitment to LLMsOrganizations are significantly increasing their investments in LLMs, with 72% expecting their spending to rise this year. Currently, nearly 40% a

AI Investor Stuck At A Standstill? 3 Strategic Paths To Buy, Build, Or Partner With AI Vendors AI Investor Stuck At A Standstill? 3 Strategic Paths To Buy, Build, Or Partner With AI Vendors Jul 02, 2025 am 11:13 AM

Investing is booming, but capital alone isn’t enough. With valuations rising and distinctiveness fading, investors in AI-focused venture funds must make a key decision: Buy, build, or partner to gain an edge? Here’s how to evaluate each option—and pr

The Unstoppable Growth Of Generative AI (AI Outlook Part 1) The Unstoppable Growth Of Generative AI (AI Outlook Part 1) Jun 21, 2025 am 11:11 AM

Disclosure: My company, Tirias Research, has consulted for IBM, Nvidia, and other companies mentioned in this article.Growth driversThe surge in generative AI adoption was more dramatic than even the most optimistic projections could predict. Then, a

These Startups Are Helping Businesses Show Up In AI Search Summaries These Startups Are Helping Businesses Show Up In AI Search Summaries Jun 20, 2025 am 11:16 AM

Those days are numbered, thanks to AI. Search traffic for businesses like travel site Kayak and edtech company Chegg is declining, partly because 60% of searches on sites like Google aren’t resulting in users clicking any links, according to one stud

New Gallup Report: AI Culture Readiness Demands New Mindsets New Gallup Report: AI Culture Readiness Demands New Mindsets Jun 19, 2025 am 11:16 AM

The gap between widespread adoption and emotional preparedness reveals something essential about how humans are engaging with their growing array of digital companions. We are entering a phase of coexistence where algorithms weave into our daily live

AGI And AI Superintelligence Are Going To Sharply Hit The Human Ceiling Assumption Barrier AGI And AI Superintelligence Are Going To Sharply Hit The Human Ceiling Assumption Barrier Jul 04, 2025 am 11:10 AM

Let’s talk about it. This analysis of an innovative AI breakthrough is part of my ongoing Forbes column coverage on the latest in AI, including identifying and explaining various impactful AI complexities (see the link here). Heading Toward AGI And

Cisco Charts Its Agentic AI Journey At Cisco Live U.S. 2025 Cisco Charts Its Agentic AI Journey At Cisco Live U.S. 2025 Jun 19, 2025 am 11:10 AM

Let’s take a closer look at what I found most significant — and how Cisco might build upon its current efforts to further realize its ambitions.(Note: Cisco is an advisory client of my firm, Moor Insights & Strategy.)Focusing On Agentic AI And Cu

See all articles