An intelligent AI agent built with LangChain and Google Gemini that extracts company information from textual essays and generates structured CSV output. This project demonstrates the implementation of LCEL Runnable Interface, Tools, Tool Calling and Agentic workflows.
- Structured Data Extraction: Extract company names, founding dates and founders from text
- AI Agent Workflow: Autonomous agent using ReAct pattern with tool calling
- Multiple Extraction Methods: Both agent-based and direct structured extraction
- Smart Date Formatting: Handles various date formats with intelligent defaults
- CSV Generation: Automated output in specified format
- Streaming Capabilities: Real-time processing feedback
- Error Handling: Robust error management throughout the pipeline
- Batch Processing: Individual paragraph processing for large texts
- Python 3.8 or higher
- Google Gemini API Key
- Required packages (see installation)
-
Open the project with Google Colab:
- Visit Google Colab
-
Make your own copy:
- Once the notebook opens, click "File" → "Save a copy in Drive"
- This creates your personal copy that you can edit and run
-
Get your Google Gemini API Key:
- Visit Google AI Studio
- Sign in with your Google account
- Click "Get API key" → "Create API key in new project"
- Copy your API key
-
Set up your API key in Colab:
- Go to the 🔑 Secrets tab in the left sidebar of your Colab notebook
- Add a new secret named
GEMINI_API_KEY - Paste your API key as the value
- Enable notebook access by toggling the switch
-
Run the notebook:
- The required packages will be installed automatically in the first cell
- Execute cells step by step to see the AI agent in action!
- Watch as it extracts company information and generates a CSV file
-
Clone the repository and install dependencies:
git clone https://github.com/anurag-adk/CSVision cd CSVision pip install langchain-google-genai langchain langgraph pandas pydantic -qU -
Set up environment variables:
export GOOGLE_API_KEY=your_gemini_api_key
| Component | Description | Technology |
|---|---|---|
| Structured Output | Type-safe data extraction | Pydantic Models |
| Tools | Custom extraction and CSV tools | @tool decorator |
| Agent | Autonomous task execution | LangGraph ReAct Agent |
| Date Processing | Smart date format handling | Custom regex logic |
| CSV Generation | Automated file output | Pandas DataFrame |
- Structured Output Chains: Using
llm.with_structured_output()for type-safe extraction - Chain Composition: Building processing pipelines with LangChain components
- Custom Tools: Extraction and CSV generation tools using
@tooldecorator - Agent Integration: Tools accessible by AI agent for autonomous execution
- ReAct Pattern: Reasoning and Acting agent for complex task execution
- Tool Orchestration: Intelligent selection and usage of available tools
- Message-based Communication: Structured interaction using HumanMessage/AIMessage
class CompanyInfo(BaseModel):
company_name: str = Field(..., description="The full official company name")
founding_date: str = Field(..., description="The founding date")
founders: List[str] = Field(..., description="List of founder names")- Input Validation: Robust error checking for all inputs
- Graceful Degradation: Fallback mechanisms for edge cases
- User-friendly Messages: Clear error communication
- Text Input: Essay or paragraph containing company information
- AI Analysis: LLM analyzes text and identifies company mentions
- Structured Extraction: Pydantic models ensure type-safe data extraction
- Date Processing: Smart formatting handles various date formats
- CSV Generation: Automated creation of properly formatted output
- Validation: Quality checks and error handling throughout
- Agent-based: Autonomous execution with tool calling
- Direct Extraction: Structured output without agent overhead
- Paragraph Processing: Individual chunk processing for large texts
- Partial Dates: Year-only formats default to January 1st
- Natural Language: "May 8, 1886" → "1886-05-08"
- Format Standardization: All outputs in YYYY-MM-DD format
- Real-time Feedback: Live processing updates
- Interactive Analysis: Stream-based text analysis
- Progress Monitoring: Visual feedback during long operations
A Special Thank You To Our Mentors and Facilitators at Leapfrog especially Kalash Shrestha dai