Skip to main content
TypeScript agent using LangChain.js with Bindu SDK.

Code

/**
 * TypeScript LangChain Agent — Bindufied
 *
 * Demonstrates using the Bindu TypeScript SDK with LangChain.js.
 * The developer writes their agent using any TS framework — Bindu handles
 * the conversion to a microservice with DID, auth, x402, and A2A protocol.
 *
 * Usage:
 *   1. Set OPENAI_API_KEY in .env or environment
 *   2. npx tsx index.ts
 *
 * The SDK will:
 *   - Start the Bindu Python core in the background
 *   - Register this agent with DID identity and A2A endpoints
 *   - Listen for tasks via gRPC and execute them with LangChain
 */

import { bindufy, ChatMessage } from "@bindu/sdk";
import { ChatOpenAI } from "@langchain/openai";
import * as dotenv from "dotenv";

dotenv.config();

// Create LangChain agent — this is the developer's choice
const llm = new ChatOpenAI({
  model: "gpt-4o",
  temperature: 0.7,
});

// bindufy — one call, full microservice
bindufy(
  {
    author: "dev@example.com",
    name: "langchain-research-agent",
    description: "A research assistant built with LangChain.js and Bindu",
    version: "1.0.0",
    deployment: {
      url: "http://localhost:3773",
      expose: true,
      cors_origins: ["http://localhost:5173"],
    },
    skills: ["skills/typescript-langchain-skill"],
    capabilities: {
      streaming: false,
      push_notifications: false,
    },
  },
  async (messages: ChatMessage[]) => {
    // Convert Bindu messages to LangChain format
    const langchainMessages = messages.map((m) => ({
      role: m.role as "user" | "assistant" | "system",
      content: m.content,
    }));

    // Invoke LangChain
    const response = await llm.invoke(langchainMessages);

    // Return the content — Bindu handles the rest
    return typeof response.content === "string"
      ? response.content
      : JSON.stringify(response.content);
  }
);

Skill Configuration

Create skills/typescript-langchain-skill/skill.yaml:
# TypeScript LangChain Agent Skill
# TypeScript-based AI agent using LangChain.js framework

id: typescript-langchain-skill
name: TypeScript LangChain Agent Skill
version: 1.0.0
author: typescript-developer@example.com

description: |
  TypeScript agent that demonstrates Bindu SDK integration with LangChain.js.
  Built with modern TypeScript practices and LangChain framework for AI agent development.

  Features:
  - Direct LangChain.js integration
  - TypeScript type safety and modern ES features
  - OpenAI API integration through LangChain
  - Environment-based configuration
  - CORS-enabled for frontend integration

tags:
  - typescript
  - langchain
  - openai
  - bindu-sdk
  - agent-development
  - es2022
  - nodejs

input_modes:
  - application/json
output_modes:
  - application/json

examples:
  - "Research the latest developments in quantum computing and provide a summary"
  - "What are the main benefits of using LangChain with TypeScript?"
  - "How do I integrate LangChain with OpenAI in a TypeScript application?"
  - "Create a TypeScript agent that can analyze documents"
  - "What are the best practices for TypeScript agent development?"

capabilities_detail:
  langchain_integration:
    supported: true
    description: "Direct integration with LangChain.js framework"
    features:
      - chain_composition
      - memory_management
      - prompt_templates

  typescript_support:
    supported: true
    description: "Full TypeScript support with type safety"
    features:
      - es2022_target
      - strict_typing
      - modern_syntax

  openai_backend:
    supported: true
    description: "OpenAI API integration through LangChain"
    models_supported: ["gpt-4o", "gpt-4o-mini"]

  bindu_sdk:
    supported: true
    description: "Full Bindu SDK integration for protocol compliance"
    features:
      - did_support
      - x402_payments
      - a2a_protocol
      - cors_enabled

requirements:
  packages:
    - "@bindu/sdk"
    - "@langchain/openai"
    - "dotenv"
    - "@types/node"
    - "tsx"
  system:
    - node_18_or_higher
    - typescript_5_or_higher
  api_keys:
    - OPENAI_API_KEY

performance:
  avg_response_time_ms: 3000
  max_concurrent_requests: 5
  memory_usage_mb: 256
  scalability: vertical

assessment:
  keywords:
    - typescript
    - langchain
    - openai
    - agent
    - bindu
    - nodejs
    - es2022

  specializations:
    - domain: typescript-development
      confidence_boost: 0.4
    - domain: langchain-integration
      confidence_boost: 0.5
    - domain: openai-integration
      confidence_boost: 0.3

  anti_patterns:
    - "blocking operations"
    - "callback hell"
    - "type_any_usage"
    - "legacy_syntax"

  complexity_indicators:
    simple:
      - "research"
      - "explain"
      - "what is"
    medium:
      - "how to integrate"
      - "best practices for"
    complex:
      - "create agent that"
      - "comprehensive guide"
      - "production-ready"

How It Works

TypeScript SDK Integration
  • @bindu/sdk: TypeScript Bindu SDK for agent development
  • Automatic microservice generation with DID and auth
  • gRPC communication with Bindu Python core
  • A2A protocol compliance handled by SDK
LangChain.js Integration
  • ChatOpenAI: LangChain’s OpenAI integration
  • Message format conversion between Bindu and LangChain
  • Async/await pattern for response handling
  • Flexible content type handling
Message Processing
  • ChatMessage[]: Bindu message format with role and content
  • Role mapping (user/assistant/system) for LangChain compatibility
  • Content extraction and type checking
  • Response formatting for Bindu protocol
Configuration
  • Environment-based API key management
  • Standard Bindu deployment configuration
  • Skills and capabilities declaration
  • CORS origins for frontend integration

Dependencies

npm install @bindu/sdk @langchain/openai dotenv
npm install -D @types/node tsx

Environment Setup

Create .env file:
OPENAI_API_KEY=your_openai_api_key_here

Run

npx tsx index.ts
Examples:
  • “Research the latest developments in quantum computing and provide a summary”
  • “What are the main benefits of using LangChain with TypeScript?”
  • “How do I integrate LangChain with OpenAI in a TypeScript application?”

Example API Calls

{
  "jsonrpc": "2.0",
  "method": "message/send",
  "params": {
    "message": {
      "role": "user",
      "kind": "message",
      "messageId": "9f11c870-5616-49ad-b187-d93cbb100001",
      "contextId": "9f11c870-5616-49ad-b187-d93cbb100002",
      "taskId": "9f11c870-5616-49ad-b187-d93cbb100003",
      "parts": [
        {
          "kind": "text",
          "text": "Research the latest developments in quantum computing and provide a summary"
        }
      ]
    },
     "skillId": "typescript-langchain-skill",
    "configuration": {
      "acceptedOutputModes": ["application/json"]
    }
  },
  "id": "9f11c870-5616-49ad-b187-d93cbb100003"
}
{
  "jsonrpc": "2.0",
  "method": "tasks/get",
  "params": {
    "taskId": "9f11c870-5616-49ad-b187-d93cbb100003"
  },
  "id": "9f11c870-5616-49ad-b187-d93cbb100004"
}

Frontend Setup

# Clone the Bindu repository
git clone https://github.com/GetBindu/Bindu

# Navigate to frontend directory
cd frontend

# Install dependencies
npm install

# Start frontend development server
npm run dev
Open http://localhost:5173 and try to chat with the TypeScript LangChain agent