Invoking the agent.
This commit is contained in:
5
examples/aws-agentcore/server/env.example
Normal file
5
examples/aws-agentcore/server/env.example
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
AWS_SECRET_ACCESS_KEY=
|
||||||
|
AWS_ACCESS_KEY_ID=
|
||||||
|
AWS_REGION=us-east-1=
|
||||||
|
# You can find this inside .bedrock_agentcore.yaml
|
||||||
|
AGENT_RUNTIME_ARN=
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
from contextlib import asynccontextmanager
|
from contextlib import asynccontextmanager
|
||||||
@@ -14,6 +15,7 @@ from typing import Any, Dict, List, Optional, TypedDict, Union
|
|||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
from dotenv import load_dotenv
|
||||||
from fastapi import BackgroundTasks, FastAPI, Request, Response
|
from fastapi import BackgroundTasks, FastAPI, Request, Response
|
||||||
from fastapi.responses import RedirectResponse
|
from fastapi.responses import RedirectResponse
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
@@ -24,6 +26,8 @@ from pipecat.transports.smallwebrtc.request_handler import (
|
|||||||
)
|
)
|
||||||
from pipecat_ai_small_webrtc_prebuilt.frontend import SmallWebRTCPrebuiltUI
|
from pipecat_ai_small_webrtc_prebuilt.frontend import SmallWebRTCPrebuiltUI
|
||||||
|
|
||||||
|
load_dotenv(override=True)
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# Mount the frontend at /
|
# Mount the frontend at /
|
||||||
@@ -33,7 +37,10 @@ app.mount("/client", SmallWebRTCPrebuiltUI)
|
|||||||
active_sessions: Dict[str, Dict[str, Any]] = {}
|
active_sessions: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
# Initialize Bedrock client
|
# Initialize Bedrock client
|
||||||
bedrock = boto3.client("bedrock-agent-runtime")
|
bedrock = boto3.client("bedrock-agentcore")
|
||||||
|
|
||||||
|
# You can find this inside .bedrock_agentcore.yaml
|
||||||
|
AGENT_RUNTIME_ARN = os.getenv("AGENT_RUNTIME_ARN")
|
||||||
|
|
||||||
|
|
||||||
@app.get("/", include_in_schema=False)
|
@app.get("/", include_in_schema=False)
|
||||||
@@ -48,17 +55,17 @@ async def offer(request: Request):
|
|||||||
data = await request.json()
|
data = await request.json()
|
||||||
print(f"Received offer: {data}")
|
print(f"Received offer: {data}")
|
||||||
|
|
||||||
response = bedrock.invoke_agent(
|
response = bedrock.invoke_agent_runtime(
|
||||||
# TODO: create a custom randon id, maybe based on the pc_id
|
agentRuntimeArn=AGENT_RUNTIME_ARN,
|
||||||
agentId="network_test-11111111",
|
contentType="application/json",
|
||||||
agentAliasId="Network Test Agent",
|
accept="application/json",
|
||||||
sessionId="user-123456-conversation-11111",
|
payload=json.dumps({"input": data}),
|
||||||
inputText=json.dumps({"input": data}),
|
# TODO: create a custom randon id
|
||||||
|
runtimeSessionId="user-123456-conversation-111115555",
|
||||||
)
|
)
|
||||||
|
|
||||||
result = response["body"].read().decode("utf-8")
|
print(f"Received response: {response}")
|
||||||
|
return response
|
||||||
return {"result": result}
|
|
||||||
|
|
||||||
|
|
||||||
@app.patch("/api/offer")
|
@app.patch("/api/offer")
|
||||||
|
|||||||
Reference in New Issue
Block a user