mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-18 19:05:19 -05:00
## Description Trigger has been tested corresponding to local changes. Latest successful run: https://pantheon.corp.google.com/cloud-build/builds;region=global/0e7720f6-451c-4a89-8a43-a35131ec90a5;step=0?project=toolbox-testing-438616 Note: After merging, update JS pre and post processing sample testing trigger. ## PR Checklist > Thank you for opening a Pull Request! Before submitting your PR, there are a > few things you can do to make sure it goes smoothly: - [ ] Make sure you reviewed [CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md) - [ ] Make sure to open an issue as a [bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Make sure to add `!` if this involve a breaking change 🛠️ Fixes #<issue_number_goes_here> --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Anubhav Dhawan <anubhavdhawan@google.com>
48 lines
1.5 KiB
Markdown
48 lines
1.5 KiB
Markdown
---
|
|
title: "Javascript"
|
|
type: docs
|
|
weight: 2
|
|
description: >
|
|
How to add pre- and post- processing to your Agents using JS.
|
|
---
|
|
|
|
## Prerequisites
|
|
|
|
This tutorial assumes that you have set up MCP Toolbox with a basic agent as described in the [local quickstart](../../getting-started/local_quickstart_js.md).
|
|
|
|
This guide demonstrates how to implement these patterns in your Toolbox applications.
|
|
|
|
## Implementation
|
|
|
|
{{< tabpane persist=header >}}
|
|
{{% tab header="ADK" text=true %}}
|
|
Coming soon.
|
|
{{% /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.
|
|
|
|
```js
|
|
{{< include "js/langchain/agent.js" >}}
|
|
```
|
|
|
|
You can also use the `wrapModelCall` hook to intercept messages before and after model calls.
|
|
You can also use [node-style hooks](https://docs.langchain.com/oss/javascript/langchain/middleware/custom#node-style-hooks) to intercept messages at the agent and model level.
|
|
See the [LangChain Middleware documentation](https://docs.langchain.com/oss/javascript/langchain/middleware/custom#tool-call-monitoring) 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.
|
|
```
|