AI / LangGraph LangChain Interview questions
What is AgentExecutor?
AgentExecutor is the runtime loop that drives an agent to completion. It takes an agent (which decides actions) and a list of tools (which execute those actions), and repeatedly calls the agent, executes the selected tool, feeds the observation back, and repeats until the agent returns an AgentFinish or a stopping condition is reached.
from langchain.agents import AgentExecutor executor = AgentExecutor( agent=agent, tools=tools, verbose=True, # print each step max_iterations=10, # prevent infinite loops return_intermediate_steps=True, # include tool call history in output handle_parsing_errors=True, # auto-retry if output parse fails ) result = executor.invoke({"input": "Find the CEO of Anthropic"}) print(result["output"]) # final answer print(result["intermediate_steps"]) # list of (AgentAction, observation)
Key configuration options: max_iterations prevents runaway loops, max_execution_time adds a wall-clock timeout, early_stopping_method controls whether the agent generates a final answer when max_iterations is hit or just stops, and handle_parsing_errors retries if the LLM produces malformed output instead of crashing the loop.
More Related questions...