Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ This repository provides a comprehensive, hands-on comparison of modern AI agent
<img src="res/strands-amazon-sdk.svg" alt="Strands Agents SDK" width="120" style="vertical-align: middle;">
</picture>
</td>
<td><code>1.55.1</code></td>
<td><code>1.62.0</code></td>
<td>
<a href="https://strandsagents.com/docs/">
<picture>
Expand Down
1 change: 1 addition & 0 deletions strands-agents-sdk/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ AWS_DEFAULT_REGION=us-west-2
# --- OpenAI (alternative provider) ---
OPENAI_API_KEY=your-openai-api-key
OPENAI_MODEL_NAME=gpt-4o-mini
OPENAI_STRONG_MODEL_NAME=gpt-4.1

# --- Anthropic (alternative provider) ---
ANTHROPIC_API_KEY=your-anthropic-api-key
2 changes: 1 addition & 1 deletion strands-agents-sdk/00_hello_world.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
alternative provider configured via settings.

For more details, visit:
https://strandsagents.com/docs/user-guide/quickstart/python/
https://strandsagents.com/docs/user-guide/sdk/quickstart/python/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/01_custom_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
so the agent can decide when and how to invoke each tool.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/tools/custom-tools/
https://strandsagents.com/docs/user-guide/sdk/tools/custom-tools/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/02_structured_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
result through result.structured_output.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/structured-output/
https://strandsagents.com/docs/user-guide/sdk/agents/structured-output/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/03_system_prompt_and_conversation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
let you define the agent's personality, constraints, and response style.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/prompts/
https://strandsagents.com/docs/user-guide/sdk/agents/prompts/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/04_model_providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
more by passing a model object to the Agent constructor.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/model-providers/
https://strandsagents.com/docs/user-guide/sdk/model-providers/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/05_agents_as_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
description, and context behaviour (e.g. preserve_context=True).

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/multi-agent/agents-as-tools/
https://strandsagents.com/docs/user-guide/sdk/multi-agent/agents-as-tools/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/06_streaming_and_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use async iterators for fine-grained control over the event stream.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/streaming/
https://strandsagents.com/docs/user-guide/sdk/streaming/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/07_metrics_and_observability.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
slow runs, and understanding how the agent uses its tools.

For more details, visit:
https://strandsagents.com/docs/user-guide/observability-evaluation/observability/
https://strandsagents.com/docs/user-guide/sdk/observability-evaluation/observability/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/08_class_based_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
manage connections, or accumulate results over the course of a conversation.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/tools/custom-tools/#class-based-tools
https://strandsagents.com/docs/user-guide/sdk/tools/custom-tools/#class-based-tools
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/09_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
guardrails specifically, see the intervention API in 19_interventions.py.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/hooks/
https://strandsagents.com/docs/user-guide/sdk/agents/hooks/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/10_conversation_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
reference data in context no matter how long the conversation gets.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/conversation-management/
https://strandsagents.com/docs/user-guide/sdk/agents/conversation-management/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/11_multi_agent_swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
The swarm manages the handoff protocol, max iterations, and execution tracking.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/multi-agent/swarm/
https://strandsagents.com/docs/user-guide/sdk/multi-agent/swarm/
-------------------------------------------------------
"""

Expand Down
4 changes: 3 additions & 1 deletion strands-agents-sdk/12_multi_agent_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
multi-agent pipelines.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/multi-agent/graph/
https://strandsagents.com/docs/user-guide/sdk/multi-agent/graph/
-------------------------------------------------------
"""

Expand Down Expand Up @@ -74,6 +74,8 @@
builder.add_edge("executor", "reviewer")

builder.set_entry_point("planner")
# Bound the run; build() warns when a graph has no execution limit
builder.set_execution_timeout(300.0)

graph = builder.build()

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/13_multi_agent_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
automatically. This is ideal for complex multi-step processes.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/multi-agent/workflow/
https://strandsagents.com/docs/user-guide/sdk/multi-agent/workflow/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/14_a2a_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Install A2A support with: pip install 'strands-agents[a2a]'

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/multi-agent/agent-to-agent/
https://strandsagents.com/docs/user-guide/sdk/multi-agent/agent-to-agent/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/15_mcp_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
manager for explicit control.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/tools/mcp-tools/
https://strandsagents.com/docs/user-guide/sdk/tools/mcp-tools/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/16_skills_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
agent activates a skill through a tool call.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/plugins/skills/
https://strandsagents.com/docs/user-guide/sdk/plugins/skills/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/17_session_persistence.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
S3SessionManager (cloud) as built-in backends.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/session-management/
https://strandsagents.com/docs/user-guide/sdk/agents/session-management/
-------------------------------------------------------
"""

Expand Down
74 changes: 54 additions & 20 deletions strands-agents-sdk/18_context_compression.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os

from strands import Agent
from strands import Agent, tool
from strands.agent.conversation_manager import SummarizingConversationManager
from strands.agent.conversation_manager.conversation_manager import ProactiveCompressionConfig
from strands.experimental.context_manager import STRATEGY_PRESET_NAMES, Offload
from strands.handlers.callback_handler import null_callback_handler
from strands.models.openai import OpenAIModel

Expand All @@ -16,17 +17,19 @@
- Proactive context compression (new in v1.40.0)
- SummarizingConversationManager with ProactiveCompressionConfig
- Automatic conversation summarization to stay within token limits
- The context_manager="auto" / "agentic" shortcut (new in v1.43.0)
- Override precedence between context_manager and conversation_manager
- The context_manager="auto" / "agentic" built-in modes
- A custom strategy pipeline from named presets and raw Offload strategies

Proactive compression monitors token usage during conversation
and automatically compresses older messages when a threshold is
reached, without waiting for context window overflow errors.
context_manager="auto" is the one-word shortcut for the same setup,
composing a summarizing manager with a ContextOffloader plugin.
The context_manager parameter goes further: it registers a ContextManager
that runs an ordered pipeline of summarize / truncate / drop strategies
and replaces the conversation manager entirely (a co-provided
conversation_manager is ignored with a warning).

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/conversation-management/
https://strandsagents.com/docs/user-guide/sdk/context-management/
-------------------------------------------------------
"""

Expand Down Expand Up @@ -89,19 +92,18 @@
print(f" (Proactive compression keeps context manageable across long conversations)")
print()

# --- 5. The same setup in one word: context_manager="auto" ---
# --- 5. context_manager="auto": a strategy-driven ContextManager ---
print("=== context_manager Shortcut ===")

auto_agent = Agent(
model=openai_model,
context_manager="auto",
callback_handler=null_callback_handler,
)
print('context_manager="auto" composes, with benchmark-validated defaults:')
print(f" conversation_manager: {type(auto_agent.conversation_manager).__name__}")
print(f" summary_ratio: {auto_agent.conversation_manager.summary_ratio}")
print(f" preserve_recent_messages: {auto_agent.conversation_manager.preserve_recent_messages}")
print(f" ContextOffloader plugin tools: {auto_agent.tool_names}")
print('context_manager="auto" registers a plugin that owns all context reduction:')
print(f" context_manager: {type(auto_agent.context_manager).__name__}")
print(f" conversation_manager: {type(auto_agent.conversation_manager).__name__} (a no-op)")
print(f" tools: {auto_agent.tool_names}")
print()

# "agentic" hands the compression decisions to the model instead
Expand All @@ -114,14 +116,46 @@
print(f" tools: {agentic_agent.tool_names}")
print()

# --- 6. Override precedence: an explicit conversation_manager wins ---
override_agent = Agent(
# --- 6. A custom pipeline: named presets mixed with a raw Offload strategy ---
BUILD_LOG = "\n".join(
[f"step {i:03d} compiled module_{i:03d}.py in {10 + i % 7}ms" for i in range(1, 400)]
+ ["step 400 FAILED: test_checkout.py::test_refund timed out after 30s"]
)


@tool
def fetch_build_log(build_id: str) -> str:
"""Fetch the full CI log for a build."""
return BUILD_LOG


print("=== Custom Strategy Pipeline ===")
print(f"Named presets: {list(STRATEGY_PRESET_NAMES)}")

pipeline_agent = Agent(
model=openai_model,
context_manager="auto",
conversation_manager=conversation_manager, # the hand-built manager from step 1
tools=[fetch_build_log],
system_prompt="Answer in one short sentence.",
# Strategies run in order; each sees the output of the previous one
context_manager={
"strategies": [
"large_tool_offloading", # tool results over 2,500 tokens -> 1,000-token preview
"stale_tool_cleanup",
# A pinned config, unlike the preset "proactive_summarization" (whose values may change)
Offload.summarize("*").when(utilization=0.9, preserve_recent=2),
"overflow_protection",
],
},
callback_handler=null_callback_handler,
)
print('context_manager="auto" + an explicit conversation_manager:')
print(f" preserve_recent_messages: {override_agent.conversation_manager.preserve_recent_messages}"
" (yours wins over the auto default of 10)")
print(f" tools: {override_agent.tool_names} (the offloader is still added)")
result = pipeline_agent("Fetch the log for build b-1042. Which step failed?")

tool_result = next(
block["toolResult"] for message in pipeline_agent.messages
for block in message["content"] if "toolResult" in block
)
seen = tool_result["content"][0]["text"]
print(f" fetch_build_log returned {len(BUILD_LOG):,} chars; the model saw {len(seen):,}")
print(f" {seen.splitlines()[0]}")
print(f" original stashed for retrieve_context: {'[Stashed]' in seen}")
print(f"A: {str(result).strip()}")
2 changes: 1 addition & 1 deletion strands-agents-sdk/19_interventions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
blocking the call, feeding guidance back to the model, or rewriting arguments.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/interventions/
https://strandsagents.com/docs/user-guide/sdk/agents/interventions/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/20_human_in_the_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
instead, and passing an async callable lets you await your own approval service.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/interventions/human-in-the-loop/
https://strandsagents.com/docs/user-guide/sdk/agents/interventions/human-in-the-loop/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/21_agent_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
17_session_persistence.py, which replays the conversation history itself.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/memory/test-memory-store/
https://strandsagents.com/docs/user-guide/sdk/memory/test-memory-store/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/22_invocation_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
is left in a state you can invoke again.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/agent-loop/
https://strandsagents.com/docs/user-guide/sdk/agents/agent-loop/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/23_goal_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
agent's model, so no extra provider is needed.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/plugins/goal-loop/
https://strandsagents.com/docs/user-guide/sdk/plugins/goal-loop/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/24_cancellation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
signal so they stop promptly instead of running to completion.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/agent-loop/
https://strandsagents.com/docs/user-guide/sdk/agents/agent-loop/
-------------------------------------------------------
"""

Expand Down
2 changes: 1 addition & 1 deletion strands-agents-sdk/25_background_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
inline because later reasoning depends on it immediately.

For more details, visit:
https://strandsagents.com/docs/user-guide/concepts/agents/agent-loop/
https://strandsagents.com/docs/user-guide/sdk/agents/agent-loop/
-------------------------------------------------------
"""

Expand Down
Loading
Loading