Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions src/assets/__tests__/__snapshots__/assets.snapshot.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,9 @@ from autogen_agentchat.agents import AssistantAgent
from autogen_core.tools import FunctionTool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_tools
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger
Expand All @@ -928,14 +930,20 @@ tools = [add_numbers_tool]
async def invoke(payload, context):
log.info("Invoking Agent.....")

{{#unless isVpc}}
# Get MCP Tools
mcp_tools = await get_streamable_http_mcp_tools()

{{/unless}}
# Define an AssistantAgent with the model and tools
agent = AssistantAgent(
name="{{ name }}",
model_client=load_model(),
{{#unless isVpc}}
tools=tools + mcp_tools,
{{else}}
tools=tools,
{{/unless}}
system_message="You are a helpful assistant. Use tools when appropriate.",
)

Expand Down Expand Up @@ -1584,7 +1592,9 @@ from google.adk.sessions import InMemorySessionService
from google.genai import types
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger
Expand All @@ -1601,8 +1611,10 @@ def add_numbers(a: int, b: int) -> int:
return a + b


{{#unless isVpc}}
# Get MCP Toolset
mcp_toolset = [get_streamable_http_mcp_client()]
{{/unless}}

_credentials_loaded = False

Expand All @@ -1619,7 +1631,11 @@ agent = Agent(
name="{{ name }}",
description="Agent to answer questions",
instruction="I can answer your questions using the knowledge I have!",
{{#unless isVpc}}
tools=mcp_toolset + [add_numbers],
{{else}}
tools=[add_numbers],
{{/unless}}
)


Expand Down Expand Up @@ -1864,7 +1880,9 @@ from langgraph.prebuilt import create_react_agent
from langchain.tools import tool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger
Expand Down Expand Up @@ -1893,14 +1911,20 @@ tools = [add_numbers]
async def invoke(payload, context):
log.info("Invoking Agent.....")

{{#unless isVpc}}
# Get MCP Client
mcp_client = get_streamable_http_mcp_client()

# Load MCP Tools
mcp_tools = await mcp_client.get_tools()

{{/unless}}
# Define the agent using create_react_agent
{{#unless isVpc}}
graph = create_react_agent(get_or_create_model(), tools=mcp_tools + tools)
{{else}}
graph = create_react_agent(get_or_create_model(), tools=tools)
{{/unless}}

# Process the user prompt
prompt = payload.get("prompt", "What can you help me with?")
Expand Down Expand Up @@ -2210,13 +2234,17 @@ exports[`Assets Directory Snapshots > Python framework assets > python/python/op
from agents import Agent, Runner, function_tool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger

{{#unless isVpc}}
# Get MCP Server
mcp_server = get_streamable_http_mcp_client()
{{/unless}}

_credentials_loaded = False

Expand All @@ -2234,6 +2262,7 @@ def add_numbers(a: int, b: int) -> int:
return a + b


{{#unless isVpc}}
# Define the agent execution
async def main(query):
ensure_credentials_loaded()
Expand All @@ -2251,6 +2280,22 @@ async def main(query):
except Exception as e:
log.error(f"Error during agent execution: {e}", exc_info=True)
raise e
{{else}}
# Define the agent execution
async def main(query):
ensure_credentials_loaded()
try:
agent = Agent(
name="{{ name }}",
model="gpt-4.1",
tools=[add_numbers]
)
result = await Runner.run(agent, query)
return result
except Exception as e:
log.error(f"Error during agent execution: {e}", exc_info=True)
raise e
{{/unless}}


@app.entrypoint
Expand Down Expand Up @@ -2455,16 +2500,20 @@ exports[`Assets Directory Snapshots > Python framework assets > python/python/st
"from strands import Agent, tool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}
{{#if hasMemory}}
from memory.session import get_memory_session_manager
{{/if}}

app = BedrockAgentCoreApp()
log = app.logger

{{#unless isVpc}}
# Define a Streamable HTTP MCP Client
mcp_client = get_streamable_http_mcp_client()
{{/unless}}

# Define a collection of tools used by the model
tools = []
Expand All @@ -2490,7 +2539,11 @@ def agent_factory():
system_prompt="""
You are a helpful assistant. Use tools when appropriate.
""",
{{#unless isVpc}}
tools=tools+[mcp_client]
{{else}}
tools=tools
{{/unless}}
)
return cache[key]
return get_or_create_agent
Expand All @@ -2506,7 +2559,11 @@ def get_or_create_agent():
system_prompt="""
You are a helpful assistant. Use tools when appropriate.
""",
{{#unless isVpc}}
tools=tools+[mcp_client]
{{else}}
tools=tools
{{/unless}}
)
return _agent
{{/if}}
Expand Down
8 changes: 8 additions & 0 deletions src/assets/python/autogen/base/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from autogen_core.tools import FunctionTool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_tools
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger
Expand All @@ -27,14 +29,20 @@ def add_numbers(a: int, b: int) -> int:
async def invoke(payload, context):
log.info("Invoking Agent.....")

{{#unless isVpc}}
# Get MCP Tools
mcp_tools = await get_streamable_http_mcp_tools()

{{/unless}}
# Define an AssistantAgent with the model and tools
agent = AssistantAgent(
name="{{ name }}",
model_client=load_model(),
{{#unless isVpc}}
tools=tools + mcp_tools,
{{else}}
tools=tools,
{{/unless}}
system_message="You are a helpful assistant. Use tools when appropriate.",
)

Expand Down
8 changes: 8 additions & 0 deletions src/assets/python/googleadk/base/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
from google.genai import types
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger
Expand All @@ -22,8 +24,10 @@ def add_numbers(a: int, b: int) -> int:
return a + b


{{#unless isVpc}}
# Get MCP Toolset
mcp_toolset = [get_streamable_http_mcp_client()]
{{/unless}}

_credentials_loaded = False

Expand All @@ -40,7 +44,11 @@ def ensure_credentials_loaded():
name="{{ name }}",
description="Agent to answer questions",
instruction="I can answer your questions using the knowledge I have!",
{{#unless isVpc}}
tools=mcp_toolset + [add_numbers],
{{else}}
tools=[add_numbers],
{{/unless}}
)


Expand Down
8 changes: 8 additions & 0 deletions src/assets/python/langchain_langgraph/base/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
from langchain.tools import tool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger
Expand Down Expand Up @@ -33,14 +35,20 @@ def add_numbers(a: int, b: int) -> int:
async def invoke(payload, context):
log.info("Invoking Agent.....")

{{#unless isVpc}}
# Get MCP Client
mcp_client = get_streamable_http_mcp_client()

# Load MCP Tools
mcp_tools = await mcp_client.get_tools()

{{/unless}}
# Define the agent using create_react_agent
{{#unless isVpc}}
graph = create_react_agent(get_or_create_model(), tools=mcp_tools + tools)
{{else}}
graph = create_react_agent(get_or_create_model(), tools=tools)
{{/unless}}

# Process the user prompt
prompt = payload.get("prompt", "What can you help me with?")
Expand Down
21 changes: 21 additions & 0 deletions src/assets/python/openaiagents/base/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
from agents import Agent, Runner, function_tool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}

app = BedrockAgentCoreApp()
log = app.logger

{{#unless isVpc}}
# Get MCP Server
mcp_server = get_streamable_http_mcp_client()
{{/unless}}

_credentials_loaded = False

Expand All @@ -26,6 +30,7 @@ def add_numbers(a: int, b: int) -> int:
return a + b


{{#unless isVpc}}
# Define the agent execution
async def main(query):
ensure_credentials_loaded()
Expand All @@ -43,6 +48,22 @@ async def main(query):
except Exception as e:
log.error(f"Error during agent execution: {e}", exc_info=True)
raise e
{{else}}
# Define the agent execution
async def main(query):
ensure_credentials_loaded()
try:
agent = Agent(
name="{{ name }}",
model="gpt-4.1",
tools=[add_numbers]
)
result = await Runner.run(agent, query)
return result
except Exception as e:
log.error(f"Error during agent execution: {e}", exc_info=True)
raise e
{{/unless}}


@app.entrypoint
Expand Down
12 changes: 12 additions & 0 deletions src/assets/python/strands/base/main.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from strands import Agent, tool
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from model.load import load_model
{{#unless isVpc}}
from mcp_client.client import get_streamable_http_mcp_client
{{/unless}}
{{#if hasMemory}}
from memory.session import get_memory_session_manager
{{/if}}

app = BedrockAgentCoreApp()
log = app.logger

{{#unless isVpc}}
# Define a Streamable HTTP MCP Client
mcp_client = get_streamable_http_mcp_client()
{{/unless}}

# Define a collection of tools used by the model
tools = []
Expand All @@ -36,7 +40,11 @@ def get_or_create_agent(session_id, user_id):
system_prompt="""
You are a helpful assistant. Use tools when appropriate.
""",
{{#unless isVpc}}
tools=tools+[mcp_client]
{{else}}
tools=tools
{{/unless}}
)
return cache[key]
return get_or_create_agent
Expand All @@ -52,7 +60,11 @@ def get_or_create_agent():
system_prompt="""
You are a helpful assistant. Use tools when appropriate.
""",
{{#unless isVpc}}
tools=tools+[mcp_client]
{{else}}
tools=tools
{{/unless}}
)
return _agent
{{/if}}
Expand Down
1 change: 1 addition & 0 deletions src/cli/operations/agent/generate/schema-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export function mapGenerateConfigToRenderConfig(
modelProvider: config.modelProvider,
hasMemory: config.memory !== 'none',
hasIdentity: identityProviders.length > 0,
isVpc: config.networkMode === 'VPC',
buildType: config.buildType,
memoryProviders: mapMemoryOptionToMemoryProviders(config.memory, config.projectName),
identityProviders,
Expand Down
5 changes: 3 additions & 2 deletions src/cli/templates/BaseRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ export abstract class BaseRenderer {
hasMcp: false, // MCP is configured separately
};

// Always render base template
// Always render base template (skip mcp_client for VPC - no public internet for external MCP servers)
const baseDir = path.join(templateDir, 'base');
await copyAndRenderDir(baseDir, projectDir, templateData);
const skipDirs = this.config.isVpc ? new Set(['mcp_client']) : undefined;
await copyAndRenderDir(baseDir, projectDir, templateData, skipDirs);

// Render capability templates based on config
// Only render if the capability directory exists (not all SDKs have all capabilities)
Expand Down
Loading
Loading