This project presents an autonomous AI agent designed specifically for mental health support, with a focus on Complex Post-Traumatic Stress Disorder (CPTSD). The system transforms clinical therapeutic knowledge into accessible visual content through a novel multi-stage pipeline that extracts insights from textual sources, generates corresponding nature-themed imagery, and autonomously distributes content via social media channels. Operating with minimal human intervention, this agentic system demonstrates how AI can bridge the gap between clinical resources and individuals seeking healing support in their daily lives.
Mental health resources are often locked in dense clinical literature, making them inaccessible to many who could benefit from them. This project addresses this challenge by building an autonomous agent that:
The real-world application of this system can be seen on the Trauma Healed Instagram account, where it consistently delivers therapeutic content to a community of individuals seeking support for trauma recovery.
The system operates as a cohesive agent with four primary components that function in an autonomous workflow:
Processes therapeutic literature to identify and extract meaningful insights
Transforms extracted content into concise, social media-friendly therapeutic messages
Creates nature-themed imagery that complements and enhances the therapeutic message
Manages content storage and social media posting through cloud infrastructure
A significant challenge in this project was the computational resource constraints that prevented implementing a full Retrieval-Augmented Generation (RAG) system. Traditional approaches would require:
Instead of a traditional RAG approach, the system implements an innovative progressive PDF processing method that:
This approach allows the system to process comprehensive therapeutic resources with minimal computational overhead while maintaining contextual understanding, demonstrating how resourceful engineering can overcome infrastructure limitations.
# Innovative PDF tracking and processing system def get_and_update_current_page(file_path, increment=3): try: with open(file_path, 'r') as file: current_page = int(file.read().strip()) except FileNotFoundError: current_page = 0 # Default starting page if file not found new_current_page = current_page + increment with open(file_path, 'w') as file: file.write(str(new_current_page)) return current_page, new_current_page def extract_section_from_pdf(pdf_path, start_page, end_page): text = "" with pdfplumber.open(pdf_path) as pdf: pages = pdf.pages[start_page:end_page] for page in pages: text += page.extract_text() + "\n" return text
This innovation demonstrates that effective AI solutions don't always require expensive infrastructure—thoughtful design that works within constraints can achieve impressive results.
The system leverages the LangChain framework and OpenAI's language models to extract and transform therapeutic content:
from langchain_openai import ChatOpenAI from langchain_core.prompts import ChatPromptTemplate from langchain_core.output_parsers import StrOutputParser # Initializing the language model llm = ChatOpenAI(openai_api_key=api_key, max_tokens=100, temperature=0.8) # Creating a specialized therapeutic prompt template prompt = ChatPromptTemplate.from_messages([ ("system", "You are a CPTSD Therapist with 20 plus years experience in healing people from CPTSD."), ("user", "{input}"), ]) # Building the processing chain chain = prompt | llm | StrOutputParser() # Processing the extracted PDF content response = chain.invoke({ "input": "write a 20 words inspirational quote for a person suffering from cptsd that would heal them, from the following text" + pdf_text })
The system transforms therapeutic quotes into complementary visual imagery using DALL-E:
from langchain.chains import LLMChain from langchain.prompts import PromptTemplate from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper from langchain_openai import OpenAI # Defining the prompt template for DALL-E image generation prompt_template = PromptTemplate( input_variables=["quote"], template="Create an inspiring, hopeful, and positive image for instagram without including any text in the image, also do not include any human beings, just make it therapeutic and full of nature image: {quote}", ) # Generating the image prompt chain = LLMChain(llm=llm, prompt=prompt_template) prompt = chain.run({"quote": quote}) # Generating the therapeutic image image_url = DallEAPIWrapper().run(prompt)
The final component handles automated content distribution through AWS S3 and webhook integration:
# Uploading to AWS S3 s3_client = boto3.client('s3', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, region_name=region_name) s3_client.upload_file(file_path, bucket_name, s3_file_path) # Generating the URL of the uploaded file s3_object = s3_resource.Object(bucket_name, s3_file_path) s3_url = s3_object.meta.client.generate_presigned_url('get_object', Params={'Bucket': bucket_name, 'Key': s3_file_path}, ExpiresIn=10000) # Notifying webhook for social media posting payload = {'file_url': s3_url} response = requests.post(webhook_url, json=payload)
The system incorporates robust error handling mechanisms to ensure continuous operation, particularly in the image generation process which can be sensitive to prompt guidelines:
max_retries = 3 # Setting maximum number of retries attempt = 0 while attempt < max_retries: try: # Image generation process image_url = DallEAPIWrapper().run(prompt) break # If success, break out of the loop except Exception as e: attempt += 1 print(f"Attempt {attempt} failed with error: {e}") if attempt == max_retries: print("Max retries reached, failing gracefully.")
This approach ensures that temporary failures don't disrupt the autonomous workflow, maintaining system reliability.
The system has been successfully deployed to support the Trauma Healed Instagram account, where it autonomously generates and publishes therapeutic content. Key achievements include:
The system generates content like this therapeutic quote paired with a nature-based image:
"Healing from CPTSD is a gradual process, but with trust, self-compassion, and resilience, you can reclaim your life."
[Accompanied by a serene forest scene with a stream and sunset]
Ensuring that both quote generation and image creation maintained therapeutic integrity and quality.
Solution: Carefully crafted prompt templates that incorporate therapeutic expertise and domain knowledge, with tight constraints on output format (e.g., 20-word quotes) to ensure consistency.
Operating within budget constraints that prevented implementing full-scale RAG or similar advanced retrieval systems.
Solution: The innovative progressive PDF processing approach that maintains context while working with small chunks of content, demonstrating that clever engineering can overcome resource limitations.
Ensuring reliable delivery of content from generation to social media posting.
Solution: Implementation of AWS S3 as a stable intermediary storage solution combined with webhook integration for flexible posting mechanisms, creating a reliable autonomous pipeline.
Future development of the agentic system will focus on:
This project demonstrates the potential of agentic AI systems to transform mental health support by making therapeutic resources more accessible and engaging. By combining content extraction, generation, and distribution in an autonomous workflow, the system bridges the gap between clinical knowledge and individuals seeking healing support.
The innovative approach to resource constraints showcases that effective AI solutions don't necessarily require expensive infrastructure—thoughtful design and creative problem-solving can achieve meaningful results even with limited resources. As this system continues to evolve, it has the potential to reach and support even more individuals on their healing journeys from trauma and CPTSD.
Special thanks to Pete Walker's work on CPTSD, DR Russell Kennedy and the trauma therapy community for their guidance on creating supportive content, and to the users who have provided feedback on the generated resources.
There are no models linked
There are no datasets linked
There are no datasets linked