TL;DR
Building with AI is fun, but it's more fun when you can solve real problems like creating a clone/MVP of a trending app.
In this blog, I will walk you through building your own AI bot that can
- Find an interesting product on HackerNews
- Analyse the website
- Build a clone of it
Tech Stack
Composio - For integrating the external tools and services with AI
Composio is the integration platform with over 250+ application support for building complex agentic flows. It takes care of all the authentication troubles so you can focus on building agents.
This blog will use HackerNews, CodeInterpreter, File tool, and shell tool integrations.
LangGraph - Agentic framework
An agentic framework from LangChain lets you define workflows regarding graphs and nodes. It is ideal for building agents for production with maximum control.
OpenAI - Inference provider
For LLM inferencing. We'll use the GPT-4o model. You may use other models or providers like Claude, Gemini, Deepseek, etc. You might get even better results for complex use cases.
Workflow
The flow is effortless and straightforward.
Flow:
- Agent receives user instructions.
- Automatically decides which tools to use.
- No manual intervention is needed once they started
- Follows a straightforward, sequential process
Tool Selection:
- Agent intelligently picks appropriate tools for each task
- HackerNews tool for research
- Code Interpreter for implementation
- Web and Shell tools for execution
- File tools for handling data
HackerNews Research Process:
- Scans through Show HN feed
- Identifies interesting projects
- Evaluate the feasibility of MVP creation
- Select the most promising idea
MVP Creation:
- Takes the chosen idea
- Creates a simplified version
- Implements core functionality
- Delivers working prototype
- Executes and demonstrates results
Next, Create aΒ .env
Β file and add environment variables for the OpenAI API key.
OPENAI_API_KEY=your API key
To create an OpneAI API key, go to the official site and create an API key in the dashboard.
Set up Composio
Next, you need to log in and authenticate with Composio.
composio login
This will open a tab asking you to log in. You can log in with GitHub, Gmail, or any Email ID.
Upon logging in, a screen with a key will appear.
Copy it and paste it into the terminal.
Now, update apps.
composio apps update
Setting up Environment
Create requirements.txt file
composio-langgraph
langgraph
langchain-groq
langchain-openai
python-dotenv
The next step is to set up your virtual environment.
Create a setup.sh
account and paste the following code.
#!/bin/bash
# Create a virtual environment
echo "Creating virtual environment..."
python3 -m venv ~/.venvs/indie_hacker
# Activate the virtual environment
echo "Activating virtual environment..."
source ~/.venvs/indie_hacker/bin/activate
# Install libraries from requirements.txt
echo "Installing libraries from requirements.txt..."
pip install -r requirements.txt
# Copy env backup to .env file
if [ -f ".env.example" ]; then
echo "Copying .env.example to .env..."
cp .env.example .env
else
echo "No .env.example file found. Creating a new .env file..."
touch .env
fi
# Prompt user to fill the .env file
echo "Please fill in the .env file with the necessary environment variables."
echo "Setup completed successfully!"
Coding the AI agent
Start by importing all the necessary libraries and modules.
from composio import Composio, ComposioToolSet
import os
from dotenv import load_dotenv
from langchain_groq import ChatGroq
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from typing import Annotated
from langchain_core.messages import BaseMessage
from typing_extensions import TypedDict
from composio_langgraph import Action, ComposioToolSet, App
from langgraph.graph import StateGraph, START, END
from langgraph.graph.message import add_messages
from langgraph.prebuilt import ToolNode, tools_condition
load_dotenv()
1. State Management and Initialization
pythonCopyclass State(TypedDict):
messages: Annotated[list, add_messages]
graph_builder = StateGraph(State)
This sets up our agent's state management system. Think of it as a structured way to track conversations - it maintains a record of all messages and helps manage the flow of information throughout the system.
2. Tool Integration
pythonCopytoolset = ComposioToolSet()
tools = toolset.get_tools(apps=[
App.CODEINTERPRETER,
App.FILETOOL,
App.HACKERNEWS,
App.SHELLTOOL,
App.WEBTOOL
])
Here, we're setting up our agent's capabilities using Composio's tools:
- CodeInterpreter: For implementing MVP code
- HackerNews: For researching ideas
- WebTool: For web interactions
- ShellTool: For executing commands
- FileTool: For file operations
3. LLM Configuration
pythonCopyllm = ChatOpenAI(model="gpt-4o")
#llm = ChatGroq(model='llama3.3-70b-versatile')
llm_with_tools = llm.bind_tools(tools)
We configure our LLM (OpenAI or Groq) and bind our tools to it, enabling the model to understand and use the available tools.
4. Chatbot Node Implementation
pythonCopydef chatbot(state: State):
return {"messages": [llm_with_tools.invoke(state["messages"])]}
graph_builder.add_node("chatbot", chatbot)
This defines our central chatbot node, which processes messages and decides what actions to take. It uses the LLM with bound tools to generate responses and make decisions.
5. Tool Node and Edge Configuration
pythonCopytool_node = ToolNode(tools=tools)
graph_builder.add_node("tools", tool_node)
graph_builder.add_conditional_edges(
"chatbot",
tools_condition,
)
graph_builder.add_edge("tools", "chatbot")
graph_builder.add_edge(START, "chatbot")
The above code blocks Create a node for tool execution,
Sets up conditional routing based on whether tools are needed,
Establishes the flow between chatbot and tools
and finally defines the entry point.
6. Memory and Graph Compilation
pythonCopymemory = MemorySaver()
graph = graph_builder.compile(checkpointer=memory)
We add memory capabilities to our agent and compile the graph, preparing it for execution.
7. Execution Configuration
pythonCopyconfig = {"configurable": {"thread_id": "1"}, "recursion_limit": 50}
This sets up execution parameters, including:
Thread identification for tracking conversations
Recursion limits to prevent infinite loops
8. User Interaction
pythonCopyuser_input = """You are an Indie Hacker Agent..."""
events = graph.stream(
{"messages": [("user", user_input)]},
config,
stream_mode="values"
)
This initializes the interaction process. It sets up event streaming and manages the real-time processing of user input and agent responses.
Now, run the main.py
file to see the agent in action.
Get the complete code here: AI IndieHacker
Check out how it works.
Join our Discord Channel to gain access to an exclusive AI builder community!
Thank you for reading! Have a lovely week ahead.
Top comments (4)
This is great.
Awesome keep it up
AI is eating software. Btw nice blog.
Nice gotta try this.