Frequently Asked Questions About Krish Naik Agentic AI Stack Builder

23 answers covering everything from basics to advanced usage.

// Basics

What exactly is an agent in LangChain?

An agent is an LLM that autonomously decides which tool to call based on user input, retrieves context from that tool's execution, and generates output — without requiring explicit human routing decisions between steps. The LLM recognises its knowledge cutoff and routes to tools when it needs live or external data rather than acting alone.

What are the four message types in LangChain and when do I use each?

SystemMessage carries behavioural instructions defining persona and constraints; HumanMessage represents user input; AIMessage is the model's response and may contain tool_calls; ToolMessage carries tool execution output and needs a matching tool_call_id. Import them from langchain.messages. Mixing these incorrectly breaks the agent's reasoning chain, so message type discipline is essential.

What is init_chat_model and why use it?

init_chat_model is LangChain's single, provider-agnostic model initialisation function. It accepts a model name prefixed with a provider namespace like 'groq:qwen-32b' and returns the correct chat model object. This lets you swap providers — OpenAI, Gemini, Groq — without changing downstream code, since it wraps the provider-specific classes internally.

What is Vectorless RAG?

Vectorless RAG is a retrieval-augmented generation approach that skips vector databases and embedding-based semantic search. Instead it uses keyword search like BM25 or structured queries to retrieve relevant documents. It reduces infrastructure cost and complexity, making it a strong fit for keyword-rich domains such as legal or technical documents where exact terms matter.

// How To

How do I set up the project environment with UV?

Run 'uv init <project-name>' to initialise the repo, then 'uv venv' to create a virtual environment, and activate it via '.venv/Scripts/activate' on Windows or '.venv/bin/activate' on Mac/Linux. Create requirements.txt with langchain, langchain-community, provider packages, python-dotenv, and ipykernel, then install with 'uv add -r requirements.txt'. UV tracks versions in pyproject.toml.

How do I configure API keys securely?

Create a .env file at the project root and add OPENAI_API_KEY, GOOGLE_API_KEY, and GROQ_API_KEY. Load them at the top of every script with 'from dotenv import load_dotenv; load_dotenv()' and retrieve with os.environ.get(...). Never hardcode keys in source files — this is a security risk and prevents environment portability.

How do I invoke a create_agent agent correctly?

Pass input as a dictionary, not a plain string: agent.invoke({'messages': [{'role': 'user', 'content': 'What is the weather in New York?'}]}). Passing a plain string causes an 'expected dictionary' error. Build the agent first with create_agent(model, tools=[get_weather], system_prompt='You are a helpful assistant').

How do I enforce a structured output schema?

Define a schema using a Pydantic model, TypedDict, or dataclass, then call model.with_structured_output(YourSchema). The LLM response will conform to that structure rather than returning free-form text. Use Pydantic for the richest features — field validation, descriptions, and nested structures — when downstream code must parse output reliably.

How do I build a Deep Research Agent?

Use LangGraph to build a stateful workflow with a planning node that decomposes a complex question into sub-questions, a retrieval node that searches per sub-question, a synthesis node that combines findings, and a gap-detection conditional edge that loops retrieval until coverage is sufficient. Pair this with Agentic RAG so retrieval is a tool the agent calls autonomously.

What order should I build the layers of an agentic AI system in?

Follow this order without skipping: environment setup, model integration, tool creation, message structure, structured output, memory, streaming or batch, LangGraph orchestration, RAG, Vectorless RAG, Deep Research Agents, Guardrails, Evals, then LLM Gateways. Each layer builds on the previous. Skipping layers — especially Guardrails and Evals — creates security and quality risks in production.

// Troubleshooting

Why does my agent call the wrong tool or ignore it entirely?

The most common cause is a vague or missing docstring on your @tool function — the docstring IS the schema the LLM uses for tool selection. Rewrite it to clearly state what the tool does and when to call it. Also confirm you type-hinted parameters so the LLM knows argument types, and that tools are bound via bind_tools or passed to create_agent.

Why am I getting an 'expected dictionary' error from agent.invoke?

You're passing input as a plain string instead of the required dictionary format. Use agent.invoke({'messages': [{'role': 'user', 'content': '...'}]}) instead of agent.invoke('...'). The agent expects a messages list wrapped in a dictionary, not raw text.

Why do my installed libraries seem missing when I run the project?

You likely installed libraries outside the UV virtual environment. Always activate the venv before running 'uv add' — otherwise dependencies won't be available to the project. Confirm activation with your shell prompt showing the venv name, then reinstall with 'uv add -r requirements.txt'.

Why does a LangChain feature I used yesterday no longer work?

Deprecated features silently move between LangChain libraries as the framework evolves rapidly. Always check pyproject.toml and work with the most recent LangChain version. When something breaks, verify the import path — functionality often relocates from langchain to langchain-community or a provider-specific package.

Why is my agent's reasoning chain breaking?

You're likely conflating message types — using HumanMessage where SystemMessage is required, or omitting the ToolMessage after tool execution. Every tool call must be followed by a ToolMessage linked via tool_call_id before you send the messages back to the model. Restore message type discipline to fix the reasoning chain.

// Comparisons

How does create_agent compare to building a manual Tool Execution Loop?

create_agent composes a model, tools, and system prompt into a ready agent in one call — fast and clean for standard use. The manual Tool Execution Loop gives you full control: you send a HumanMessage, receive an AIMessage with tool_calls, execute each tool into ToolMessages, and send everything back for final output. Use the manual loop when you need custom control flow or debugging visibility.

How does this stack compare to just calling the OpenAI API directly?

Direct API calls give you raw completions but no tool decision loop, no provider-agnostic swapping, no typed message discipline, no orchestration, no built-in RAG, and no guardrails or evals framework. This stack layers those capabilities in a defined order so you reach production readiness. The trade-off is more structure upfront in exchange for maintainability, security, and multi-provider flexibility.

How does Agentic RAG differ from traditional RAG pipelines?

Traditional RAG is a fixed pipeline: chunk, embed, store, retrieve top-k, inject context. Agentic RAG wraps retrieval as a tool so the agent decides when and how many times to retrieve, enabling multi-hop reasoning and iterative research. Traditional RAG is simpler and cheaper per query; Agentic RAG handles complex questions that need multiple retrieval rounds.

// Advanced

When should I use LangGraph instead of create_agent?

Use LangGraph when your application needs complex control flow — looping, branching, multi-agent handoffs, or stateful workflows like Deep Research Agents. create_agent suits single-agent tasks with a tool set. LangGraph defines nodes, edges, and conditional edges explicitly, making it the core framework for Agentic RAG and iterative research systems.

What is an LLM Gateway and when do I add it?

An LLM Gateway sits between your application and LLM providers, handling model routing, rate limiting, cost tracking, logging, and fallback logic. Implement it at the final layer, after your core agent logic is validated and evaluated. It's an infrastructure concern that adds observability and resilience for production traffic across multiple models.

How do I decide between Vector RAG and Vectorless RAG for my dataset?

Build both pipelines and run the same eval set against them. Use Vector RAG when semantic understanding is critical and budget allows embeddings and a vector DB. Use Vectorless RAG with BM25 when cost and simplicity matter and queries are keyword-rich, like legal terms. Choose based on measured faithfulness and relevance, not assumptions.

What evaluation dimensions should I measure before production?

Measure faithfulness (does the answer match retrieved context?), relevance (is it relevant to the question?), correctness, and hallucination rate. Use open-source eval libraries against a representative or gold-standard test set. Evals are the quality gate for production readiness — run them before every deployment, especially for RAG and research agents.

How do I use batch processing for bulk workloads?

Use model.batch([question1, question2, question3], config={'max_concurrency': 5}) to send multiple independent requests in parallel and receive all responses at once. This reduces total latency and cost for bulk processing pipelines. Reserve streaming for user-facing chatbots and use batch for offline or high-volume tasks.