This project is an AI-powered automation tool for generating professional company letters and exporting them to Google Docs. It features a FastAPI backend, a modern chat-based frontend, and deep integration with Google Drive and OpenAI (or compatible LLMs) via LangChain.
report_agent copy/
├── backend/
│   ├── app.py                        # FastAPI backend entrypoint and API endpoints
│   ├── letter_agent.py               # Core automation logic for letter generation (LangChain agent)
│   ├── google_docs.py                # Google Docs API integration for document creation
│   ├── client_secret.json            # [PLACEHOLDER] Google OAuth client credentials (do not commit real secrets)
│   ├── report-agent-...json          # [PLACEHOLDER] Google service account credentials (do not commit real secrets)
│          
├── frontend/
│   └── main.html                     # Modern chat UI for interacting with the agent
└──              
- 
Clone the repository
 - 
Install dependencies
pip install -r requirements.txt
 - 
Configure credentials
- Place your Google OAuth and service account credentials in 
backend/client_secret.jsonandbackend/report-agent-...json(see the provided placeholder files for structure). - Set your OpenAI or compatible API key as an environment variable (
OPENAI_API_KEY). - Update any other placeholders in 
letter_agent.pyandgoogle_docs.py(e.g., Google Drive folder IDs, template IDs). 
 - Place your Google OAuth and service account credentials in 
 - 
Run the backend
uvicorn backend.app:app --reload
 - 
Open the frontend
- Open 
frontend/main.htmlin your browser. - Ensure the backend is running at 
http://localhost:8000(or update the API URL in the HTML if needed). 
 - Open 
 
- The user interacts with a chat interface (
frontend/main.html), sending prompts describing the letter they want to generate. 
- The frontend sends the user's message to the 
/chatendpoint of the FastAPI backend (backend/app.py). 
- The backend manages conversation state and delegates the request to a 
LetterGenerationAgent(seebackend/letter_agent.py). - The agent uses LangChain's ReAct framework, combining:
- Company context: Loads relevant documents from Google Drive (via 
GoogleDriveLoader). - LLM reasoning: Uses OpenAI (or compatible) LLM to generate letter content, recipient details, and role.
 - Custom tools:
get_current_datetime: Fetches the current date/time.get_company_context: Extracts company/recipient info from loaded docs.generate_formal_letter: Assembles a formal letter using a template and LLM-generated content.create_google_doc_from_letter: Converts the letter into a Google Doc and returns the shareable URL.
 
 - Company context: Loads relevant documents from Google Drive (via 
 - The agent follows a workflow:
- Extract recipient info from company docs.
 - Generate main content and role using the LLM.
 - Assemble the letter in a formal template.
 - Optionally, create a Google Doc and return the link.
 
 
- The backend returns the generated letter (and optionally a Google Doc link) to the frontend, which displays it in the chat.
 
GET /— Health checkPOST /chat— Main chat endpoint (send user prompt, get letter response)POST /new-conversation— Start a new chat sessionDELETE /conversation/{conversation_id}— Delete a sessionGET /conversations— List all active sessions
See requirements.txt for all dependencies. Key packages:
fastapi,uvicorn— API serverlangchain,langchain-openai,langchain-google-community— LLM and tool orchestrationopenai— LLM APIgoogle-auth,google-api-python-client,google-auth-oauthlib— Google Docs/Drive integrationpython-dotenv— Environment variable management
Built by Shilok Kumar
