[PR #793] [MERGED] feat(langgraph): functional API #1013

Closed
opened 2026-02-15 19:16:48 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/langgraphjs/pull/793
Author: @benjamincburns
Created: 1/21/2025
Status: Merged
Merged: 1/28/2025
Merged by: @benjamincburns

Base: mainHead: ben/functional-api


📝 Commits (10+)

  • 478149f Add support for returnDirect in createReactAgent, typing fixes
  • f3669ec feat(langgraph): functional API
  • b986d8c WIP
  • 0f1c049 getting there...
  • 68fcfc4 lint
  • 041feb7 actually export the darned thing
  • 9f0d56f add getStore
  • 97c1ea8 Move interrupt & getStore out of web.ts (needs AsyncLocalStorage)
  • 614fbe3 more test, WIP fixes
  • 3d64ecd handle multiple interrupts

📊 Changes

43 files changed (+2749 additions, -418 deletions)

View changed files

📝 docs/docs/concepts/functional_api.md (+81 -59)
📝 docs/docs/tutorials/workflows/index.md (+87 -81)
📝 examples/how-tos/cross-thread-persistence-functional.ipynb (+5 -5)
📝 examples/how-tos/multi-agent-multi-turn-convo-functional.ipynb (+1 -1)
📝 examples/how-tos/multi-agent-network-functional.ipynb (+2 -2)
📝 examples/how-tos/persistence-functional.ipynb (+3 -3)
📝 examples/how-tos/react-agent-from-scratch-functional.ipynb (+25 -24)
📝 examples/how-tos/review-tool-calls-functional.ipynb (+1 -1)
📝 examples/how-tos/wait-user-input-functional.ipynb (+1 -1)
📝 libs/checkpoint/src/store/batch.ts (+12 -0)
📝 libs/langgraph/src/channels/any_value.ts (+10 -10)
📝 libs/langgraph/src/channels/ephemeral_value.ts (+10 -9)
📝 libs/langgraph/src/channels/last_value.ts (+8 -7)
📝 libs/langgraph/src/constants.ts (+35 -6)
libs/langgraph/src/func/index.ts (+423 -0)
libs/langgraph/src/func/types.ts (+85 -0)
📝 libs/langgraph/src/graph/graph.ts (+2 -5)
📝 libs/langgraph/src/graph/index.ts (+1 -1)
📝 libs/langgraph/src/graph/message.ts (+1 -1)
📝 libs/langgraph/src/graph/state.ts (+2 -2)

...and 23 more files

📄 Description

feat(langgraph): Add Functional API

This PR introduces a new functional API to langgraphjs that provides a simpler, more intuitive way to create and compose tasks in a graph. The changes focus on improving developer experience while maintaining the power and flexibility of the existing graph-based system.

Key Changes

1. New Functional API Components

  • Added new task and entrypoint functions for creating graph nodes
  • Introduced experimental TaskOptions and EntrypointOptions interfaces
  • Added support for retry policies at the task level

2. Configuration and Constants Updates

  • Added new configuration keys for the functional API (CONFIG_KEY_CALL)
  • Introduced new control flow constants (NO_WRITES, RETURN)
  • Enhanced type safety for the SendInterface validation

3. Pregel Engine Improvements

  • Modified task handling to support functional API calls
  • Enhanced error handling and null value checking in task writes
  • Updated the IGNORE set to include new control flow signals

4. Type System Enhancements

  • Added new types for task paths and calls
  • Improved type safety throughout the codebase

Implementation Details

The implementation focuses on maintaining backward compatibility while introducing the new functional API. Key architectural decisions include:

  1. Using the Pregel engine as the underlying execution system
  2. Maintaining the existing channel-based communication system
  3. Adding proper TypeScript types for improved developer experience
  4. Implementing proper error handling and validation

Example Usage

import { task, entrypoint } from "@langchain/langgraph";

// Define a task with optional retry policy
const processData = task(
  "process",
  async (data) => {
    // Process the data
    return result;
  },
  { retry: { maxAttempts: 3 } }
);

// Create an entrypoint
const workflow = entrypoint({ name: "main" }, async (input) => {
  const result = await processData(input);
  return result;
});

Breaking Changes

None. This is a purely additive change that maintains compatibility with existing code.

Testing

Added new test files and cases to cover the functional API functionality:

  • func.test.ts for testing the new API
  • Additional test coverage in existing test files

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/langgraphjs/pull/793 **Author:** [@benjamincburns](https://github.com/benjamincburns) **Created:** 1/21/2025 **Status:** ✅ Merged **Merged:** 1/28/2025 **Merged by:** [@benjamincburns](https://github.com/benjamincburns) **Base:** `main` ← **Head:** `ben/functional-api` --- ### 📝 Commits (10+) - [`478149f`](https://github.com/langchain-ai/langgraphjs/commit/478149f9bf6ab1d7d950b05c9082b7c5f9c53f9d) Add support for returnDirect in createReactAgent, typing fixes - [`f3669ec`](https://github.com/langchain-ai/langgraphjs/commit/f3669ec816f95d102f319060f5ee0165c1b545b5) feat(langgraph): functional API - [`b986d8c`](https://github.com/langchain-ai/langgraphjs/commit/b986d8c86e296d41e9106fe1cba78a8772bcd9eb) WIP - [`0f1c049`](https://github.com/langchain-ai/langgraphjs/commit/0f1c049033af48a8bfbb3490648fc41e7b7fb8c5) getting there... - [`68fcfc4`](https://github.com/langchain-ai/langgraphjs/commit/68fcfc4fb5d242a9012be9ff86f7a52a48a8a160) lint - [`041feb7`](https://github.com/langchain-ai/langgraphjs/commit/041feb74c911f051f319da328bcb948c4e085c0f) actually export the darned thing - [`9f0d56f`](https://github.com/langchain-ai/langgraphjs/commit/9f0d56fcb2609460c98731fb1e11659861610d07) add getStore - [`97c1ea8`](https://github.com/langchain-ai/langgraphjs/commit/97c1ea850d2abfe312a41434ecbbc6413fc82255) Move interrupt & getStore out of web.ts (needs AsyncLocalStorage) - [`614fbe3`](https://github.com/langchain-ai/langgraphjs/commit/614fbe35afe0992273f66781c21ad329021939bb) more test, WIP fixes - [`3d64ecd`](https://github.com/langchain-ai/langgraphjs/commit/3d64ecd1f5720a6d665a1dc7dd9fcd246d5fd2bc) handle multiple interrupts ### 📊 Changes **43 files changed** (+2749 additions, -418 deletions) <details> <summary>View changed files</summary> 📝 `docs/docs/concepts/functional_api.md` (+81 -59) 📝 `docs/docs/tutorials/workflows/index.md` (+87 -81) 📝 `examples/how-tos/cross-thread-persistence-functional.ipynb` (+5 -5) 📝 `examples/how-tos/multi-agent-multi-turn-convo-functional.ipynb` (+1 -1) 📝 `examples/how-tos/multi-agent-network-functional.ipynb` (+2 -2) 📝 `examples/how-tos/persistence-functional.ipynb` (+3 -3) 📝 `examples/how-tos/react-agent-from-scratch-functional.ipynb` (+25 -24) 📝 `examples/how-tos/review-tool-calls-functional.ipynb` (+1 -1) 📝 `examples/how-tos/wait-user-input-functional.ipynb` (+1 -1) 📝 `libs/checkpoint/src/store/batch.ts` (+12 -0) 📝 `libs/langgraph/src/channels/any_value.ts` (+10 -10) 📝 `libs/langgraph/src/channels/ephemeral_value.ts` (+10 -9) 📝 `libs/langgraph/src/channels/last_value.ts` (+8 -7) 📝 `libs/langgraph/src/constants.ts` (+35 -6) ➕ `libs/langgraph/src/func/index.ts` (+423 -0) ➕ `libs/langgraph/src/func/types.ts` (+85 -0) 📝 `libs/langgraph/src/graph/graph.ts` (+2 -5) 📝 `libs/langgraph/src/graph/index.ts` (+1 -1) 📝 `libs/langgraph/src/graph/message.ts` (+1 -1) 📝 `libs/langgraph/src/graph/state.ts` (+2 -2) _...and 23 more files_ </details> ### 📄 Description # feat(langgraph): Add Functional API This PR introduces a new functional API to langgraphjs that provides a simpler, more intuitive way to create and compose tasks in a graph. The changes focus on improving developer experience while maintaining the power and flexibility of the existing graph-based system. ## Key Changes ### 1. New Functional API Components - Added new `task` and `entrypoint` functions for creating graph nodes - Introduced experimental TaskOptions and EntrypointOptions interfaces - Added support for retry policies at the task level ### 2. Configuration and Constants Updates - Added new configuration keys for the functional API (`CONFIG_KEY_CALL`) - Introduced new control flow constants (`NO_WRITES`, `RETURN`) - Enhanced type safety for the SendInterface validation ### 3. Pregel Engine Improvements - Modified task handling to support functional API calls - Enhanced error handling and null value checking in task writes - Updated the IGNORE set to include new control flow signals ### 4. Type System Enhancements - Added new types for task paths and calls - Improved type safety throughout the codebase ## Implementation Details The implementation focuses on maintaining backward compatibility while introducing the new functional API. Key architectural decisions include: 1. Using the Pregel engine as the underlying execution system 2. Maintaining the existing channel-based communication system 3. Adding proper TypeScript types for improved developer experience 4. Implementing proper error handling and validation ## Example Usage ```typescript import { task, entrypoint } from "@langchain/langgraph"; // Define a task with optional retry policy const processData = task( "process", async (data) => { // Process the data return result; }, { retry: { maxAttempts: 3 } } ); // Create an entrypoint const workflow = entrypoint({ name: "main" }, async (input) => { const result = await processData(input); return result; }); ``` ## Breaking Changes None. This is a purely additive change that maintains compatibility with existing code. ## Testing Added new test files and cases to cover the functional API functionality: - `func.test.ts` for testing the new API - Additional test coverage in existing test files --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 19:16:48 -05:00
yindo closed this issue 2026-02-15 19:16:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#1013