Files
wehub-resource-sync e04ed9c211
CF: Deploy Dev Docs / deploy (push) Has been cancelled
Sync Labels / build (push) Has been cancelled
tests / unit tests (macos-latest) (push) Has been cancelled
tests / unit tests (windows-latest) (push) Has been cancelled
tests / unit tests (ubuntu-latest) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:32:45 +08:00

2.2 KiB

title, type, weight, description, sample_filters, is_sample
title type weight description sample_filters is_sample
Javascript: Pre & Post Processing docs 2 How to add pre- and post- processing to your Agents using JS.
Pre & Post Processing
JavaScript
ADK
LangChain
true

Prerequisites

This tutorial assumes that you have set up MCP Toolbox with a basic agent as described in the local quickstart.

This guide demonstrates how to implement these patterns in your Toolbox applications.

Implementation

{{< tabpane persist=header >}} {{% tab header="ADK" text=true %}} The following example demonstrates how to use the beforeToolCallback and afterToolCallback hooks in the ADK LlmAgent to implement pre and post processing logic.

{{< include "adk/agent.js" "js" >}}

You can also add model-level (beforeModelCallback, afterModelCallback) and agent-level (beforeAgentCallback, afterAgentCallback) hooks to intercept messages at different stages of the execution loop.

For more information, see the ADK Callbacks documentation. {{% /tab %}} {{% tab header="Langchain" text=true %}} The following example demonstrates how to use ToolboxClient with LangChain's middleware to implement pre and post processing for tool calls.

{{< include "langchain/agent.js" "js" >}}

You can also use the wrapModelCall hook to intercept messages before and after model calls. You can also use node-style hooks to intercept messages at the agent and model level. See the LangChain Middleware documentation for details on these additional hook types.

{{% /tab %}} {{< /tabpane >}}

Results

The output should look similar to the following.

{{< notice note >}} The exact responses may vary due to the non-deterministic nature of LLMs and differences between orchestration frameworks. {{< /notice >}}

AI: Booking Confirmed! You earned 500 Loyalty Points with this stay.

AI: Error: Maximum stay duration is 14 days.