A workflow demonstrating how the Programming Agent can analyze, generate, execute, and debug code.

Quick Start

1

Install Package

First, install the PraisonAI Agents package:

pip install praisonaiagents
2

Set API Key

Set your OpenAI API key as an environment variable:

export OPENAI_API_KEY=your_api_key_here
3

Create Script

Create a new file code_assistant.py:

from praisonaiagents import Agent, Tools
from praisonaiagents.tools import execute_code, analyze_code, format_code, lint_code, disassemble_code # Code Tools
from praisonaiagents.tools import execute_command, list_processes, kill_process, get_system_info # Shell Tools
from praisonaiagents.tools import duckduckgo # Web Search Tool

agent = Agent(
    instructions="You are a Programming Agent", self_reflect=True, min_reflect=5, max_reflect=10, 
    tools=[execute_code, analyze_code, format_code, lint_code, disassemble_code, execute_command, list_processes, kill_process, get_system_info, duckduckgo]
)
agent.start(
    "Write a python script using yfinance to find the stock price of Tesla"
    "First check if required packages are installed"
    "Run it using execute_code"
    "execute_command if you want to run any terminal command"
    "search internet using duckduckgo if you want to know update python package information"
    "Analyse the output using analyze_code and fix error if required"
    "if no package is installed, install it"
    "then run the code"
)

Understanding Code Development

The Programming Agent combines multiple tools for comprehensive code development:

  1. Code Tools:

    • execute_code: Run Python code
    • analyze_code: Analyze code structure
    • format_code: Format code to standards
    • lint_code: Check code quality
    • disassemble_code: View bytecode
  2. Shell Tools:

    • execute_command: Run terminal commands
    • list_processes: View running processes
    • kill_process: Terminate processes
    • get_system_info: System information
  3. Web Tools:

    • duckduckgo: Search for programming resources

Features

Code Execution

Run and test code directly.

Code Analysis

Analyze and improve code quality.

System Integration

Execute system commands and manage processes.

Package Management

Handle dependencies and installations.

Example Usage

# Example: Create and run a data analysis script
response = agent.start("""
    1. Create a script that:
       - Uses pandas for data analysis
       - Reads a CSV file
       - Performs basic statistics
       - Creates a visualization
    2. Check and install required packages
    3. Execute and analyze the results
""")

Next Steps

Was this page helpful?