Skip to content

writer/langchain-examples

Repository files navigation

LangChain examples

This repository contains sample code demonstrating how to use LangChain, LangGraph, and WRITER's Palmyra family of models for building AI-powered applications.

Table of contents

Example overview

This repository includes the following examples:

  • /financial-assistant – A data analysis agent that combines internal documents with external market data to generate structured research briefs

    • Ingests internal documents (PDFs, reports, memos) into WRITER's Knowledge Graph for structured retrieval
    • Retrieves external market data from SEC filings, financial news feeds, historical stock data, and web sources
    • Uses LangGraph to orchestrate a multi-step workflow: knowledge graph retrieval, external data gathering, summarization, and brief generation
    • Uses middleware to generate role-specific briefs (e.g., detailed for Junior Analysts, concise for Portfolio Managers) with key drivers, risks, and metrics
    • Powered by WRITER's Palmyra X5 model for content generation
  • /article-research-creation – Converts voice dictation notes into publication-ready articles

    • Analyzes and organizes spoken notes into a structured outline
    • Conducts targeted web research from provided URLs
    • Generates article sections in parallel using LangGraph and WRITER's Palmyra X5 model
  • /customer-facing-chat-assistant – A customer support agent for handling customer inquiries

  • /human-in-the-loop-agent – Demonstrates human-in-the-loop patterns for LangChain agents requiring human approval

    • Reads customer messages and extracts refund or action requests using specialized tools
    • Supports multiple decision flows: approve, reject, or edit actions
    • Uses HumanInTheLoopMiddleware to require human approval for sensitive actions
    • Maintains conversation memory and state using InMemorySaver for context-aware interactions
    • Powered by WRITER's Palmyra X5 model with LangChain agents
  • /deep-agents – A multi-agent research system for producing comprehensive research reports

    • Uses an orchestrator agent to coordinate specialized research and critique agents
    • Performs web searches, data analysis, and peer-style review of report quality
    • Decomposes complex topics into parallel sub-questions via the deepagents framework
    • Powered by WRITER's Palmyra X5 model

Prerequisites

Ensure you have the following before starting:

  • Python 3.11 or higher installed

Installation

Follow these steps to set up the project:

  1. Clone the repository

    git clone https://github.com/writer/langchain-examples.git
    cd langchain-examples
  2. Create and activate a virtual environment

    python -m venv venv
    source venv/bin/activate  # On Windows, use `venv\Scripts\activate`
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    Copy the .env.template file to a .env file in the project root with your credentials (if available):

    cp .env.template .env

    WRITER credentials

    Required for all examples.

    WRITER_API_KEY=your WRITER API key

    Note: see WRITER developer documentation for info on how to get your API key.

    (optional) LangSmith observability

    LANGSMITH_TRACING=true #set to false to disable tracing
    LANGSMITH_API_KEY=your_langsmith_api_key_here
    LANGSMITH_PROJECT=langchain-examples

    Note: See LangSmith documentation on environment variables for additional configuration options

    SEC credentials (for financial-assistant)

    Required only for the financial assistant example.

    SEC_IDENTITY_EMAIL=your email address

    Note: You can find more information on how to set up these credentials in each example's README.

Run the examples

Each example runs independently. Navigate to the example directory and follow the instructions below.

Financial assistant

Run the financial assistant:

cd financial-assistant/src
python main.py

Article research and creation

Run the article research and creation agent:

cd article-research-creation/src
python main.py

The generated article will be saved to article-research-creation/src/results/ with a timestamp.

Customer-facing chat assistant

Run the customer-facing chat assistant:

cd customer-facing-chat-assistant/src
python main.py

Human in the loop agent

cd human-in-the-loop-agent/src
python main.py

Demonstrates human-in-the-loop patterns for agents requiring human approval before executing critical actions.

Deep agents

Run the deep agents research system:

cd deep-agents
python research_agent.py

About WRITER

WRITER is the full-stack generative AI platform for enterprises. Build and deploy AI apps with a suite of developer tools fully integrated with LLMs, graph-based RAG, AI guardrails, and more. To learn more, visit our website.

Support

If you encounter any issues or have questions, please file an issue on this repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages