Skip to content

Instantly share code, notes, and snippets.

@Shivakishore14
Created January 27, 2026 20:23
Show Gist options
  • Select an option

  • Save Shivakishore14/2652daff64a7c573bb14ff02e263066c to your computer and use it in GitHub Desktop.

Select an option

Save Shivakishore14/2652daff64a7c573bb14ff02e263066c to your computer and use it in GitHub Desktop.
idea2domain script
#!/usr/bin/env python3
"""LangChain agent-based Streamlit app to find available domain names for your idea."""
import os
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import whois
from whois.exceptions import WhoisDomainNotFoundError, FailedParsingWhoisOutputError
from langchain_google_genai import ChatGoogleGenerativeAI
from langchain_core.tools import tool
from langchain_core.messages import AIMessage
from langchain.agents import create_agent
SYSTEM_PROMPT = """You are a domain name assistant. When users describe ideas:
1. Generate 10 creative domain suggestions
2. Use the check_domain tool to verify availability of each
3. Present results showing which are available vs taken
4. Support follow-up requests for variations or different TLDs
Keep domain names short, memorable, and brandable. Include various TLDs like .com, .io, .co, .app, .dev, .ai, .tech, etc."""
@tool
def check_domain(domain: str) -> str:
"""Check if a domain is available using WHOIS lookup.
Args:
domain: Full domain name (e.g., 'example.com')
Returns:
'available' or 'taken (registrar name)'
"""
try:
w = whois.whois(domain)
if w.domain_name is None:
return "available"
return f"taken ({w.registrar or 'unknown registrar'})"
except WhoisDomainNotFoundError:
return "available"
except FailedParsingWhoisOutputError:
return "available (could not parse WHOIS)"
except Exception as e:
return f"error: {str(e)}"
def main():
st.set_page_config(page_title="Idea2Domain", page_icon="๐ŸŒ")
st.title("๐ŸŒ Idea2Domain")
st.caption("Find available domain names for your idea using AI")
if "messages" not in st.session_state:
st.session_state.messages = []
# Display chat history
for msg in st.session_state.messages:
with st.chat_message(msg["role"]):
st.markdown(msg["content"])
if prompt := st.chat_input("Describe your idea..."):
st.session_state.messages.append({"role": "user", "content": prompt})
with st.chat_message("user"):
st.markdown(prompt)
with st.chat_message("assistant"):
with st.spinner("Finding domains..."):
llm = ChatGoogleGenerativeAI(model="gemini-3-flash-preview")
agent = create_agent(
model=llm,
tools=[check_domain],
system_prompt=SYSTEM_PROMPT
)
# Build messages for the agent
messages = [
{"role": m["role"], "content": m["content"]}
for m in st.session_state.messages
]
result = agent.invoke({"messages": messages})
print(f"DEBUG num messages: {len(result['messages'])}")
for i, msg in enumerate(result["messages"]):
print(f"DEBUG msg[{i}] type: {type(msg).__name__}, content: {msg.content[:200] if isinstance(msg.content, str) else msg.content}")
# Find the last AIMessage with actual text content
response = ""
for msg in reversed(result["messages"]):
if isinstance(msg, AIMessage):
content = msg.content
if isinstance(content, list) and content:
for block in content:
if isinstance(block, dict) and "text" in block:
response = block["text"]
break
if response:
break
elif isinstance(content, str) and content.strip():
response = content
break
print(f"DEBUG final response: {response[:200] if response else 'EMPTY'}")
st.markdown(response)
st.session_state.messages.append({"role": "assistant", "content": response})
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment