File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
examples/mcp-client/langchain Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change 4545from contextlib import asynccontextmanager
4646from langchain .agents import create_agent as create_langchain_agent
4747from langchain_aws import ChatBedrock
48+ from langchain_core .messages import HumanMessage
4849from langchain_mcp_adapters .tools import load_mcp_tools
4950from mcp .client .session import ClientSession
5051from mcp_proxy_for_aws .client import aws_iam_mcp_client
@@ -91,13 +92,13 @@ async def create_agent():
9192
9293 # Create the agent with access to the tools
9394 agent = create_langchain_agent (
94- model = ChatBedrock (model_id = BEDROCK_MODEL_ID ), tools = mcp_tools
95+ model = ChatBedrock (model = BEDROCK_MODEL_ID ), tools = mcp_tools
9596 )
9697
9798 # Yield a callable interface to the agent
9899 async def agent_callable (user_input : str ) -> str :
99100 """Send a message to the agent and return its response."""
100- result = await agent .ainvoke ({'messages' : [( 'user' , user_input )]})
101+ result = await agent .ainvoke ({'messages' : [HumanMessage ( content = user_input )]})
101102 return result ['messages' ][- 1 ].content
102103
103104 yield agent_callable
Original file line number Diff line number Diff line change @@ -77,7 +77,12 @@ def aws_iam_mcp_client(
7777 session = boto3 .Session (** kwargs )
7878
7979 profile = session .profile_name
80- region : str = session .region_name
80+ region = session .region_name
81+
82+ if not region :
83+ raise ValueError (
84+ 'AWS region must be specified via aws_region parameter, AWS_PROFILE environment variable, or AWS config.'
85+ )
8186
8287 logger .debug ('AWS profile: %s' , profile )
8388 logger .debug ('AWS region: %s' , region )
You can’t perform that action at this time.
0 commit comments