-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Add providerToolDefinition field to support built-in client tools
#9261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add providerToolDefinition field to support built-in client tools
#9261
Conversation
|
christian-bromann
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if we want to apply this to the general tool primitive when we currently only see support for this (ever) in 1 provider. Looking at the attached PR adding a middleware to the createAgent I am concerned about mixing provider related code with our general langchain package.
Some thoughts:
- instead of introducing
providerToolDefinition, should we just use themetadatafield for this? - let's move everything in
libs/langchain/src/agents/middleware/anthropicToolsfrom your PR into the anthropic provider package and use schema primitives from the provider packages directly - export these tools (currently defined from the middleware) from the provider package, attach metadata to it and make a small change in the chat model to adjust for it
So the final interface may look something like:
import { tools } from "@langchain/anthropic"
const agent = createAgent({
model: "anthropic:...",
tools: [
tools.textEditor({
type: "fs" // or "memory" or custom implementation
}),
tools.memory()
]
})What do you think?
|
@christian-bromann yeah that all makes sense to me. I guess one question is how we'd handle the version of Anthropic tools that stores the file contents on the graph state. That seems to rely on langgraph / middleware types. Did we end up finding a way to do that without the circular deps issue? |
|
@pokey would there still be a need for middleware if we abstract this as tool functions? |
|
Good question. There are 4 different middlewares in my PR, for combinations of (file system vs graph state X memory vs file tool). The one that leverages the most middleware functionality is memory tool with graph state. That uses the following middleware functionality:
If we can accomplish all of these things with just tools and no middleware, then I'm all for it! See https://github.com/pokey/langchainjs/blob/pokey/featlangchainagents-add-anthropic-tools-middleware/libs/langchain/src/agents/middleware/anthropicTools/index.ts for the relevant code |
Why?
Today, the way we determine whether a tool is a server or client tool is based on its shape: it it has
{type: ..., name: ...}then it is server, otherwise client. This heuristic breaks for Anthropic memory and text editor tools, which have that shape, but are client toolsWhat?
This PR introduces the
providerToolDefinitionfield on client tools, allowing you to define a client tool but override the way it presents itself to the provider, rather than automatically generating based on schema