You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`
import os
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from dotenv import load_dotenv
load_dotenv(override=True)
from mcp.server.fastmcp import FastMCP
carosel_mcp = FastMCP("API_Server")
GPT_MODEL = os.getenv("GPT_MODEL")
CAROUSEL GENERATION
@carosel_mcp.tool()
async def create_carousel(text: str, tone_level: int, user_prompt: str, trace = None) -> str:
print("INFO: Creating carousel...")
#create langchain handler from trace
handler = None
if trace is not None:
handler=trace.get_langchain_handler()
llm = ChatOpenAI(model=GPT_MODEL, temperature=0.4, max_retries=3)
prompt = PromptTemplate(
input_variables=["text", "tone_level","user_prompt"],
template="""
You are a skilled B2B social media content strategist, helping users generate high-quality, engaging LinkedIn carousel posts based on case studies.
<case study text>
CASE STUDY:
{text}
</case study text>
<tone level>
TONE LEVEL: {tone_level}
</tone level>
<user prompt>
ADDITIONAL USER PROMPT: {user_prompt}
</user prompt>
**IMPORTANT VALIDATION RULES**:
- You must validate if the case study text contains meaningful details for each section:
1. Objective/Objectives
2. Solution/Solutions
3. Business Impact
- If sufficient data for a section is missing, do NOT fabricate content.
- Instead, return a with the following format for that section:
"Insufficient data for [section name]."
**INSTRUCTIONS**:
- Use the tone level (1–5) provided above to shape the voice, where 1 is technical and 5 is narrative/storytelling.
**STRICT GUARDRAILS**:
- You MUST extract objective(s), solution(s), and impact point(s) ONLY from the case study text.
- Do NOT use internal/custom API, agent, or tool names in the response, Instead add what those tools achieve (their outcomes or value) instead of naming them.
- Do NOT invent, assume, or add extra content not present in the case study.
- Headlines and subtitles should be engaging but still faithful to the case study’s context.
- Impacts in Slide 3 must be **directly measurable outcomes or benefits mentioned in the case study**.
- Do not generalize with vague statements like "Improved efficiency" unless explicitly stated in the case study.
- Avoid the use of sensitive, confidential, or proprietary information.
**TONE CLARIFICATION TABLE**:
Tone Level 1 – Very Technical:
- Description: Deep-dive, jargon-heavy
- Ideal For: Tech leads, Architects
- Example: "We integrated a cloud-native ETL pipeline using Kubernetes and Terraform for auto-scaled processing."
Tone Level 2 – Technical but Conversational:
- Description: Balanced tone, light jargon
- Ideal For: CTOs, Senior Engineers
- Example: "Our solution automated data pipelines using modern cloud-native tools—saving 40% infra cost."
Tone Level 3 – Business-Friendly:
- Description: Value-focused, minimal jargon
- Ideal For: CXOs, Business Heads
- Example: "We streamlined operations and cut cloud costs by 40% with a data automation strategy."
Tone Level 4 – Executive:
- Description: Vision-driven, results-first
- Ideal For: CEOs, Cloud Partners
- Example: "Our automation-led approach translated into rapid digital transformation and 3x ROI."
Tone Level 5 – Narrative / Storytelling:
- Description: Relatable, human, emotional
- Ideal For: General audience, social storytelling
- Example: "Imagine saving weeks of manual effort with one simple change. That’s what this brand achieved."
**CAROUSEL GENERATION**:
- Identify the challenge, solution, and business impact from the case study text.
- Create a 3-slide carousel.
Slide 1: Headline hook + subtitle (designed to grab attention).
Slide 2: High-level solution overview. Objective should always have solution and objectives should always have solutions as the headers.
If the header is objectives: Always list the objectives and the solutions in 3 bullet points each, never in paragraph form. These bullet points should be indicated using hyphens.
If the header is objective: Keep the objective to 2–3 lines and the solution to 3-4 lines. The objective and solution stay in a paragraph form of 2-3 lines.
Slide 3: Headline “Business Impact” + Impact summary with at least 3–5 non-redundant bullet points, encouraging users to visit the detailed HTML case study. Do NOT mention the words “case study” in the bullet points.
Here is an example generate the carousel in a similar fashion. All the information should be taken from the case study text:
**Slide 1**:
Headline: How can multi-cloud architecture turn legacy challenges into business wins?
Subtitle: A Unified Platform for Greater Impact
**Slide 2**:
Objective: The client was struggling with a rigid legacy system that impacted scalability, compliance, and user experience. They needed a modern, flexible infrastructure to stay competitive.
Solution: We migrated their systems to a scalable, multi-cloud setup using GCP, Azure, and AWS—ensuring zero disruption through agile execution and complete automation.
OR
Objectives: - Overcome the limitations of a rigid legacy system that hindered scalability. - Ensure compliance with evolving industry standards and regulatory requirements. - Improve overall user experience to maintain a competitive edge.
Solutions: - Migrated infrastructure to a modern, scalable multi-cloud setup across GCP, Azure, and AWS. - Executed the transition with agile methodologies to ensure zero disruption to operations. - Automated deployment and monitoring processes for improved efficiency and control.
**Slide 3**:
Headline: Business Impact
Body:
- 60 '%' faster reporting
- Real-time performance tracking
- KPI alignment across teams
- Reduced analyst dependency
- Proactive issue detection
**HASHTAGS**:
- Generate 3–5 relevant hashtags.
- Use CamelCase with no spaces (e.g., #CloudComputing, #DigitalTransformation).
**DOMAIN**: You must select exactly one domain from the following list, based solely on the context of the case study text:
['AWS', 'Cloud', 'FinTech', 'GenAI', 'HCLS', 'HiTech', 'M&A', 'Retail', 'SCL', 'T&H']
Use the following keyword mapping to guide your choice:
"AWS": ["aws", "amazon web services"],
"Cloud": ["cloud", "cloud-native", "multi-cloud", "cloud migration"],
"FinTech": ["fintech", "banking", "financial", "payments", "insurance"],
"GenAI": ["gen ai", "generative ai", "llm", "language model"],
"HCLS": ["healthcare", "life sciences", "pharma", "clinical", "patient"],
"HiTech": ["semiconductor", "hardware", "hitech", "electronics", "iot"],
"M&A": ["merger", "acquisition", "m&a", "corporate deal"],
"Retail": ["retail", "ecommerce", "shopping", "consumer"],
"SCL": ["supply chain", "logistics", "warehouse", "inventory"]
"T&H": ["travel", "hospitality", "airline", "tourism", "hotel"],
As per the case study content, choose the **most relevant** domain from this list and include only the domain name (not the keywords or explanations) in the output JSON under the key `"Domain"`.
**OBJECTIVE**: You must state wether there was only one objective or many. Include this in the output JSON under the key `"Objective"` with either "one" or "many".
**SOLUTION**: You must state if the solution is in a paragraph or list format. Include this in the output JSON under the key `"Solution"` with either "paragraph" or "list".
**Output JSON**:
{{
"Headline": "...",
"Hashtags": ["...", "..."],
"Slide_1_Text": "Headline:..., Subtitle:...",
"Slide_2_Text": "Objectives:..., Solutions:...",
"Slide_3_Text": "Headline:..., Body:...",
"Domain": "...",
"Objective": "...",
"Solution": "..."
}}
**final note**:
- Output must strictly follow the JSON schema above.
- Do not include any additional commentary, explanations, or introductory text (e.g., do not write “Here is the JSON:”).
- Return only the JSON output, nothing else.
"""
)
# return (prompt | llm).invoke({"text": text[:4000], "tone_level": str(tone_level), "user_prompt": user_prompt}).content
input_data = {"text": text, "tone_level": str(tone_level), "user_prompt": user_prompt}
# print("INFO: Input data:", input_data)
print("INFO: Tone level:", tone_level)
print("INFO: User prompt:", user_prompt)
#use the handler for callbacks
result = (prompt | llm).invoke(input_data, config={"callbacks":[handler] if handler else []})
final_result = result.content.strip()
#update trace with the result obtained from llm
if trace is not None:
trace.update(input=input_data,output=final_result)
print("RESPONSE: Extracted content:", final_result)
return final_result
if name == "main":
carosel_mcp.run(transport="streamable-http")
`
above is my server code , was facing issue while creating client for this , want langgraph agent to commnunicate with the abover server with transport protocol as streamable http, Thanks :)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
`
import os
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from dotenv import load_dotenv
load_dotenv(override=True)
from mcp.server.fastmcp import FastMCP
carosel_mcp = FastMCP("API_Server")
GPT_MODEL = os.getenv("GPT_MODEL")
CAROUSEL GENERATION
@carosel_mcp.tool()
async def create_carousel(text: str, tone_level: int, user_prompt: str, trace = None) -> str:
print("INFO: Creating carousel...")
#create langchain handler from trace
handler = None
if trace is not None:
handler=trace.get_langchain_handler()
if name == "main":
carosel_mcp.run(transport="streamable-http")
`
above is my server code , was facing issue while creating client for this , want langgraph agent to commnunicate with the abover server with transport protocol as streamable http, Thanks :)
Beta Was this translation helpful? Give feedback.
All reactions