strands-bedrock-agents-cookbook

mcp
Security Audit
Warn
Health Warn
  • License — License: MIT
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 7 GitHub stars
Code Pass
  • Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Pass
  • Permissions — No dangerous permissions requested

No AI report is available for this listing yet.

SUMMARY

Strands Agents SDK 1.x cookbook: 10 AI agent examples for Amazon Bedrock & local Ollama/Apple Silicon MLX, FinOps/OTel/Langfuse tracing, and zero-dep MCP

README.md

Strands Bedrock Agents Cookbook

한국어 문서 (README-kr.md) | Portable Agent Skill (SKILL.md)

Strands

A practical Strands Agents SDK 1.x cookbook with 10 runnable AI agent use cases that work across Amazon Bedrock, local Ollama, Apple Silicon MLX, and an offline deterministic mock preset (zero AWS credentials required) — plus Bedrock vs. local FinOps cost/latency reporting, OpenTelemetry / Langfuse trace export, and a zero-dependency Python stdlib stdio MCP server.


Zero-Account Local Quickstart (uv + Python 3.12)

No AWS account or API keys are required to verify or run the cookbook locally.

1. Offline Deterministic Verification (0 Credentials, 0 Downloads)

# Sync pinned Python 3.12 environment (requires uv)
uv sync --python 3.12 --extra dev --extra otel
cp .env.example .env

# Run all 10 Strands Agent use cases offline through the real Strands Agent + @tool loop
uv run strands-cookbook --preset mock

# Inspect local Ollama / MLX runtime availability on loopback
uv run strands-cookbook --probe-local

# Run any 1-Basic-agent example offline
uv run python 1-Basic-agent/0_main.py --preset mock
uv run python 1-Basic-agent/4_main_python_repl_calculator.py --preset mock

2. Local Ollama (Strict Loopback 127.0.0.1:11434)

uv sync --python 3.12 --extra ollama
ollama pull qwen3:8b
STRANDS_MODEL_PRESET=ollama-qwen3 OLLAMA_HOST=http://127.0.0.1:11434 \
  uv run strands-cookbook --use-case uc05_llm_cost_calculator

3. Local Apple Silicon MLX (Strict Loopback 127.0.0.1:8080/v1)

uv sync --python 3.12 --extra mlx
# Start an OpenAI-compatible MLX server on loopback:
python -m mlx_lm.server --model mlx-community/Qwen2.5-7B-Instruct-4bit --port 8080

STRANDS_MODEL_PRESET=mlx-qwen2.5 MLX_BASE_URL=http://127.0.0.1:8080/v1 \
  uv run strands-cookbook --use-case uc05_llm_cost_calculator

Security guard: OLLAMA_HOST and MLX_BASE_URL enforce strict loopback validation (localhost, 127.0.0.0/8, [::1] over http/https without embedded credentials). Cloud metadata IPs (169.254.169.254), 0.0.0.0, LAN IPs, and external domains are rejected.


Bedrock vs. Local FinOps Cost & Latency Comparison

Generated with uv run strands-cookbook-finops --input-tokens 2000 --output-tokens 500 --format markdown (llm_cost_utils.py).

Published Pricing Assumptions (published_list_price_assumption) — Sample 2,000 Input / 500 Output Tokens

Model ID Provider Input ($/1M) Output ($/1M) Est. API Cost / Run Projected 1,000 Runs Measured Live Latency
us.anthropic.claude-sonnet-4-20250514-v1:0 Bedrock $3.000 $15.000 $0.0135 $13.50 Not measured (run with AWS creds)
us.anthropic.claude-3-5-haiku-20241022-v1:0 Bedrock $0.800 $4.000 $0.0036 $3.60 Not measured (run with AWS creds)
us.amazon.nova-pro-v1:0 Bedrock $0.800 $3.200 $0.0032 $3.20 Not measured (run with AWS creds)
us.amazon.nova-lite-v1:0 Bedrock $0.060 $0.240 $0.00024 $0.24 Not measured (run with AWS creds)
us.amazon.nova-micro-v1:0 Bedrock $0.035 $0.140 $0.00014 $0.14 Not measured (run with AWS creds)
ollama/qwen3:8b Local Ollama $0.000 $0.000 $0.00 $0.00 Not measured (run locally on Ollama)
mlx/mlx-community/Qwen2.5-7B-Instruct-4bit Local MLX $0.000 $0.000 $0.00 $0.00 Not measured (run locally on Apple Silicon)

Honesty & methodology note:

  • Pricing assumptions vs. billing: Amazon Bedrock USD/1M rates are published on-demand list-price assumptions (published_list_price_assumption) for estimation only — never live AWS billing invoices — and vary by region, tier, and prompt caching. Local Ollama and MLX API token costs are $0.00 (API billing only; excludes user-owned hardware amortization and electricity).
  • Measured timings: CI runs execution_mode="mock_offline" (measuring deterministic Strands harness/tool-loop overhead only, e.g., ~1.6–7.4 ms per in-process use case and ~206 ms for stdio MCP subprocess roundtrips — not live LLM inference). Run uv run strands-cookbook --preset <ollama|mlx|bedrock> on your hardware to capture live latencies.

OpenTelemetry & Langfuse Trace Export

cookbook/observability.py integrates with Strands Agents 1.x StrandsTelemetry for offline in-memory span checks, console export, generic OTLP collectors, and Langfuse OTLP ingestion (with automatic secret/header redaction):

# Capture real Strands OpenTelemetry spans completely offline (in-memory exporter)
uv run python examples/telemetry_export_example.py --mode memory

# Validate Langfuse OTLP endpoint & redacted Basic Auth configuration without network calls
uv run python examples/telemetry_export_example.py --mode langfuse-dryrun
from cookbook.observability import configure_strands_telemetry

# Modes: "memory" | "console" | "otlp" | "langfuse"
telemetry, config, exporter = configure_strands_telemetry(
    mode="langfuse",  # reads LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY, LANGFUSE_HOST
    service_name="strands-bedrock-agents-cookbook",
)

Zero-Dependency MCP Server & Portable SKILL.md (3-Line Setup)

mcp_server/cookbook_mcp_server.py uses only the Python standard library (Python 3.10–3.15, zero pip install needed) and exposes 5 cookbook tools (list_cookbook_recipes, get_model_preset_config, estimate_finops_cost, generate_telemetry_config, check_cookbook_env_security) plus 2 read-only cookbook:// resources.

Claude Code (.mcp.json or CLI)

{
  "mcpServers": {
    "strands-cookbook": {
      "type": "stdio",
      "command": "python3",
      "args": ["mcp_server/cookbook_mcp_server.py"]
    }
  }
}

Codex CLI (~/.codex/config.toml)

[mcp_servers.strands-cookbook]
command = "python3"
args = ["mcp_server/cookbook_mcp_server.py"]
cwd = "/path/to/strands-bedrock-agents-cookbook"

Copilot CLI (~/.copilot/mcp-config.json)

{
  "mcpServers": {
    "strands-cookbook": {
      "type": "stdio",
      "command": "python3",
      "args": ["/path/to/strands-bedrock-agents-cookbook/mcp_server/cookbook_mcp_server.py"]
    }
  }
}

For cross-agent guidance, copy or symlink the root SKILL.md into your agent's skills directory (~/.claude/skills/, ~/.codex/skills/, or ~/.copilot/skills/).


10 Practical Cookbook Use Cases

All 10 use cases from Strands.ipynb are runnable via uv run strands-cookbook --use-case <id> --preset <preset> and verified offline in CI (mock_offline):

# Use Case ID Description Offline CI Local (ollama/mlx)
01 uc01_web_scraping Extract Hacker News titles/links and export CSV Verified Supported
02 uc02_stock_analysis 20-day moving average, daily returns, annualized volatility Verified Supported
03 uc03_insurance_claims Severe weather claim inspection & DynamoDB-shaped store Verified Supported
04 uc04_kb_internet_search Env-driven Bedrock KB (BEDROCK_KB_ID) + news synthesis Verified Supported
05 uc05_llm_cost_calculator Custom @tool FinOps token cost estimator (llm_cost_utils.py) Verified Supported
06 uc06_dataframe_manipulation Salary/10% bonus calculation, age filtering, bracket grouping Verified Supported
07 uc07_pyspark_etl CSV filter, Adult/Minor labeling, city aggregation (PySpark + stdlib fallback) Verified Supported
08 uc08_ml_churn_pipeline Synthetic churn preprocessing, 80/20 split, F1 evaluation Verified Supported
09 uc09_multi_agent_finance Multi-agent financial orchestrator routing 3 specialist sub-agents Verified Supported
10 uc10_mcp_integration Strands MCPClient calling live stdio cookbook_mcp_server.py tools Verified Supported

Model Presets & Extended Thinking

Switch providers with one line via cookbook.presets.create_model:

from strands import Agent
from cookbook.presets import create_model

# Offline mock, local Ollama, local Apple Silicon MLX, or Amazon Bedrock
model = create_model("ollama-qwen3")  # or "mock", "mlx-qwen2.5", "bedrock-claude-4"
agent = Agent(model=model)

# Amazon Bedrock Claude 4 Sonnet with Extended / Interleaved Thinking
reasoning_model = create_model(
    "bedrock-claude-4",
    extended_thinking=True,
    thinking_budget=8000,
)
# Or local reasoning presets without AWS:
# reasoning_model = create_model("ollama-deepseek-r1")
# reasoning_model = create_model("mlx-deepseek-r1")

Configuration & Security

  • Environment variables (.env.example): Copy .env.example to .env (gitignored). Root kb_id.txt has been removed and gitignored; configure Bedrock Knowledge Base IDs via BEDROCK_KB_ID or KNOWLEDGE_BASE_ID.
  • Fallback in advanced_rag_utils.py: load_variables() gracefully falls back to environment variables (BEDROCK_KB_ID, AWS_DEFAULT_REGION, AWS_ACCOUNT_ID) when variables.json is absent.
  • Safe tool consent: Scripts default to BYPASS_TOOL_CONSENT=false unless explicitly enabled.
  • Regression suite: tests/test_security_regression.py verifies kb_id.txt absence, secret-free tracked files, strict loopback SSRF rejection, and lightweight media rules.

Testing & Verification

# Run full test suite (presets, 10 use cases, FinOps, OTel/Langfuse, MCP E2E, security)
uv run --python 3.12 pytest

# Run linter
uv run --python 3.12 ruff check cookbook mcp_server llm_cost_utils.py examples 1-Basic-agent tests

# Verify pure-stdlib MCP server runs outside .venv with stock Python
python3 -I -c "import json, subprocess; p = subprocess.Popen(['python3', '-I', 'mcp_server/cookbook_mcp_server.py'], stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True); out, _ = p.communicate(json.dumps({'jsonrpc':'2.0','id':1,'method':'ping'}) + '\n'); print(out.strip()); assert p.returncode == 0"

File Structure

.
├── .env.example                       # Environment variable template (replaces kb_id.txt)
├── .python-version                    # Pinned Python 3.12 for uv
├── pyproject.toml                     # uv packaging, extras (tools/ollama/mlx/otel/dev), CLIs
├── SKILL.md                           # Portable cross-agent skill & 3-line MCP configs
├── cookbook/
│   ├── presets.py                     # mock / ollama / mlx / bedrock presets + loopback guard
│   ├── use_cases.py                   # Runnable implementations of all 10 use cases
│   ├── runner.py                      # `strands-cookbook` CLI runner & local probe
│   └── observability.py               # StrandsTelemetry OpenTelemetry & Langfuse helpers
├── mcp_server/
│   └── cookbook_mcp_server.py         # Zero-dependency Python stdlib stdio MCP server
├── examples/
│   └── telemetry_export_example.py    # Offline OTel / Langfuse + FinOps demo script
├── 1-Basic-agent/                     # 5 progressive basic agent scripts (--preset support)
├── Reasoning_Model_Claude/            # Claude 3.7/4.0 & local reasoning guide + notebook
├── tests/                             # Unit, 10-use-case, FinOps, MCP E2E & security tests
├── llm_cost_utils.py                  # FinOps cost/latency reporter & CloudWatch @tool
├── advanced_rag_utils.py              # Bedrock RAG utilities with env-var fallback
├── Strands.ipynb                      # 10-use-case interactive notebook (Strands 1.x)
├── research_agent_kb_internet.ipynb   # Research agent notebook (env-driven KB ID)
├── README.md                          # English documentation
└── README-kr.md                       # Korean documentation

Resources

License

This project is licensed under the MIT License — see LICENSE for details.

Reviews (0)

No results found