ChinaWHAPI
Global Gateway
← Back to Knowledge Center
LangChainChainAgentPython

Integrating LangChain with Chinese LLMs: From Chain to Agent

LangChain is the most popular LLM application development framework. This article covers integrating LangChain with ChinaWHAPI to build Chain and Agent applications.

LangChain Integration

from langchain.chat_models import ChatOpenAI
from langchain.schema import HumanMessage

llm = ChatOpenAI(
    model="qwen3.6-plus",
    openai_api_key="your_chinawhapi_key",
    openai_api_base="https://chinawhapi.com/v1",
)

response = llm([HumanMessage(content="Explain microservices architecture")])

Simple Chain

from langchain.chains import SimpleChain

chain = SimpleChain(llm=llm)
response = chain.run("Generate a technical weekly report template")

Building an Agent

from langchain.agents import initialize_agent, Tool
from langchain.tools import WikipediaQueryRun

tools = [Tool(name="Wikipedia", func=WikipediaQueryRun().run, description="Query Wikipedia")]

agent = initialize_agent(
    tools, llm, agent_type="zero-shot-react-description"
)
response = agent.run("What are the basic principles of quantum computing?")