Files
hncb-fusion-deid-demo/agent/agent.py

56 lines
2.1 KiB
Python

"""
Cloud agent (steps 3 + 7) -- runs on Amazon Bedrock AgentCore Runtime.
It receives an ALREADY de-identified prompt from Fusion (contains a token like
CUST_000123, never a name), reasons with a Bedrock model, calls the RAG tool
through AgentCore Gateway (MCP), and returns de-identified talking points.
Fusion restores the real identity on the way back out -- not this agent.
Framework: Strands. Deploy target: AgentCore Runtime (see scripts/agentcore_setup.py).
Pin versions in requirements.txt; SDK surfaces move quickly.
"""
import os
from bedrock_agentcore.runtime import BedrockAgentCoreApp
from strands import Agent
from strands.models import BedrockModel
from strands.tools.mcp import MCPClient
from mcp.client.streamable_http import streamablehttp_client
app = BedrockAgentCoreApp()
GATEWAY_URL = os.environ["AGENTCORE_GATEWAY_URL"] # set by agentcore_setup.py
GATEWAY_TOKEN = os.environ.get("AGENTCORE_GATEWAY_TOKEN", "")
MODEL_ID = os.environ.get("BEDROCK_MODEL_ID", "anthropic.claude-3-5-sonnet-20241022-v2:0")
SYSTEM_PROMPT = (
"You are a financial-advisor assistant. You will be given a customer reference "
"that is an opaque TOKEN (e.g. CUST_000123). Treat it as an opaque identifier: "
"never invent a name, and always pass the token verbatim to tools. Use the "
"get_customer_activity_summary tool to fetch a de-identified evidence package, "
"then produce concise, numbered visit talking points based only on that evidence. "
"Do not include the raw token in your final talking points."
)
def _mcp_client():
headers = {"Authorization": f"Bearer {GATEWAY_TOKEN}"} if GATEWAY_TOKEN else {}
return MCPClient(lambda: streamablehttp_client(GATEWAY_URL, headers=headers))
@app.entrypoint
def invoke(payload):
"""payload == {'prompt': '<de-identified prompt from Fusion>'}"""
prompt = payload.get("prompt", "")
with _mcp_client() as client:
agent = Agent(
model=BedrockModel(model_id=MODEL_ID),
system_prompt=SYSTEM_PROMPT,
tools=client.list_tools_sync(),
)
result = agent(prompt)
return {"result": str(result)}
if __name__ == "__main__":
app.run()