Skip to content

Instantly share code, notes, and snippets.

@YurgenUA
Created January 17, 2026 00:32
Show Gist options
  • Select an option

  • Save YurgenUA/223867bb2a63bf148b57c589725fecc5 to your computer and use it in GitHub Desktop.

Select an option

Save YurgenUA/223867bb2a63bf148b57c589725fecc5 to your computer and use it in GitHub Desktop.
import boto3
import json
agent_arn = launch_result.agent_arn
agentcore_client = boto3.client(
'bedrock-agentcore',
region_name=region
)
boto3_response = agentcore_client.invoke_agent_runtime(
agentRuntimeArn=agent_arn,
qualifier="DEFAULT",
payload=json.dumps({"prompt": "What is the weather?"})
)
if "text/event-stream" in boto3_response.get("contentType", ""):
content = []
for line in boto3_response["response"].iter_lines(chunk_size=1):
if line:
line = line.decode("utf-8")
if line.startswith("data: "):
line = line[6:]
print(line)
content.append(line)
display(Markdown("\n".join(content)))
else:
try:
events = []
for event in boto3_response.get("response", []):
events.append(event)
except Exception as e:
events = [f"Error reading EventStream: {e}"]
display(Markdown(json.loads(events[0].decode("utf-8"))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment