File tree Expand file tree Collapse file tree 3 files changed +20
-3
lines changed
agents/chat_with_tools_agent Expand file tree Collapse file tree 3 files changed +20
-3
lines changed Original file line number Diff line number Diff line change 7
7
- [ 🤖 LangGraph Multi-Agent Supervisor] ( https://github.com/langchain-ai/langgraph-supervisor-py )
8
8
- [ Software Design 誌「実践 LLM アプリケーション開発」第 24 回サンプルコード] ( https://github.com/mahm/softwaredesign-llm-application/tree/main/24 )
9
9
- [ Streamlit] ( https://python.langchain.com/docs/integrations/callbacks/streamlit/ )
10
+ - [ LangChain MCP Adapters] ( https://github.com/langchain-ai/langchain-mcp-adapters )
11
+ - [ Research Agent with MCP Integration.] ( https://github.com/langchain-ai/deep_research_from_scratch/blob/main/src/deep_research_from_scratch/research_agent_mcp.py )
10
12
11
13
### Sample Codes
12
14
Original file line number Diff line number Diff line change
1
+ import asyncio
1
2
import json
2
3
3
4
from langchain_core .messages import ToolMessage
6
7
from template_langgraph .agents .chat_with_tools_agent .models import AgentState
7
8
from template_langgraph .llms .azure_openais import AzureOpenAiWrapper
8
9
from template_langgraph .loggers import get_logger
9
- from template_langgraph .tools .common import get_default_tools
10
+ from template_langgraph .tools .common import get_default_tools , is_async_call_required
10
11
11
12
logger = get_logger (__name__ )
12
13
@@ -25,10 +26,13 @@ def __call__(self, inputs: dict):
25
26
outputs = []
26
27
for tool_call in message .tool_calls :
27
28
try :
28
- tool_result = self .tools_by_name [tool_call ["name" ]].invoke (tool_call ["args" ])
29
+ if is_async_call_required (tool_call ["name" ]):
30
+ observation = asyncio .run (self .tools_by_name [tool_call ["name" ]].ainvoke (tool_call ["args" ]))
31
+ else :
32
+ observation = self .tools_by_name [tool_call ["name" ]].invoke (tool_call ["args" ])
29
33
outputs .append (
30
34
ToolMessage (
31
- content = json .dumps (tool_result .__str__ (), ensure_ascii = False ),
35
+ content = json .dumps (observation .__str__ (), ensure_ascii = False ),
32
36
name = tool_call ["name" ],
33
37
tool_call_id = tool_call ["id" ],
34
38
)
Original file line number Diff line number Diff line change @@ -25,3 +25,14 @@ def get_default_tools():
25
25
)
26
26
+ McpClientWrapper ().get_tools ()
27
27
)
28
+
29
+
30
+ def is_async_call_required (tool_name : str ) -> bool :
31
+ # FIXME: adhoc impl
32
+ if tool_name .startswith ("browser_" ):
33
+ return True
34
+ return tool_name in [
35
+ "echo" ,
36
+ "add" ,
37
+ # add async tool names here
38
+ ]
You can’t perform that action at this time.
0 commit comments