Skip to content

Commit 58ec639

Browse files
author
Containerized Agent
committed
refactor: use Agent SOPs from strands-agents-sops for prompts
BREAKING CHANGE: Prompts now use the code-assist SOP from strands-agents-sops ## Changes - Add strands-agents-sops>=1.0.0 as a dependency - Refactor prompts.py to use the SOP wrapper pattern: code_assist_with_input(dynamic_documentation) - Simplify Jinja2 templates to only format dynamic content (documentation), removing full instruction sets - Templates now focus on user requirements and fetched docs - SOP provides the structured workflow (Explore, Plan, Code, Commit) ## Architecture New pattern: Agent SOP (instructions) + Dynamic Content (documentation) - Agent SOP (code-assist): Provides TDD methodology, design-first workflow, RFC 2119 constraints, and best practices - Dynamic Content: Up-to-date Strands documentation fetched from strandsagents.com, formatted via Jinja2 templates ## Template Changes All templates now contain only: 1. Task description and user requirements 2. Strands framework documentation (fetched dynamically) 3. Implementation notes specific to the domain The workflow instructions are provided by the code-assist SOP. ## Test Updates - Updated tests to verify SOP wrapper structure - Fixed fetch_doc tests for SSRF protection (from upstream) - Added tests for SOP integration Refs: strands-agents/agent-sop
1 parent a2040af commit 58ec639

File tree

9 files changed

+326
-1395
lines changed

9 files changed

+326
-1395
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dependencies = [
2626
"mcp>=1.1.3",
2727
"pydantic>=2.0.0",
2828
"jinja2>=3.1.0",
29+
"strands-agents-sops>=1.0.0",
2930
]
3031

3132
[project.scripts]

src/strands_mcp_server/prompts.py

Lines changed: 74 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
1-
"""Prompt generation system for Strands development."""
1+
"""Prompt generation system for Strands development.
2+
3+
This module combines Agent SOPs with dynamically fetched Strands documentation
4+
to create comprehensive prompts for various development tasks.
5+
6+
Architecture:
7+
- Agent SOPs (from strands-agents-sops): Provide structured workflows,
8+
constraints, and best practices for development tasks
9+
- Dynamic Content (from strandsagents.com): Up-to-date documentation
10+
specific to each development area
11+
- Jinja2 Templates: Format the dynamic documentation content
12+
13+
Pattern: sop_with_input(dynamic_documentation)
14+
"""
215

316
import re
417
from pathlib import Path
518

619
import jinja2
20+
from strands_agents_sops import code_assist_with_input
721

822
from .utils import cache
923

10-
# Initialize Jinja2 environment
24+
# Initialize Jinja2 environment for formatting dynamic content
1125
template_dir = Path(__file__).parent / "prompts"
1226
jinja_env = jinja2.Environment(
1327
loader=jinja2.FileSystemLoader(template_dir), trim_blocks=True, lstrip_blocks=True, autoescape=False
@@ -51,13 +65,23 @@ def fetch_content(url: str) -> str:
5165

5266

5367
# ============================================================================
54-
# SIMPLE PROMPT GENERATORS - Direct documentation inclusion
68+
# PROMPT GENERATORS - SOP + Dynamic Documentation Pattern
5569
# ============================================================================
5670

5771

5872
def generate_tool_prompt(request: str, tool_use_examples: str = "", preferred_libraries: str = "") -> str:
59-
"""Generate a design-first tool development prompt with dynamic documentation."""
73+
"""Generate a design-first tool development prompt with dynamic documentation.
74+
75+
Combines the code-assist SOP workflow with Strands-specific tool documentation.
6076
77+
Args:
78+
request: Description of the tool functionality needed
79+
tool_use_examples: Examples of how the tool will be used (optional)
80+
preferred_libraries: Specific libraries or APIs to use (optional)
81+
82+
Returns:
83+
Generated prompt combining SOP instructions with Strands documentation
84+
"""
6185
cache.ensure_ready()
6286

6387
# Fetch documentation
@@ -69,21 +93,32 @@ def generate_tool_prompt(request: str, tool_use_examples: str = "", preferred_li
6993
)
7094
python_tools_content = fetch_content(python_tools_url)
7195

72-
# Load and render template
96+
# Load and render template for dynamic content
7397
template = jinja_env.get_template("tool_development.jinja2")
74-
75-
return template.render(
98+
dynamic_content = template.render(
7699
request=request,
77100
tool_use_examples=tool_use_examples,
78101
preferred_libraries=preferred_libraries,
79102
llms_txt_content=llms_txt_content,
80103
python_tools_content=python_tools_content,
81104
)
82105

106+
# Combine SOP with dynamic content
107+
return code_assist_with_input(dynamic_content)
108+
83109

84110
def generate_session_prompt(request: str, include_examples: bool = True) -> str:
85-
"""Generate a session management implementation prompt with documentation."""
111+
"""Generate a session management implementation prompt with documentation.
112+
113+
Combines the code-assist SOP workflow with Strands session management documentation.
114+
115+
Args:
116+
request: Description of the session management needs
117+
include_examples: Include usage examples (default: True)
86118
119+
Returns:
120+
Generated prompt combining SOP instructions with session documentation
121+
"""
87122
cache.ensure_ready()
88123

89124
# Fetch documentation
@@ -98,17 +133,19 @@ def generate_session_prompt(request: str, include_examples: bool = True) -> str:
98133
session_api_url = "https://strandsagents.com/latest/documentation/docs/api-reference/session/index.md"
99134
session_api_content = fetch_content(session_api_url)
100135

101-
# Load and render template
136+
# Load and render template for dynamic content
102137
template = jinja_env.get_template("session_management.jinja2")
103-
104-
return template.render(
138+
dynamic_content = template.render(
105139
request=request,
106140
include_examples=include_examples,
107141
llms_txt_content=llms_txt_content,
108142
session_management_content=session_management_content,
109143
session_api_content=session_api_content,
110144
)
111145

146+
# Combine SOP with dynamic content
147+
return code_assist_with_input(dynamic_content)
148+
112149

113150
def generate_agent_prompt(
114151
use_case: str,
@@ -121,6 +158,8 @@ def generate_agent_prompt(
121158
) -> str:
122159
"""Generate a design-first agent development prompt with dynamic documentation.
123160
161+
Combines the code-assist SOP workflow with Strands agent documentation.
162+
124163
Args:
125164
use_case: Description of what the agent should do
126165
examples: Optional examples of expected agent behavior
@@ -131,9 +170,8 @@ def generate_agent_prompt(
131170
verbosity: Level of detail (minimal, normal, detailed)
132171
133172
Returns:
134-
Generated prompt text for agent development
173+
Generated prompt combining SOP instructions with agent documentation
135174
"""
136-
137175
cache.ensure_ready()
138176

139177
# Fetch documentation
@@ -148,16 +186,14 @@ def generate_agent_prompt(
148186
agent_api_url = "https://strandsagents.com/latest/documentation/docs/api-reference/agent/index.md"
149187
agent_api_content = fetch_content(agent_api_url)
150188

151-
# Fetch community tools documentation - just pass the raw content
152189
community_tools_url = (
153190
"https://strandsagents.com/latest/documentation/docs/user-guide/concepts/tools/community-tools-package/index.md"
154191
)
155192
community_tools_content = fetch_content(community_tools_url)
156193

157-
# Load and render template
194+
# Load and render template for dynamic content
158195
template = jinja_env.get_template("agent_development.jinja2")
159-
160-
return template.render(
196+
dynamic_content = template.render(
161197
use_case=use_case,
162198
examples=examples,
163199
agent_guidelines=agent_guidelines,
@@ -166,11 +202,14 @@ def generate_agent_prompt(
166202
llms_txt_content=llms_txt_content,
167203
agent_loop_content=agent_loop_content,
168204
agent_api_content=agent_api_content,
169-
community_tools_content=community_tools_content, # Pass raw content
205+
community_tools_content=community_tools_content,
170206
include_examples=include_examples,
171207
verbosity=verbosity,
172208
)
173209

210+
# Combine SOP with dynamic content
211+
return code_assist_with_input(dynamic_content)
212+
174213

175214
def generate_model_prompt(
176215
use_case: str,
@@ -182,6 +221,8 @@ def generate_model_prompt(
182221
) -> str:
183222
"""Generate a design-first custom model provider development prompt.
184223
224+
Combines the code-assist SOP workflow with Strands model provider documentation.
225+
185226
Args:
186227
use_case: Description of the model provider's purpose
187228
model_details: Details about the models to support
@@ -191,9 +232,8 @@ def generate_model_prompt(
191232
include_examples: Whether to include code examples
192233
193234
Returns:
194-
Generated prompt text for model provider development
235+
Generated prompt combining SOP instructions with model provider documentation
195236
"""
196-
197237
cache.ensure_ready()
198238

199239
# Fetch documentation
@@ -203,10 +243,9 @@ def generate_model_prompt(
203243
models_api_url = "https://strandsagents.com/latest/documentation/docs/api-reference/models/index.md"
204244
models_api_content = fetch_content(models_api_url)
205245

206-
# Load and render template
246+
# Load and render template for dynamic content
207247
template = jinja_env.get_template("model_development.jinja2")
208-
209-
return template.render(
248+
dynamic_content = template.render(
210249
use_case=use_case,
211250
model_details=model_details,
212251
api_documentation=api_documentation,
@@ -217,6 +256,9 @@ def generate_model_prompt(
217256
include_examples=include_examples,
218257
)
219258

259+
# Combine SOP with dynamic content
260+
return code_assist_with_input(dynamic_content)
261+
220262

221263
def generate_multiagent_prompt(
222264
use_case: str,
@@ -228,6 +270,8 @@ def generate_multiagent_prompt(
228270
) -> str:
229271
"""Generate a multi-agent systems development prompt.
230272
273+
Combines the code-assist SOP workflow with Strands multi-agent documentation.
274+
231275
Args:
232276
use_case: Description of what the multi-agent system should accomplish
233277
pattern: Preferred pattern (graph/swarm/hybrid) or let the prompt guide selection
@@ -237,14 +281,10 @@ def generate_multiagent_prompt(
237281
include_examples: Whether to include code examples
238282
239283
Returns:
240-
A comprehensive prompt for multi-agent system development
284+
Generated prompt combining SOP instructions with multi-agent documentation
241285
"""
242-
243286
cache.ensure_ready()
244287

245-
# Load the template
246-
template = jinja_env.get_template("multiagent_development.jinja2")
247-
248288
# Fetch multi-agent documentation
249289
graph_url = "https://strandsagents.com/latest/documentation/docs/user-guide/concepts/multi-agent/graph/index.md"
250290
swarm_url = "https://strandsagents.com/latest/documentation/docs/user-guide/concepts/multi-agent/swarm/index.md"
@@ -254,8 +294,9 @@ def generate_multiagent_prompt(
254294
swarm_content = fetch_content(swarm_url)
255295
multiagent_api_content = fetch_content(multiagent_api_url)
256296

257-
# Simply pass all parameters to template - no string building in Python!
258-
return template.render(
297+
# Load the template for dynamic content
298+
template = jinja_env.get_template("multiagent_development.jinja2")
299+
dynamic_content = template.render(
259300
use_case=use_case,
260301
pattern=pattern,
261302
agent_roles=agent_roles,
@@ -266,3 +307,6 @@ def generate_multiagent_prompt(
266307
multiagent_api_content=multiagent_api_content,
267308
include_examples=include_examples,
268309
)
310+
311+
# Combine SOP with dynamic content
312+
return code_assist_with_input(dynamic_content)

0 commit comments

Comments
 (0)