dsh-graph-runtime: Graph Runtime Capabilities of DeepSeek Harness

Introduction

In the development of DeepSeek Harness (DSH), directly integrating LangGraph requires handling graph definitions, tool registration, and routing logic. dsh-graph-runtime is an independent Cordis plugin/bundle that registers LangGraph compiled graphs as DSH tools and provides a graph-driven routing agent.

What It Is

This is a standalone plugin that provides graph runtime capabilities for DSH. It is maintained by developer snail30xx under the MIT license. It mainly solves the problems of defining graphs, automatic mounting, and intelligent routing in a DSH environment.

Core Features

  • Definition and Automatic Mounting: Use defineGraph to define an extended StateGraph; registration is completed when the module is loaded.
  • Tool Registration: Register LangGraph compiled graphs as DSH tools (asTool), automatically discovering tool names and descriptions.
  • Graph-Driven Routing Agent: Provide a GraphRoutingAgent that allows an LLM to select one graph tool to execute.
  • Validation and Extension: Built-in tool parameter validation hooks, plus graphTools/pre-execute and graphTools/post-execute extension points.

Installation and Enablement

Before installing, make sure the environment meets the dependency requirements:
* Node.js >= 22.5
* Dependencies: @deepseek-ai/cordis, @deepseek-ai/dsh-llm, @langchain/langgraph

Run the installation command:

npm install dsh-graph-runtime

Add an entry to the root composition in cordis.yml (the plugin ships with cordis.patch.yml; adding the package name to the configuration will automatically mount it):

- id: graph-runtime
  name: dsh-graph-runtime

Typical Usage

1. Define a Graph

Graph authors only need to use defineGraph to define a graph; there is no need to mount it manually or invoke services.

// graphs/echo.ts
import { defineGraph } from 'dsh-graph-runtime'
import { Annotation, END, START, StateGraph } from '@langchain/langgraph'

const State = Annotation.Root({
  topic: Annotation<string>,
  log: Annotation<string[]>({
    reducer: (left, right) => [...left, ...right],
    default: () => [],
  }),
})

export const echoGraph = defineGraph({
  name: 'echo_graph',
  description: 'Echo the given topic.',
  build: () =>
    new StateGraph(State)
      .addNode('echo', async (state) => ({ log: [`seen:${state.topic}`] }))
      .addEdge(START, 'echo')
      .addEdge('echo', END),
  asTool: true, // 声明为模型可见的 DSH 工具
})

2. Use GraphRoutingAgent

Initialize the routing agent with GraphRoutingAgent and configure parameters such as the model and filters.

import { GraphRoutingAgent } from 'dsh-graph-runtime'

const router = new GraphRoutingAgent(ctx, {
  provider: 'deepseek',
  model: 'deepseek-chat',
  filter: { allow: ['echo_graph', 'search_graph'] },
  maxRetries: 3, // 验证失败时的最大重试次数
})

const outcome = await router.route({ input: 'echo hello for me' })

3. Use Extension Points

Listen to the graphTools/pre-execute and graphTools/post-execute events via ctx.on to perform auditing, policy gating, or result transformation before and after graph execution.

// 执行前门控
ctx.on('graphTools/pre-execute', async (execution, next) => {
  if (execution.tool === 'restricted_tool') {
    return { kind: 'deny', reason: 'Policy disabled' }
  }
  return next()
})

// 执行后转换
ctx.on('graphTools/post-execute', async (execution, outcome, next) => {
  if (execution.tool === 'sensitive_graph') {
    return { kind: 'accept', result: redact(outcome.result) }
  }
  return next()
})

Applicable Scenarios and Notes

This plugin is suitable for scenarios where you need to build complex workflows in DSH using LangGraph and require unified tool management and intelligent routing.

Notes:
* The plugin runs with the permissions of the current DSH process.
* It is recommended to review the source code and license (MIT) before use.
* TypeScript module support (type: module) is required.

Summary

dsh-graph-runtime encapsulates the details of integrating LangGraph in DSH through defineGraph and GraphRoutingAgent. It provides automatic mounting, validation hooks, and execution extension points, simplifying the development of graph tools and routing logic.

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye