-
Notifications
You must be signed in to change notification settings - Fork 148
Add ContextRouter #275
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 ContextRouter #275
Conversation
🦋 Changeset detectedLatest commit: c8f0e8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
1da2903
to
e1daa91
Compare
43f7d09
to
da66fa3
Compare
da66fa3
to
c8f0e8c
Compare
includeResources: boolean | ||
) { | ||
return `<integrations_list> | ||
You have access to multiple integrations via Model Context Protocol (MCP). These integrations provide you with tools which you can use to execute to complete tasks or retrieive information. |
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.
retrieive -> retrieve
which you can use to execute -> which you can execute
@@ -308,12 +287,12 @@ export class MCPClientManager { | |||
* | |||
* @param includeResources Whether to include resources in the prompt. This may be useful if you include a tool to fetch resources OR if the servers you connect to interact with resources. |
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.
This function no longer has a parameter
I like this approach in that you can expose some very clean functionality for the user. I dont like that you are hardcoding a workflow to create an agent (llm + set some active tools). ie,
imo the agent should be free to create itself over time and we should accomodate. It should have a tool which can start server, stop server and the tools should be updated for the next step. |
The ContextRouter itself is more of a way for users to define their own ways of filtering tools/resources. This could be an LLM workflow to filter tools ( This design doesn't preclude implementing a ContextRouter that exposes filtering tools to the Agent. For example, to support the usecase you describe, something like should work: class ToolContextRouter extends BaseContextRouter {
private activeServers = []
listTools() {
// filter list tools to only include active servers
const filteredConnections = {}
for (const serverId in activeServers) {
filteredConnections[serverId] = this.connectionManager[serverId]
}
return getNamespacedData(filteredConnections, "tools");
}
// returns tools of activeServers and two utility tools to add/remove servers from context
getAITools() {
return {
...super.getAITools(),
addMcpServer: {
// adds a server to this.activeServers
},
removeMcpServer: {
// removes a server from this.activeServers
}
}
}
systemPrompt() {
// describes the servers that are accessible and how to use addMcpServer/removeMcpServer
}
} This is an abbreviated implementation, but I think I'll play around with adding something like the above as an included ContextRouter implementation in this PR like you describe. |
I've expanded the scope of this PR per discussion w/ @threepointone on MCP Routers. This PR adds the
ContextRouter
interface, which does the following:I have purposely excluded prompts and resource templates from the ContextRouter interface because those features are not intended to be model controlled. Tools are intended to be LLM controlled, and resources may be LLM controlled.
Given this interface, I've implemented two ContextRouters:
Here is a sample agent using the
LLMContextRouter
: