@@ -904,7 +904,9 @@ from autogen_agentchat.agents import AssistantAgent
904904from autogen_core.tools import FunctionTool
905905from bedrock_agentcore.runtime import BedrockAgentCoreApp
906906from model.load import load_model
907+ { {#unless isVpc }}
907908from mcp_client.client import get_streamable_http_mcp_tools
909+ { {/unless }}
908910
909911app = BedrockAgentCoreApp()
910912log = app.logger
@@ -928,14 +930,20 @@ tools = [add_numbers_tool]
928930async def invoke(payload, context):
929931 log.info("Invoking Agent.....")
930932
933+ { {#unless isVpc }}
931934 # Get MCP Tools
932935 mcp_tools = await get_streamable_http_mcp_tools()
933936
937+ { {/unless }}
934938 # Define an AssistantAgent with the model and tools
935939 agent = AssistantAgent(
936940 name="{ { name }} ",
937941 model_client=load_model(),
942+ { {#unless isVpc }}
938943 tools=tools + mcp_tools,
944+ { {else }}
945+ tools=tools,
946+ { {/unless }}
939947 system_message="You are a helpful assistant. Use tools when appropriate.",
940948 )
941949
@@ -1584,7 +1592,9 @@ from google.adk.sessions import InMemorySessionService
15841592from google.genai import types
15851593from bedrock_agentcore.runtime import BedrockAgentCoreApp
15861594from model.load import load_model
1595+ { {#unless isVpc }}
15871596from mcp_client.client import get_streamable_http_mcp_client
1597+ { {/unless }}
15881598
15891599app = BedrockAgentCoreApp()
15901600log = app.logger
@@ -1601,8 +1611,10 @@ def add_numbers(a: int, b: int) -> int:
16011611 return a + b
16021612
16031613
1614+ { {#unless isVpc }}
16041615# Get MCP Toolset
16051616mcp_toolset = [get_streamable_http_mcp_client()]
1617+ { {/unless }}
16061618
16071619_credentials_loaded = False
16081620
@@ -1619,7 +1631,11 @@ agent = Agent(
16191631 name="{ { name }} ",
16201632 description="Agent to answer questions",
16211633 instruction="I can answer your questions using the knowledge I have!",
1634+ { {#unless isVpc }}
16221635 tools=mcp_toolset + [add_numbers],
1636+ { {else }}
1637+ tools=[add_numbers],
1638+ { {/unless }}
16231639)
16241640
16251641
@@ -1864,7 +1880,9 @@ from langgraph.prebuilt import create_react_agent
18641880from langchain.tools import tool
18651881from bedrock_agentcore.runtime import BedrockAgentCoreApp
18661882from model.load import load_model
1883+ { {#unless isVpc }}
18671884from mcp_client.client import get_streamable_http_mcp_client
1885+ { {/unless }}
18681886
18691887app = BedrockAgentCoreApp()
18701888log = app.logger
@@ -1893,14 +1911,20 @@ tools = [add_numbers]
18931911async def invoke(payload, context):
18941912 log.info("Invoking Agent.....")
18951913
1914+ { {#unless isVpc }}
18961915 # Get MCP Client
18971916 mcp_client = get_streamable_http_mcp_client()
18981917
18991918 # Load MCP Tools
19001919 mcp_tools = await mcp_client.get_tools()
19011920
1921+ { {/unless }}
19021922 # Define the agent using create_react_agent
1923+ { {#unless isVpc }}
19031924 graph = create_react_agent(get_or_create_model(), tools=mcp_tools + tools)
1925+ { {else }}
1926+ graph = create_react_agent(get_or_create_model(), tools=tools)
1927+ { {/unless }}
19041928
19051929 # Process the user prompt
19061930 prompt = payload.get("prompt", "What can you help me with?")
@@ -2210,13 +2234,17 @@ exports[`Assets Directory Snapshots > Python framework assets > python/python/op
22102234from agents import Agent, Runner, function_tool
22112235from bedrock_agentcore.runtime import BedrockAgentCoreApp
22122236from model.load import load_model
2237+ { {#unless isVpc }}
22132238from mcp_client.client import get_streamable_http_mcp_client
2239+ { {/unless }}
22142240
22152241app = BedrockAgentCoreApp()
22162242log = app.logger
22172243
2244+ { {#unless isVpc }}
22182245# Get MCP Server
22192246mcp_server = get_streamable_http_mcp_client()
2247+ { {/unless }}
22202248
22212249_credentials_loaded = False
22222250
@@ -2234,6 +2262,7 @@ def add_numbers(a: int, b: int) -> int:
22342262 return a + b
22352263
22362264
2265+ { {#unless isVpc }}
22372266# Define the agent execution
22382267async def main(query):
22392268 ensure_credentials_loaded()
@@ -2251,6 +2280,22 @@ async def main(query):
22512280 except Exception as e:
22522281 log.error(f"Error during agent execution: { e } ", exc_info=True)
22532282 raise e
2283+ { {else }}
2284+ # Define the agent execution
2285+ async def main(query):
2286+ ensure_credentials_loaded()
2287+ try:
2288+ agent = Agent(
2289+ name="{ { name }} ",
2290+ model="gpt-4.1",
2291+ tools=[add_numbers]
2292+ )
2293+ result = await Runner.run(agent, query)
2294+ return result
2295+ except Exception as e:
2296+ log.error(f"Error during agent execution: { e } ", exc_info=True)
2297+ raise e
2298+ { {/unless }}
22542299
22552300
22562301@app.entrypoint
@@ -2455,16 +2500,20 @@ exports[`Assets Directory Snapshots > Python framework assets > python/python/st
24552500"from strands import Agent, tool
24562501from bedrock_agentcore.runtime import BedrockAgentCoreApp
24572502from model.load import load_model
2503+ { {#unless isVpc }}
24582504from mcp_client.client import get_streamable_http_mcp_client
2505+ { {/unless }}
24592506{ {#if hasMemory }}
24602507from memory.session import get_memory_session_manager
24612508{ {/if }}
24622509
24632510app = BedrockAgentCoreApp()
24642511log = app.logger
24652512
2513+ { {#unless isVpc }}
24662514# Define a Streamable HTTP MCP Client
24672515mcp_client = get_streamable_http_mcp_client()
2516+ { {/unless }}
24682517
24692518# Define a collection of tools used by the model
24702519tools = []
@@ -2490,7 +2539,11 @@ def agent_factory():
24902539 system_prompt="""
24912540 You are a helpful assistant. Use tools when appropriate.
24922541 """,
2542+ { {#unless isVpc }}
24932543 tools=tools+[mcp_client]
2544+ { {else }}
2545+ tools=tools
2546+ { {/unless }}
24942547 )
24952548 return cache[key]
24962549 return get_or_create_agent
@@ -2506,7 +2559,11 @@ def get_or_create_agent():
25062559 system_prompt="""
25072560 You are a helpful assistant. Use tools when appropriate.
25082561 """,
2562+ { {#unless isVpc }}
25092563 tools=tools+[mcp_client]
2564+ { {else }}
2565+ tools=tools
2566+ { {/unless }}
25102567 )
25112568 return _agent
25122569{ {/if }}
0 commit comments