[KongchangAI]
· 2 min read· 1,119 words

LangChain in Practice: Hand-Writing a Multi-Tool Agent and Execution Loop

LangChain in Practice: Hand-Writing a Multi-Tool Agent and Execution Loop

LangChain unifies model APIs and modular components to help enterprises quickly build multi-tool Agent applications.

This article explains LangChain's core value in enterprise AI application development. It distinguishes "using AI tools" from "building AI applications," notes that data security forces enterprises to develop independently, and shows how LangChain reduces switching costs by unifying model vendor APIs. It then covers LangChain's modular architecture—prompt templates, memory management, and tool calling—and breaks down the three steps of building a multi-tool Agent: model integration, structured output, and the execution loop, with LangGraph for complex orchestration. Finally, it highlights the interview advantage of LangChain project experience and suggests a learning path.

Why LangChain Is Needed: From "Using Tools" to "Building Applications"

Many developers easily confuse "using AI tools" with "building AI applications." Using web coding to assist in writing code, or consulting Doubao with questions—these count as using tools. What enterprises truly need, however, is to build AI applications that can connect to private data and manage complex interactions. According to the Bilibili creator's view in the video, when enterprises interview candidates for large model development positions, they almost always ask about experience with web coding tools—but this is only a basic threshold.

The real dividing line is this: core enterprise data cannot be leaked to third-party tool platforms, so applications must be developed independently on top of a framework. LangChain was born for exactly this purpose—it unifies the API calling methods of different model vendors, so developers no longer need to write multiple sets of adapter code for each model and can switch vendors simply by changing the upper-level configuration.

What is this thing

The API adaptation layer is one of LangChain's most fundamental abstractions. Different large model vendors (such as OpenAI, Anthropic, and domestic vendors) differ in request formats, authentication methods, parameter naming, and streaming response handling. LangChain defines a unified BaseLanguageModel interface and provides corresponding implementations for each vendor, so developers only need to call methods like .invoke() and .stream() without worrying about underlying HTTP details. This layer of abstraction not only simplifies model switching but also supports mixing multiple models in the same application—for example, using a cheap model for simple tasks and a high-performance model for complex reasoning.

LangChain's Core Capabilities: Modularity and Full-Process Management

LangChain provides a modular architecture covering components such as prompt templates, pluggable model configuration, memory management, agents, and tool calling. These upper-layer abstractions let developers focus on business logic instead of repeatedly handling low-level chores such as maintaining conversation state and managing context.

Take memory management as an example. In multi-turn conversations, the model needs to remember historical information; if you implement this by manually calling APIs, the code becomes bloated and error-prone. LangChain's built-in mechanism automatically maintains conversation history, so developers only need to focus on how business data is injected. In addition, tool development is encapsulated into a standard interface, eliminating the need to write calling logic from scratch.

Then a large model like this

Prompt templates are a core component in LangChain for dynamically generating model inputs. They abstract the variable parts of a prompt as placeholders and inject concrete values at runtime, thereby avoiding errors and maintenance difficulties caused by manually concatenating strings. For example, ChatPromptTemplate allows defining templates for system messages, user messages, and assistant messages, and supports extracting variables from dictionaries or objects. Templates can also be combined, reused, and linked with output parsers to form a complete input-output pipeline. This is especially important for scenarios requiring multi-turn conversations or complex instructions, and it can significantly improve code readability and testability.

The Construction Logic of a Multi-Tool Agent: Model Integration, Structured Output, and the Execution Loop

The "hand-written multi-tool Agent" mentioned in the video title is the core of this practical session. Its flow can be broken down into three steps:

  1. Model integration: Connect to any model that supports tool calling—such as GPT, Claude, or domestic large models—through LangChain's unified interface. The creator mentions that API differences between models are shielded by the framework, making switching costs extremely low.
  2. Structured output: The Agent needs to parse the tool-calling intent returned by the model, which requires the model output to conform to a specific format (such as JSON). LangChain provides output parsers that convert natural language responses into structured instructions, ensuring the accuracy of subsequent execution.
  3. Execution loop: The Agent calls tools (such as search, calculation, or database queries) based on the model's decisions, returns the results to the model for further reasoning, and repeats until the task is complete. This loop embodies the Agent's autonomy, while LangGraph is used to orchestrate more complex multi-agent nesting and state transitions.

According to the creator's analysis, mastering the LangChain ecosystem (including LangGraph) is sufficient to handle the vast majority of enterprise AI application scenarios, with no need to introduce other frameworks.

How to handle the conversation

Tool Calling is the mechanism by which an Agent interacts with the outside world. The model itself cannot directly execute code or query databases, but it can request tool calls by outputting instructions in a specific format (such as JSON). LangChain defines tools as functions with names, descriptions, and parameter schemas, and automatically generates corresponding tool descriptions for the model's reference. When the model returns a tool-calling request, the framework parses the parameters, executes the tool function, and returns the result in a form the model can understand. This process usually requires multiple rounds of looping until the model decides not to call any more tools and generates a final answer. The reliability of tool calling depends heavily on model capability, so choosing a model that supports tool calling is crucial.

LangGraph is a library in the LangChain ecosystem for building stateful, multi-participant complex Agent workflows. Unlike traditional chain structures, LangGraph models applications as graphs, where nodes represent computation steps (such as calling a model or executing a tool) and edges represent state transition conditions. It supports loops, branching, parallel execution, and persistent state, making it very suitable for implementing scenarios such as multi-agent collaboration and human-in-the-loop interactions. LangGraph shares model and tool abstractions with LangChain but provides finer-grained control, enabling developers to orchestrate complex business processes involving multiple Agents, tools, and conditional logic.

Enterprise-Level Applications and Interview Preparation

From feedback in the job market, candidates with LangChain project experience have a significantly higher pass rate in interviews. Among the cases the creator has encountered, interviews for positions such as large model development, Java development, and big data development all assess experience with web coding, and having a hands-on multi-tool Agent project becomes a differentiating advantage.

For beginners, the creator suggests first becoming familiar with web coding tools (such as Cursor and Claude Code), then diving deeper into LangChain's modular design. When choosing tools, there is no need to agonize over rankings; the key is to understand how the framework solves enterprise pain points such as model switching, private data integration, and context management.

What exactly is your problem

Conclusion

The value of LangChain lies in standardizing common problems in large model application development (interface adaptation, memory management, tool calling), enabling developers to quickly build secure and maintainable enterprise-level AI applications. By hand-writing a multi-tool Agent, you can gain a deep understanding of the collaborative mechanisms among model integration, structured output, and the execution loop, laying the foundation for more complex multi-agent systems.

#LangChain#Multi-Tool Agent#Tool Calling#LangGraph#Large Model Development
Share:

Related articles