SUMMARY of Part 3
This is part 3 of the summary of a 2-day workshop, designed for anyone who is looking to explore low-code applications to create Agentic AI based on Large Language Models (LLMs) from design to deployment.
Now we will try out creating our own Agentic AI by:
• Setting up a virtual environment
• Configurating our API Keys
• Creating a simple commercial Agent with LangChain
Before you start, you need: an IDE (like VS Code), an OpenAI Key (or any other model you aim to use). Access to LangChain and either: LangGraph Studio, and Docker (Both available as free Desktop Apps), or the sufficient WebApp on LangSmith.
After last week’s exploration of OpenManus, I’ve got access to OG Manus. I am pretty impressed – thats why we will, after all, use a more complex way to create AI agents (For the sake of controlability, transparency and thus, explainability) I will walk you through LangChain, we will set up our first easy AI Agent and use this as a foundation to make sense of other Agentic AI tools.
First things first: What are Agents?
Kapoor et al. (2024) from Princeton University provided the (so far) most useful definition. I’ll go with it: three sets of properties cause an AI system to be considered more agentic according to existing definitions (Shavit et al. 2023, Chan et al. 2023, Gabriel et al. 2024, Weng 2023, Chase 2024):
Environment and goals. The more complex the environment, the more AI systems operating in that environment are agentic. Complex environments have a range of tasks and domains, multiple stakeholders, a long time horizon to take action, and unexpected changes. Systems that pursue complex goals without being instructed on how to pursue the goal are more agentic.
User interface and supervision. AI systems that can be instructed in natural language and act autonomously on the user's behalf are more agentic. In particular, systems that require less user supervision are more agentic. For example, chatbots cannot take real-world action, but adding plugins to chatbots (such as Zapier for ChatGPT) allows them to take some actions on behalf of users.
System design. Systems that use tools (like web search or code terminal) or planning (like reflecting on previous outputs or decomposing goals into subgoals) are more agentic. Systems whose control flow is driven by an LLM, rather than LLMs being invoked by a static program, are more agentic.
Quick Guide: Building a Simple AI Agent on MacOS
Step 1: Setup Project Environment
Open Terminal and create your project:
mkdir ai_agent
cd ai_agent
Create and activate a virtual environment:
python3 -m venv agent_env
source agent_env/bin/activate
Step 2: Install Required Packages
pip install langgraph langchain langchain-openai python-dotenv
Step 3: Setup OpenAI API
Sign up at OpenAI.
Navigate to API Keys, click "Create new secret key", and copy the key.
Create a .env
file:
echo "OPENAI_API_KEY=your-api-key-here" > .env
Replace your-api-key-here
with your actual API key.
Step 4: Test Setup
Create test_setup.py
:
from dotenv import load_dotenv
from langchain_openai import ChatOpenAI
load_dotenv()
llm = ChatOpenAI(model="gpt-4o-mini")
response = llm.invoke("Hello! Are you working?")
print(response.content)
Run your test:
python test_setup.py
If you see a response, you're ready!
Step 5: Build the Agent
Create simple_agent.py
:
from typing import TypedDict
from langgraph.graph import StateGraph, END
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from langchain.schema import HumanMessage
from dotenv import load_dotenv
load_dotenv()
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)
class State(TypedDict):
text: str
classification: str
summary: str
def classify_text(state: State):
prompt = PromptTemplate(
input_variables=["text"],
template="Classify the text as News, Blog, Research, or Other:\n{text}\nCategory:"
)
message = HumanMessage(content=prompt.format(text=state["text"]))
classification = llm.invoke([message]).content.strip()
return {"classification": classification}
def summarize_text(state: State):
prompt = PromptTemplate.from_template("Summarize this text in one sentence:\n{text}\nSummary:")
chain = prompt | llm
response = chain.invoke({"text": state["text"]})
return {"summary": response.content}
workflow = StateGraph(State)
workflow.add_node("classify", classify_text)
workflow.add_node("summarize", summarize_text)
workflow.set_entry_point("classify")
workflow.add_edge("classify", "summarize")
workflow.add_edge("summarize", END)
app = workflow.compile()
sample_text = "Anthropic's MCP is an open-source system enabling easy interaction with APIs."
result = app.invoke({"text": sample_text})
print("Classification:", result["classification"])
print("Summary:", result["summary"])
Step 6: Run Your Agent
python simple_agent.py
You should see output similar to:
Classification: Other
Summary: Anthropic's MCP is an open-source system for easy API interaction.
Congrats, you have built a simple, functional AI agent on MacOS.