PraisonAI icon indicating copy to clipboard operation
PraisonAI copied to clipboard

How to pass in a CSV file

Open jimjcranshaw opened this issue 1 year ago • 1 comments

Is it possible to pass in a CSV list of, for me URLs, but for others maybe something else, and then the agents work through the list each in turn? In which case, how do I code that?

jimjcranshaw avatar Apr 17 '24 13:04 jimjcranshaw

I having a similar problem. I don't know how to pass in a text file from my computer.

scaruslooner avatar Apr 21 '24 19:04 scaruslooner

@claude Please review this issue and provide a solution

MervinPraison avatar May 30 '25 12:05 MervinPraison

Claude encountered an error —— View job


I'll analyze this and get back to you.

claude[bot] avatar May 30 '25 12:05 claude[bot]

@claude Please review this issue and provide a solution

MervinPraison avatar May 30 '25 12:05 MervinPraison

Claude finished @MervinPraison's task —— View jobclaude/issue-23-20250530_125338Create PR ➔


✅ CSV Processing Solution for Issue #23

I've analyzed the codebase and created a comprehensive solution for processing CSV files with PraisonAI agents.

Todo List:

  • [x] Read repository guidelines (CLAUDE.md)
  • [x] Explore existing CSV tools and file processing capabilities
  • [x] Examine agent examples for sequential processing patterns
  • [x] Create example code for CSV processing with agents
  • [x] Document the solution with multiple use cases
  • [x] Test the implementation

Answer: YES, it's absolutely possible!

PraisonAI provides multiple ways to process CSV files with agents working through lists sequentially.

🚀 Quick Solution (Simplest approach)

For your exact use case - processing a CSV list of URLs sequentially:

from praisonaiagents import Agent, Task, PraisonAIAgents

# Create your agent
agent = Agent(
    name="URLProcessor",
    instructions="Analyze each URL from the CSV file"
)

# Create a loop task that processes each CSV row
task = Task(
    description="Process each URL from the CSV",
    agent=agent,
    task_type="loop",           # This enables CSV loop processing
    input_file="your_urls.csv"  # Your CSV file with URLs
)

# Run the agents
agents = PraisonAIAgents(
    agents=[agent],
    tasks=[task],
    process="workflow"
)

agents.start()

📁 CSV File Format

Your CSV can be simple:

url
https://example.com
https://github.com
https://stackoverflow.com

Or with additional columns:

url,description,priority
https://example.com,Example site,high
https://github.com,Code platform,medium

📦 Complete Examples Created

I've created comprehensive examples in the repository:

  1. simple-csv-url-processor.py - Direct solution for your use case
  2. csv-processing-agents.py - 4 different methods including:
    • Simple loop processing (easiest)
    • Manual CSV processing with tools
    • URL-specific processing
    • Advanced processing with validation
  3. CSV_PROCESSING_README.md - Complete documentation

🛠 Built-in CSV Tools Available

PraisonAI includes robust CSV tools:

from praisonaiagents.tools import read_csv, write_csv, merge_csv

# Read CSV files with advanced options
data = read_csv("input.csv", delimiter=",", header=0)

# Write data to CSV
write_csv("output.csv", data)

# Merge multiple CSV files
merge_csv(["file1.csv", "file2.csv"], "merged.csv")

📋 Setup Requirements

  1. Install PraisonAI Agents: pip install praisonaiagents
  2. Set API key: export OPENAI_API_KEY=your_key
  3. Optional: pip install pandas (for advanced CSV operations)

💡 For Text Files

@scaruslooner For text files from your computer, you can:

  1. Convert to CSV format, or
  2. Use file tools to read line by line, or
  3. Process the text file directly with agents

🎯 Key Benefits

  • Sequential Processing: Agents work through each item in order
  • Automatic Looping: Built-in task_type="loop" handles iteration
  • Flexible Input: Support for various CSV formats and columns
  • Error Handling: Robust processing with validation options
  • Multiple Patterns: Choose the approach that fits your needs

The examples are ready to use and demonstrate exactly how to process CSV lists with agents working through each item sequentially!

--- | Branch: claude/issue-23-20250530_125338

claude[bot] avatar May 30 '25 12:05 claude[bot]