Skip to content

Commit 08fce07

Browse files
committed
Complete ConfigLoader tutorial system with cache-free implementation
Comprehensive ConfigLoader tutorial implementation covering the entire ecosystem: Tutorial Structure: - 01-tool-loading.ipynb - Tool configuration and loading fundamentals - 02-agent-loading.ipynb - Agent configuration with models, tools, structured output - 03-agents-as-tools.ipynb - Agent-as-Tool patterns for nested agent workflows - 04-swarm-loading.ipynb - Multi-agent swarm coordination and configuration - 05-graph-loading.ipynb - Graph-based agent workflows with nodes, edges, conditions - 06-structured-output-config.ipynb - Advanced structured output configuration - 07-swarms-as-tools.ipynb - Swarm-as-Tool patterns for complex workflows - 08-graphs-as-tools.ipynb - Graph-as-Tool patterns for reusable graph components Configuration Files: - tools.strands.yml - Tool configuration examples with proper top-level keys - weather-agent.strands.yml - Complete agent configuration with structured output - agents-as-tools.strands.yml - Agent-as-Tool configuration patterns - swarm.strands.yml - Multi-agent swarm configuration - graph-simple.strands.yml - Basic graph configuration with sequential flow - graph-parallel.strands.yml - Parallel graph execution patterns - graph-conditional.strands.yml - Conditional graph routing with complex conditions - swarms-as-tools.strands.yml - Swarm-as-Tool configuration - graphs-as-tools.strands.yml - Graph-as-Tool configuration Supporting Code: - weather_tool.py - Custom tool implementation for examples - workflow/conditions.py - Custom condition implementations for graph tutorials - workflow/__init__.py - Package initialization - README.md - Comprehensive tutorial overview and navigation Key Features Demonstrated: - Cache-free ConfigLoader architecture (simplified API without caching) - Top-level key requirements enforced (agent:, graph:, swarm:, tools:) - Schema validation integration with real-time IDE support - Advanced patterns: nested configurations, parameter substitution - Complex workflows: conditional routing, parallel execution, multi-agent coordination - Structured output configuration with Pydantic models - Error handling and troubleshooting patterns - Production-ready configuration examples Tutorial Progression: 1. Fundamentals: Tool and agent loading basics 2. Intermediate: Agent-as-Tool and swarm coordination 3. Advanced: Graph workflows and conditional routing 4. Expert: Structured output and complex nested patterns 5. Composition: Multi-agent tools (Swarms-as-Tools, Graphs-as-Tools) Production Quality: - 100% working examples tested with current ConfigLoader implementation - Comprehensive error handling and troubleshooting guidance - Real-world use cases and practical patterns - Progressive complexity from beginner to expert level - Complete ecosystem coverage for all ConfigLoader capabilities This tutorial system provides hands-on learning for the complete ConfigLoader ecosystem with cache-free architecture, enabling developers to master configuration-driven agent development.
1 parent 9451645 commit 08fce07

22 files changed

+2963
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.txt
2+
*.md
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "8e394456",
6+
"metadata": {},
7+
"source": [
8+
"# Loading Tools from Configuration Files\n",
9+
"\n",
10+
"This notebook demonstrates how to use the **ToolConfigLoader** to dynamically load and instantiate tools from YAML configuration files. This approach enables:\n",
11+
"\n",
12+
"- **Declarative Tool Management**: Define tools in configuration files rather than hardcoding them\n",
13+
"- **Dynamic Tool Loading**: Load tools at runtime based on configuration\n",
14+
"- **Flexible Tool Composition**: Mix custom tools with pre-built tools from strands-tools\n",
15+
"\n",
16+
"## What You'll Learn\n",
17+
"\n",
18+
"1. How to define tools in YAML configuration files\n",
19+
"2. Using ToolConfigLoader to load custom and pre-built tools\n",
20+
"3. Executing loaded tools with proper parameters\n",
21+
"4. Best practices for tool configuration management\n",
22+
"\n",
23+
"## Prerequisites\n",
24+
"\n",
25+
"- Python 3.10 or later\n",
26+
"- strands-agents and strands-agents-tools packages\n",
27+
"- Basic understanding of YAML configuration files\n",
28+
"\n",
29+
"Let's explore tool loading from configuration!"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"id": "5f7b62fd",
36+
"metadata": {},
37+
"outputs": [],
38+
"source": [
39+
"# Install Strands using pip\n",
40+
"!pip install strands-agents strands-agents-tools PyYAML"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"id": "6763a5b8",
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"import yaml\n",
51+
"import sys\n",
52+
"\n",
53+
"with open('./configs/tools.strands.yml', 'r') as file:\n",
54+
" config = yaml.safe_load(file)\n",
55+
"print(config)\n"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": null,
61+
"id": "51dba503",
62+
"metadata": {},
63+
"outputs": [],
64+
"source": [
65+
"from strands.experimental.config_loader.tools.tool_config_loader import ToolConfigLoader\n",
66+
"\n",
67+
"tool_loader = ToolConfigLoader()\n",
68+
"weather = tool_loader.load_tool(tool=config[\"tools\"][0])\n",
69+
"\n",
70+
"print(weather)"
71+
]
72+
},
73+
{
74+
"cell_type": "code",
75+
"execution_count": null,
76+
"id": "e19068ac",
77+
"metadata": {},
78+
"outputs": [],
79+
"source": [
80+
"response = weather()\n",
81+
"print(response)"
82+
]
83+
},
84+
{
85+
"cell_type": "code",
86+
"execution_count": null,
87+
"id": "f5cb951a",
88+
"metadata": {},
89+
"outputs": [],
90+
"source": [
91+
"# from strands_tools import file_write\n",
92+
"tool_loader = ToolConfigLoader()\n",
93+
"file_write = tool_loader.load_tool(tool=config[\"tools\"][1])\n",
94+
"\n",
95+
"print(file_write)"
96+
]
97+
},
98+
{
99+
"cell_type": "markdown",
100+
"id": "demo_explanation",
101+
"metadata": {},
102+
"source": [
103+
"## Demonstrating the file_write Tool\n",
104+
"\n",
105+
"Now let's use the `file_write` tool to create a simple text file. This demonstrates how to:\n",
106+
"\n",
107+
"1. Create a proper `ToolUse` request with the required parameters\n",
108+
"2. Execute the tool asynchronously using the `stream` method\n",
109+
"3. Handle the tool's response and verify the operation\n",
110+
"\n",
111+
"The `file_write` tool requires two parameters:\n",
112+
"- `path`: The file path where content should be written\n",
113+
"- `content`: The text content to write to the file"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": null,
119+
"id": "b131235e",
120+
"metadata": {},
121+
"outputs": [],
122+
"source": [
123+
"import os\n",
124+
"\n",
125+
"# Set environment variable to bypass interactive prompts\n",
126+
"os.environ['BYPASS_TOOL_CONSENT'] = 'true'\n",
127+
"\n",
128+
"# Create a ToolUse request for the file_write tool\n",
129+
"tool_use = {\n",
130+
" 'toolUseId': 'demo-file-write',\n",
131+
" 'name': 'file_write',\n",
132+
" 'input': {\n",
133+
" 'path': 'hello-strands.txt',\n",
134+
" 'content': 'Hello Strands!'\n",
135+
" }\n",
136+
"}\n",
137+
"\n",
138+
"[result async for result in file_write.stream(tool_use, {})]"
139+
]
140+
}
141+
],
142+
"metadata": {
143+
"kernelspec": {
144+
"display_name": "dev",
145+
"language": "python",
146+
"name": "python3"
147+
},
148+
"language_info": {
149+
"codemirror_mode": {
150+
"name": "ipython",
151+
"version": 3
152+
},
153+
"file_extension": ".py",
154+
"mimetype": "text/x-python",
155+
"name": "python",
156+
"nbconvert_exporter": "python",
157+
"pygments_lexer": "ipython3",
158+
"version": "3.12.9"
159+
}
160+
},
161+
"nbformat": 4,
162+
"nbformat_minor": 5
163+
}
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "8e394456",
6+
"metadata": {},
7+
"source": [
8+
"# Loading Agents from Configuration Files\n",
9+
"\n",
10+
"This notebook demonstrates how to create and configure Strands Agents using **YAML configuration files** and the **AgentConfigLoader**. This declarative approach provides several advantages:\n",
11+
"\n",
12+
"- **Configuration-Driven Development**: Define agent behavior, tools, and models in external config files\n",
13+
"- **Environment Flexibility**: Easily switch between different configurations for development, testing, and production\n",
14+
"- **Maintainability**: Separate agent logic from configuration, making updates easier\n",
15+
"- **Reusability**: Share and version control agent configurations independently\n",
16+
"\n",
17+
"## What You'll Learn\n",
18+
"\n",
19+
"1. How to define agent configurations in YAML files\n",
20+
"2. Loading agents using the AgentConfigLoader from configuration files or dictionaries\n",
21+
"3. Configuring models, system prompts, and tools declaratively\n",
22+
"4. Best practices for agent configuration management\n",
23+
"\n",
24+
"## Prerequisites\n",
25+
"\n",
26+
"- Python 3.10 or later\n",
27+
"- AWS account configured with appropriate permissions for Bedrock\n",
28+
"- strands-agents package installed\n",
29+
"- Basic understanding of YAML syntax\n",
30+
"\n",
31+
"Let's build agents from configuration!"
32+
]
33+
},
34+
{
35+
"cell_type": "code",
36+
"execution_count": null,
37+
"id": "5f7b62fd",
38+
"metadata": {},
39+
"outputs": [],
40+
"source": [
41+
"# Install Strands using pip\n",
42+
"!pip install strands-agents strands-agents-tools python-dotenv PyYAML"
43+
]
44+
},
45+
{
46+
"cell_type": "code",
47+
"execution_count": null,
48+
"id": "fda69d85",
49+
"metadata": {},
50+
"outputs": [],
51+
"source": [
52+
"from dotenv import load_dotenv\n",
53+
"load_dotenv()"
54+
]
55+
},
56+
{
57+
"cell_type": "markdown",
58+
"id": "79a45632",
59+
"metadata": {
60+
"vscode": {
61+
"languageId": "plaintext"
62+
}
63+
},
64+
"source": [
65+
"\n",
66+
"## Creating an Agent from Configuration\n",
67+
"\n",
68+
"Let's examine how to define and load a weather agent using YAML configuration and the AgentConfigLoader.\n",
69+
"\n",
70+
"### 1. Weather Agent Configuration:\n",
71+
"\n",
72+
"The configuration file defines:\n",
73+
"- **Model**: Specifies which LLM to use (Claude 3.7 Sonnet via Amazon Bedrock)\n",
74+
"- **System Prompt**: Sets the agent's behavior and capabilities\n",
75+
"- **Tools**: Lists the tools available to the agent (weather_tool.weather)\n",
76+
"\n",
77+
"This creates a specialized weather assistant that can:\n",
78+
"- Answer weather-related queries using the weather tool\n",
79+
"- Perform simple calculations as specified in the system prompt\n",
80+
"- Maintain consistent behavior across different environments\n",
81+
"\n",
82+
"<div style=\"text-align:center\">\n",
83+
" <img src=\"images/simple_agent.png\" width=\"75%\" />\n",
84+
"</div>"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"id": "5f35b45a",
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"import yaml\n",
95+
"\n",
96+
"with open('./configs/weather-agent.strands.yml', 'r') as file:\n",
97+
" config = yaml.safe_load(file)\n",
98+
"print(config)"
99+
]
100+
},
101+
{
102+
"cell_type": "code",
103+
"execution_count": null,
104+
"id": "0d7592da",
105+
"metadata": {},
106+
"outputs": [],
107+
"source": [
108+
"from pathlib import Path\n",
109+
"from strands.experimental.config_loader.agent import AgentConfigLoader\n",
110+
"\n",
111+
"# Create the config loader\n",
112+
"loader = AgentConfigLoader()\n",
113+
"\n",
114+
"# Load agent from dictionary config\n",
115+
"weather_agent = loader.load_agent(config)\n",
116+
"\n",
117+
"print(weather_agent)"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"id": "b61d3792",
124+
"metadata": {},
125+
"outputs": [],
126+
"source": [
127+
"response = weather_agent(\"What is the weather today?\")\n",
128+
"print(response)"
129+
]
130+
}
131+
],
132+
"metadata": {
133+
"kernelspec": {
134+
"display_name": "dev",
135+
"language": "python",
136+
"name": "python3"
137+
},
138+
"language_info": {
139+
"codemirror_mode": {
140+
"name": "ipython",
141+
"version": 3
142+
},
143+
"file_extension": ".py",
144+
"mimetype": "text/x-python",
145+
"name": "python",
146+
"nbconvert_exporter": "python",
147+
"pygments_lexer": "ipython3",
148+
"version": "3.12.9"
149+
}
150+
},
151+
"nbformat": 4,
152+
"nbformat_minor": 5
153+
}

0 commit comments

Comments
 (0)