Create autonomous AI agents that reason, plan, use tools, remember, and act – using BabyAGI, AutoGPT-style clones, LangGraph and more.
In 2026, AI agents are autonomous programs that can:
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_react_agent
from langchain.prompts import PromptTemplate
from langchain.tools import Tool
llm = ChatOpenAI(model="gpt-4o", temperature=0)
tools = [
Tool(
name="Search",
func=lambda q: f"Search results for '{q}'", # Replace with real search tool
description="Useful for searching the web"
),
Tool(
name="Calculator",
func=lambda x: str(eval(x)),
description="Useful for math calculations"
)
]
prompt = PromptTemplate.from_template(
"""Answer the following questions as best you can. You have access to the following tools:
{tools}
Use the following format:
Question: the input question you must answer
Thought: you should always think about what to do
Action: the action to take, should be one of [{tool_names}]
Action Input: the input to the action
Observation: the result of the action
... (this Thought/Action/Action Input/Observation can repeat N times)
Thought: I now know the final answer
Final Answer: the final answer to the original input question
Question: {input}
{agent_scratchpad}"""
)
agent = create_react_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
response = agent_executor.invoke({"input": "What is the capital of France?"})
print(response["output"])
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_tools_agent
from langchain.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-4o", temperature=0.7)
prompt = ChatPromptTemplate.from_messages([
("system", """You are an autonomous AI agent. Your goal is {goal}.
You can use tools to help achieve it. Think step by step."""),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
tools = [...] # your tools here
agent = create_openai_tools_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True, max_iterations=15)
result = agent_executor.invoke({
"input": "Research and write a short report on AI agents in 2026",
"goal": "Create a concise report on the state of AI agents in 2026"
})
print(result["output"])
from langgraph.graph import StateGraph, END
from typing import TypedDict, Annotated
import operator
class AgentState(TypedDict):
messages: Annotated[list, operator.add]
next: str
def supervisor(state):
# Decide next agent
return {"next": "researcher"}
def researcher(state):
return {"messages": ["Research complete"]}
workflow = StateGraph(AgentState)
workflow.add_node("supervisor", supervisor)
workflow.add_node("researcher", researcher)
workflow.add_conditional_edges("supervisor", lambda s: s["next"], {"researcher": "researcher"})
workflow.add_edge("researcher", END)
graph = workflow.compile()
result = graph.invoke({"messages": ["Build AI agent report"]})
print(result)