generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 63
feat: add end to end integration test #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JackYPCOnline
merged 19 commits into
strands-agents:main
from
JackYPCOnline:integration-test
Aug 15, 2025
Merged
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
74e8464
feat: add end to end integration test
JackYPCOnline 6910700
Merge branch 'strands-agents:main' into integration-test
JackYPCOnline 42656ba
feat: add integration tests for the package
JackYPCOnline f24b8fe
feat: remove old test
JackYPCOnline b4d3cfc
refactor: refactor the test code with patch api instead of monkeypatch
JackYPCOnline 991e70d
feat: add STRANDS_ANTHROPIC_BETA environment variable (#34)
awsarron a4fed3c
Windows: Remove cron tool + document missing tools when on windows (#33)
zastrowm 88c305d
udpate agent system_prompt reference (#35)
Unshure 2eff5dc
chore: explicitly set load_tools_from_directory on Agent initilizatio…
dbschmigelski 68e2c50
Update builder with updates from 0.3.0 SDK (#39)
zastrowm 577e9f0
chore: Remove Preview (#40)
yonib05 ac7d801
deps: bump strangs-agents to v1.0.0 (#41)
jer96 e30a6e9
build(pyproject): update development status classifier (#42)
awsarron 0702a52
Use strands logo that looks good in dark & light mode (#44)
zastrowm 09a19a9
fix: refactor some tests
JackYPCOnline 0dd5163
Merge branch 'strands-agents:main' into integration-test
JackYPCOnline b0c5f7e
fix: refactor tests code
JackYPCOnline c149f5b
fix: make tests more accurate
JackYPCOnline 629e722
fix: remove test_custom_load_from_file to avoiding text based respons…
JackYPCOnline File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import re | ||
|
||
import pytest | ||
from strands.agent import Agent | ||
from strands.models import BedrockModel | ||
|
||
|
||
@pytest.fixture | ||
def bedrock_model(): | ||
return BedrockModel( | ||
model_id="us.anthropic.claude-3-7-sonnet-20250219-v1:0", | ||
streaming=True, | ||
) | ||
|
||
|
||
def extract_code_from_response(response): | ||
"""Extract Python code blocks from the agent's response.""" | ||
code_pattern = r"```python\s*(.*?)\s*```" | ||
matches = re.findall(code_pattern, str(response), re.DOTALL) | ||
if matches: | ||
return matches[0].strip() | ||
return None | ||
|
||
|
||
def test_agent_creates_calculator_tool(tmp_path, monkeypatch, bedrock_model): | ||
"""End-to-end test: Ask agent to create a tool, validate it, then delete it.""" | ||
tools_dir = tmp_path / "tools" | ||
JackYPCOnline marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
tools_dir.mkdir(parents=True) | ||
monkeypatch.setenv("STRANDS_TOOLS_DIR", str(tools_dir)) | ||
JackYPCOnline marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
tool_path = tools_dir / "calculator_tool.py" | ||
|
||
try: | ||
creator_agent = Agent(model=bedrock_model) | ||
JackYPCOnline marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
prompt = """ | ||
Create a Python tool named calculator_tool that can perform basic arithmetic operations. | ||
The tool should: | ||
1. Take two numbers and an operator ('+', '-', '*', '/') | ||
2. Return the result of the operation | ||
3. Include proper docstrings and error handling | ||
4. Be compatible with the Strands SDK tool system | ||
Provide only the Python code with no additional explanation. | ||
""" | ||
creation_response = creator_agent(prompt) | ||
|
||
tool_code = extract_code_from_response(creation_response) | ||
assert tool_code is not None, "Failed to extract tool code from agent response" | ||
|
||
with open(tool_path, "w") as f: | ||
f.write(tool_code) | ||
assert tool_path.exists(), f"Tool file was not created at {tool_path}" | ||
|
||
agent = Agent(model=bedrock_model, tools=None, load_tools_from_directory=True) | ||
|
||
test_cases = [ | ||
("What is 1 + 2?", "3"), | ||
("Calculate 2 - 1", "1"), | ||
("What is 1 multiplied by 5?", "5"), | ||
("Divide 20 by 4", "5"), | ||
] | ||
|
||
for question, expected in test_cases: | ||
response = agent(question) | ||
response_str = str(response).lower() | ||
assert expected.lower() in response_str, f"Failed to find '{expected}' in response to '{question}'" | ||
|
||
finally: | ||
if tool_path.exists(): | ||
tool_path.unlink() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.