AI / LangGraph LangChain Interview questions
How do you create custom agents?
The easiest way to create a custom agent is with the factory functions create_react_agent() or create_openai_tools_agent(), which combine a custom prompt, an LLM, and a list of tools. Most customisation needs are met by adjusting the prompt and tool list.
from langchain import hub
from langchain.agents import create_react_agent, AgentExecutor
from langchain_openai import ChatOpenAI
from langchain_community.tools.tavily_search import TavilySearchResults
# Pull base ReAct prompt from Hub or define your own
prompt = hub.pull("hwchase17/react")
tools = [TavilySearchResults(max_results=3)]
llm = ChatOpenAI(model="gpt-4o")
agent = create_react_agent(llm=llm, tools=tools, prompt=prompt)
executor = AgentExecutor(agent=agent, tools=tools, verbose=True)
executor.invoke({"input": "What is the population of France?"})
For full control, subclass BaseSingleActionAgent (returns one action per step) or BaseMultiActionAgent (returns multiple actions per step). You must implement plan() and aplan() which receive the current intermediate steps and return either an AgentAction (tool to call) or AgentFinish (final answer).
For production multi-step agents with complex state and human-in-the-loop needs, LangGraph's graph-based approach is more appropriate than subclassing agent base classes.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
