-
Notifications
You must be signed in to change notification settings - Fork 216
Support MCP Tools in Agent #1810
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
e896bf3
init agent mcp, add mcp_tool in base agent
letonghan a29f1db
compatible with both yaml tools and mcp tools
letonghan 5ccda1c
Merge branch 'main' into agent_mcp
letonghan 12882a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] e5e52d2
refine async functions, enable singleton for agent instance
letonghan dc1900b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 4c15ebf
add mcp related arguments
letonghan 916e504
Merge branch 'agent_mcp' of https://github.com/letonghan/GenAIComps i…
letonghan 23f0bb0
refine mcp tool initialization, add ut for mcp
letonghan 7a9e04d
resolve conflict with main branch
letonghan 0087311
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 3944900
refine mcp service, start in docker container
letonghan 63e449f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 81b56dd
change args order
letonghan 66c2c04
Merge branch 'agent_mcp' of https://github.com/letonghan/GenAIComps i…
letonghan e158a10
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,51 +1,72 @@ | ||
| # Copyright (C) 2024 Intel Corporation | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| from .storage.persistence_redis import RedisPersistence | ||
| from .tools import get_mcp_tools, get_tools_descriptions | ||
| from .utils import load_python_prompt | ||
|
|
||
| agent = None | ||
|
|
||
| def instantiate_agent(args): | ||
|
|
||
| async def instantiate_agent(args): | ||
| global agent | ||
| strategy = args.strategy | ||
| with_memory = args.with_memory | ||
|
|
||
| if args.custom_prompt is not None: | ||
| print(f">>>>>> custom_prompt enabled, {args.custom_prompt}") | ||
| custom_prompt = load_python_prompt(args.custom_prompt) | ||
| else: | ||
| custom_prompt = None | ||
| # initialize tools | ||
| base_tools = get_tools_descriptions(getattr(args, "tools", None)) | ||
| mcp_tools = await get_mcp_tools(args.mcp_sse_server_url) if getattr(args, "mcp_sse_server_url", None) else [] | ||
| all_tools = base_tools + mcp_tools | ||
|
|
||
| if agent is None: | ||
|
|
||
| if args.custom_prompt is not None: | ||
| print(f">>>>>> custom_prompt enabled, {args.custom_prompt}") | ||
| custom_prompt = load_python_prompt(args.custom_prompt) | ||
| else: | ||
| custom_prompt = None | ||
|
|
||
| if strategy == "react_langchain": | ||
| from .strategy.react import ReActAgentwithLangchain | ||
|
|
||
| if strategy == "react_langchain": | ||
| from .strategy.react import ReActAgentwithLangchain | ||
| agent = ReActAgentwithLangchain( | ||
| args, tools_descriptions=all_tools, with_memory=with_memory, custom_prompt=custom_prompt | ||
| ) | ||
| elif strategy == "react_langgraph": | ||
| from .strategy.react import ReActAgentwithLanggraph | ||
|
|
||
| return ReActAgentwithLangchain(args, with_memory, custom_prompt=custom_prompt) | ||
| elif strategy == "react_langgraph": | ||
| from .strategy.react import ReActAgentwithLanggraph | ||
| agent = ReActAgentwithLanggraph( | ||
| args, tools_descriptions=all_tools, with_memory=with_memory, custom_prompt=custom_prompt | ||
| ) | ||
| elif strategy == "react_llama": | ||
| print("Initializing ReAct Agent with LLAMA") | ||
| from .strategy.react import ReActAgentLlama | ||
|
|
||
| return ReActAgentwithLanggraph(args, with_memory, custom_prompt=custom_prompt) | ||
| elif strategy == "react_llama": | ||
| print("Initializing ReAct Agent with LLAMA") | ||
| from .strategy.react import ReActAgentLlama | ||
| agent = ReActAgentLlama(args, tools_descriptions=all_tools, custom_prompt=custom_prompt) | ||
| elif strategy == "plan_execute": | ||
| from .strategy.planexec import PlanExecuteAgentWithLangGraph | ||
|
|
||
| return ReActAgentLlama(args, custom_prompt=custom_prompt) | ||
| elif strategy == "plan_execute": | ||
| from .strategy.planexec import PlanExecuteAgentWithLangGraph | ||
| agent = PlanExecuteAgentWithLangGraph( | ||
| args, tools_descriptions=all_tools, with_memory=with_memory, custom_prompt=custom_prompt | ||
| ) | ||
|
|
||
| return PlanExecuteAgentWithLangGraph(args, with_memory, custom_prompt=custom_prompt) | ||
| elif strategy == "rag_agent" or strategy == "rag_agent_llama": | ||
| print("Initializing RAG Agent") | ||
| from .strategy.ragagent import RAGAgent | ||
|
|
||
| elif strategy == "rag_agent" or strategy == "rag_agent_llama": | ||
| print("Initializing RAG Agent") | ||
| from .strategy.ragagent import RAGAgent | ||
| agent = RAGAgent(args, tools_descriptions=all_tools, with_memory=with_memory, custom_prompt=custom_prompt) | ||
| elif strategy == "sql_agent_llama": | ||
| print("Initializing SQL Agent Llama") | ||
| from .strategy.sqlagent import SQLAgentLlama | ||
|
|
||
| return RAGAgent(args, with_memory, custom_prompt=custom_prompt) | ||
| elif strategy == "sql_agent_llama": | ||
| print("Initializing SQL Agent Llama") | ||
| from .strategy.sqlagent import SQLAgentLlama | ||
| agent = SQLAgentLlama( | ||
| args, tools_descriptions=all_tools, with_memory=with_memory, custom_prompt=custom_prompt | ||
| ) | ||
| elif strategy == "sql_agent": | ||
| print("Initializing SQL Agent") | ||
| from .strategy.sqlagent import SQLAgent | ||
|
|
||
| return SQLAgentLlama(args, with_memory, custom_prompt=custom_prompt) | ||
| elif strategy == "sql_agent": | ||
| print("Initializing SQL Agent") | ||
| from .strategy.sqlagent import SQLAgent | ||
| agent = SQLAgent(args, tools_descriptions=all_tools, with_memory=with_memory, custom_prompt=custom_prompt) | ||
| else: | ||
| raise ValueError(f"Agent strategy: {strategy} not supported!") | ||
|
|
||
| return SQLAgent(args, with_memory, custom_prompt=custom_prompt) | ||
| else: | ||
| raise ValueError(f"Agent strategy: {strategy} not supported!") | ||
| return agent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.