LangChain
LangChain is a framework for building agents and other applications on large language models. init_chat_model opens a chat model from any supported provider by name, and create_agent combines a model, a list of tools, and middleware into an agent that calls tools until it reaches an answer. A declared schema returns the final answer as validated data. Each provider, vector store, and tool comes from a separate integration package, and the agent itself runs on LangGraph.
- Downloads / mo
- 156.9M
- Stars
- 149.6K
- Last release
- 1.5.0
- License
- MIT
Strengths
- Creates customizable tool agents. Compose a model, tools, and middleware with create_agent.
- Validates structured agent responses. Declare a schema and receive validated data in structured_response.
Limitations
- Provider integrations install separately. Install the package for the chosen model provider.
- JSON schemas need explicit strategies. Wrap schema dictionaries in ProviderStrategy or ToolStrategy.
Quickstart
from langchain.chat_models import init_chat_model model = init_chat_model("gpt-6.1-sol") response = model.invoke("Why do parrots have colorful feathers?") print(response)
LangChain examples
async def write_research_brief(state: AgentState, config: RunnableConfig) -> Command[Literal["research_supervisor"]]: """Transform user messages into a structured research brief and initialize supervisor. This function analyzes the user's messages and generates a focused research brief that will guide the research supervisor. It also sets up the initial supervisor context with appropriate prompts and instructions. Args: state: Current agent state containing user messages config: Runtime configuration with model settings Returns: Command to proceed to research supervisor with initialized context """ # Step 1: Set up the research model for structured output configurable = Configuration.from_runnable_config(config) research_model_config = { "model": configurable.research_model, "max_tokens": configurable.research_model_max_tokens, "api_key": get_api_key_for_model(configurable.research_model, config), "tags": ["langsmith:nostream"] } # Configure model for structured research question generation research_model = ( configurable_model .with_structured_output(ResearchQuestion) .with_retry(stop_after_attempt=configurable.max_structured_output_retries) .with_config(research_model_config) ) # Step 2: Generate structured research brief from user messages prompt_content = transform_messages_into_research_topic_prompt.format( messages=get_buffer_string(state.get("messages", [])), date=get_today_str() ) response = await research_model.ainvoke([HumanMessage(content=prompt_content)]) # Step 3: Initialize supervisor with research brief and instructions supervisor_system_prompt = lead_researcher_prompt.format( date=get_today_str(), max_concurrent_research_units=configurable.max_concurrent_research_units, max_researcher_iterations=configurable.max_researcher_iterations ) return Command( goto="research_supervisor", update={ "research_brief": response.research_brief, "supervisor_messages": { "type": "override", "value": [ SystemMessage(content=supervisor_system_prompt), HumanMessage(content=response.research_brief) ] } } )