Skip to content

chainSAW-crypto/Agentic-learner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Agentic Learner

An intelligent agentic learning application powered by LangChain, LangGraph, and web search capabilities using Groq LLM.

Features

  • πŸ€– Agentic Workflow: Intelligent agent-based processing using LangGraph
  • πŸ” Web Search Integration: Real-time web search capabilities
  • πŸ’¬ Chat API: RESTful API endpoints for querying the agentic workflow
  • πŸ₯ Health Monitoring: Built-in health check endpoint
  • ⚑ Fast Performance: Built with FastAPI and Uvicorn

Project Structure

Agentic-learner/
β”œβ”€β”€ main.py                 # FastAPI application with chat endpoints
β”œβ”€β”€ agents/
β”‚   └── agentic_workflow.py # Core agentic workflow using LangGraph
β”œβ”€β”€ config/
β”‚   └── config.yaml         # Configuration settings
β”œβ”€β”€ prompt_library/
β”‚   └── socrates_p1.py      # Prompt templates
β”œβ”€β”€ tools/
β”‚   β”œβ”€β”€ medium_tool.py      # Medium integration tool
β”‚   └── scraper_tool.py     # Web scraping tool
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ config_loader.py    # Configuration loader
β”‚   β”œβ”€β”€ model_loader.py     # LLM model loader
β”‚   β”œβ”€β”€ scraping.py         # Scraping utilities
β”‚   └── medium_tool_utils.py# Medium tool utilities
β”œβ”€β”€ requirements.txt        # Python dependencies
└── notebook.ipynb          # Jupyter notebook for experimentation

Installation

Prerequisites

  • Python 3.8+
  • Groq API key (set as environment variable GROQ_API_KEY)

Setup

  1. Clone and navigate to the project:

    cd Agentic-learner
  2. Create a virtual environment:

    python -m venv env
    source env/bin/activate  # On Windows: env\Scripts\activate
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up environment variables: Create a .env file in the project root:

    GROQ_API_KEY=your_groq_api_key_here
    

Usage

Running the API Server

Start the FastAPI application:

python main.py

The API will be available at http://localhost:8000

API Documentation

Once the server is running, access the interactive API documentation:

API Endpoints

1. Chat Endpoint

POST /api/chat

Processes user queries through the agentic workflow with web search capabilities.

Request:

{
  "query": "What is quantum computing?"
}

Response:

{
  "query": "What is quantum computing?",
  "response": "Quantum computing is...",
  "message_count": 5
}

2. Health Check Endpoint

GET /health

Check the service status.

Response:

{
  "status": "healthy",
  "service": "agentic-learner"
}

Example Usage

Using cURL:

curl -X POST "http://localhost:8000/api/chat" \
  -H "Content-Type: application/json" \
  -d '{"query": "How does machine learning work?"}'

Using Python:

import requests

response = requests.post(
    "http://localhost:8000/api/chat",
    json={"query": "Explain artificial intelligence"}
)
print(response.json())

Using JavaScript/Fetch:

fetch('http://localhost:8000/api/chat', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({query: 'What is deep learning?'})
})
.then(response => response.json())
.then(data => console.log(data));

Configuration

Edit config/config.yaml to customize:

  • Model provider settings
  • Tool configurations
  • Prompt templates
  • Search parameters

Technologies Used

  • FastAPI: Modern web framework for building APIs
  • LangChain: Framework for developing LLM applications
  • LangGraph: Agentic workflow orchestration
  • Groq: High-performance LLM provider
  • BeautifulSoup4: Web scraping
  • Pydantic: Data validation
  • Uvicorn: ASGI server

Development

Running Jupyter Notebook

Explore the project interactively:

jupyter notebook notebook.ipynb

Project Workflow

  1. User sends a query via the /api/chat endpoint
  2. Request is processed by FastAPI
  3. GraphWorkflow initializes the agentic chain
  4. Agent performs web searches using available tools
  5. LLM (Groq) generates a comprehensive response
  6. Response is returned to the client

Dependencies

See requirements.txt for all dependencies. Key packages:

  • fastapi
  • langchain
  • langgraph
  • groq
  • beautifulsoup4
  • pydantic

Environment Variables

  • GROQ_API_KEY: Your Groq API key for LLM access
  • Additional configuration can be set in config/config.yaml

Error Handling

The API includes built-in error handling:

  • Invalid requests return appropriate HTTP status codes
  • Query processing errors are caught and logged
  • Error messages are included in the response

Performance Notes

  • The workflow is initialized once at startup for efficiency
  • Web searches are performed asynchronously where possible
  • Response times depend on query complexity and web search availability

Future Enhancements

  • Chat history/conversation memory
  • Rate limiting and authentication
  • Caching for repeated queries
  • Multiple model provider support
  • Custom tool integration framework
  • Analytics and usage metrics

Troubleshooting

Issue: GROQ_API_KEY not found

  • Solution: Ensure your API key is set in the .env file or environment variables

Issue: Module not found errors

  • Solution: Run pip install -r requirements.txt to install all dependencies

Issue: Port 8000 already in use

  • Solution: Modify the port in main.py or kill the process using the port

License

[Add your license information here]

Contributing

[Add contribution guidelines here]

Support

For issues or questions, please open an issue on the project repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors