Is the Bull Market Still Alive? Stock Analysis with OpenAI and AgentCore
This article walks through deploying OpenAI's open‑source GPT‑OSS models on Amazon SageMaker, building a multi‑agent stock‑analysis workflow with LangGraph, and orchestrating the agents via Amazon Bedrock AgentCore, providing end‑to‑end code, configuration steps, and cleanup procedures.
Open‑source GPT‑OSS models
OpenAI released two open‑source weight models: gpt‑oss‑120b (1.17 trillion parameters) and gpt‑oss‑20b (210 billion parameters). Both use a Mixture‑of‑Experts (MoE) architecture with 128 K context windows. The MoE design includes 128 experts for the 120 B model and 32 experts for the 20 B model; each token is routed to 4 experts. MXFP4 4‑bit quantization compresses the models to 63 GB (120 B) and 14 GB (20 B), enabling execution on a single GPU.
Deploying gpt‑oss‑20b on Amazon SageMaker
The model is served with the vLLM inference framework (v0.10.0‑gpt‑oss) inside a Docker container. The deployment uses a G6e instance (ml.g6e.4xlarge) with one L40 GPU.
inference_image = f"{account_id}.dkr.ecr.{region}.amazonaws.com/vllm:v0.10.0-gpt-oss"
instance_type = "ml.g6e.4xlarge"
num_gpu = 1
model_name = sagemakerutilsname_from_base("model-byoc")
endpoint_name = model_name
config = {
"OPTION_MODEL": "openai/gpt-oss-20b",
"OPTION_SERVED_MODEL_NAME": "model",
"OPTION_TENSOR_PARALLEL_SIZE": json.dumps(num_gpu),
"OPTION_ASYNC_SCHEDULING": "true"
}Creating the SageMaker model and launching the endpoint:
lmi_model = sagemaker.Model(
image_uri=inference_image,
env=config,
role=role,
name=model_name,
)
lmi_model.deploy(
initial_instance_count=1,
instance_type=instance_type,
endpoint_name=endpoint_name,
endpoint_type=sagemaker.enums.EndpointType.INFERENCE_COMPONENT_BASED,
inference_component_name=f"ic-{model_name}",
resources=ResourceRequirements(requests={"num_accelerators": num_gpu, "memory": 1024*5, "copies": 1})
)Multi‑agent stock‑analysis workflow with LangGraph
LangGraph orchestrates three specialized agents:
gather_stock_data : collects current price, historical performance, financial ratios and recent news for a given ticker.
analyze_stock_performance : computes technical trends, volatility, P/E, dividend yield, and produces a composite investment score.
generate_stock_report : formats the analysis into a PDF and uploads it to Amazon S3.
Local testing in a Jupyter notebook (see the notebook at https://github.com/aws-samples/sagemaker-genai-hosting-examples/blob/main/OpenAI/gpt-oss/deploy/openai_gpt_oss.ipynb):
from langgraph_stock_local import langgraph_stock_sagemaker
result = langgraph_stock_sagemaker({"prompt": "Analyze SIM_STOCK Stock for Investment purposes."})
print(result)Deploying the agents to Amazon Bedrock AgentCore
An IAM role that permits Bedrock AgentCore to invoke the SageMaker endpoint, manage ECR repositories, write CloudWatch logs and interact with Bedrock services is created with the helper library:
role_arn = create_bedrock_agentcore_role(
role_name="MyStockAnalyzerRole",
sagemaker_endpoint_name="your-endpoint-name",
region="us-west-2"
)The Bedrock AgentCore Starter Toolkit packages the code, builds the container and launches the runtime:
from bedrock_agentcore_starter_toolkit import Runtime
agentcore_runtime = Runtime()
agentcore_runtime.configure(
entrypoint="langgraph_stock_sagemaker_gpt_oss.py",
execution_role=role_arn,
auto_create_ecr=True,
requirements_file="requirements.txt",
region="us-west-2",
agent_name="stock_analyzer_agent"
)
launch_result = agentcore_runtime.launch(local=False, local_build=False)After launch the console shows the runtime as “Ready”. The runtime exposes HTTP endpoints /invocations and /ping.
Invoking the stock‑analysis agent
import boto3, json
agentcore_client = boto3.client('bedrock-agentcore', region_name='us-west-2')
response = agentcore_client.invoke_agent_runtime(
agentRuntimeArn=launch_result.agent_arn,
qualifier="DEFAULT",
payload=json.dumps({"prompt": "Analyze SIM_STOCK for investment purposes"})
)The response is a byte stream that must be decoded, parsed as JSON, and split into three sections (data collection, analysis, PDF report). A helper parses the response:
stock_analysis = parse_bedrock_agentcore_stock_response(response)Cleanup
To avoid ongoing charges, delete the SageMaker resources and Bedrock runtime:
sessdelete_inference_component(inference_component_name)
sessdelete_endpoint(endpoint_name)
sessdelete_endpoint_config(endpoint_name)
sessdelete_model(model_name)
runtime_delete_response = agentcore_control_client.delete_agent_runtime(agentRuntimeId=launch_result.agent_id)
# Delete the ECR repository used for the container
ecr_client.delete_repository(repositoryName=launch_result.ecr_uri.split('/')[-1], force=True)Reference repositories
Docker files and build scripts: https://github.com/aws-samples/sagemaker-genai-hosting-examples/tree/main/OpenAI/gpt-oss/deploy/docker
Jupyter notebook for local testing: https://github.com/aws-samples/sagemaker-genai-hosting-examples/blob/main/OpenAI/gpt-oss/deploy/openai_gpt_oss.ipynb
Agent source code: https://github.com/aws-samples/sagemaker-genai-hosting-examples/tree/main/OpenAI/gpt-oss/agents
Key outcome
The end‑to‑end workflow demonstrates that a 20 B open‑source LLM can be quantized and served on a single G6e GPU with vLLM, orchestrated as a multi‑agent stock‑analysis pipeline using LangGraph, and scaled serverlessly via Amazon Bedrock AgentCore. This provides a cost‑effective path for enterprises to run powerful open‑source models and automate complex analysis tasks.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Amazon Cloud Developers
Official technical community of Amazon Cloud. Shares practical AI/ML, big data, database, modern app development, IoT content, offers comprehensive learning resources, hosts regular developer events, and continuously empowers developers.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
