-
Notifications
You must be signed in to change notification settings - Fork 0
Adding tests for tutorials #150
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
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4bebbd2
the tutorial workflow
RoxyFarhad 162da54
revert name
RoxyFarhad 7ca8b5c
adding workflow to start the agentex image
RoxyFarhad bfc0a34
adding tutorials and tests
RoxyFarhad 43f5613
Merge branch 'main' into adding-workflow
RoxyFarhad 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,5 @@ name: Test AgentEx Tutorials | |
|
|
||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| workflow_call: | ||
|
|
||
|
|
||
| workflow_call: | ||
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
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 |
|---|---|---|
|
|
@@ -14,4 +14,6 @@ dist | |
| codegen.log | ||
| Brewfile.lock.json | ||
|
|
||
| .DS_Store | ||
| .DS_Store | ||
|
|
||
| examples/**/uv.lock | ||
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
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
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
128 changes: 128 additions & 0 deletions
128
examples/tutorials/00_sync/000_hello_acp/tests/test_agent.py
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,128 @@ | ||
| """ | ||
| Sample tests for AgentEx ACP agent. | ||
|
|
||
| This test suite demonstrates how to test the main AgentEx API functions: | ||
| - Non-streaming message sending | ||
| - Streaming message sending | ||
| - Task creation via RPC | ||
|
|
||
| To run these tests: | ||
| 1. Make sure the agent is running (via docker-compose or `agentex agents run`) | ||
| 2. Set the AGENTEX_API_BASE_URL environment variable if not using default | ||
| 3. Run: pytest test_agent.py -v | ||
|
|
||
| Configuration: | ||
| - AGENTEX_API_BASE_URL: Base URL for the AgentEx server (default: http://localhost:5003) | ||
| - AGENT_NAME: Name of the agent to test (default: hello-acp) | ||
| """ | ||
|
|
||
| import os | ||
| from agentex.types import TextContentParam, TextDelta, TextContent | ||
| from agentex.types.agent_rpc_params import ParamsSendMessageRequest | ||
| from agentex.types.task_message_update import StreamTaskMessageDelta, StreamTaskMessageFull | ||
| import pytest | ||
| from agentex import Agentex | ||
|
|
||
|
|
||
| # Configuration from environment variables | ||
| AGENTEX_API_BASE_URL = os.environ.get("AGENTEX_API_BASE_URL", "http://localhost:5003") | ||
| AGENT_NAME = os.environ.get("AGENT_NAME", "s000-hello-acp") | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| """Create an AgentEx client instance for testing.""" | ||
| client = Agentex(base_url=AGENTEX_API_BASE_URL) | ||
| yield client | ||
| # Clean up: close the client connection | ||
| client.close() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def agent_name(): | ||
| """Return the agent name for testing.""" | ||
| return AGENT_NAME | ||
|
|
||
|
|
||
| class TestNonStreamingMessages: | ||
| """Test non-streaming message sending.""" | ||
|
|
||
| def test_send_simple_message(self, client: Agentex, agent_name: str): | ||
| """Test sending a simple message and receiving a response.""" | ||
|
|
||
| message_content = "Hello, Agent! How are you?" | ||
| response = client.agents.send_message( | ||
| agent_name=agent_name, | ||
| params=ParamsSendMessageRequest( | ||
| content=TextContentParam( | ||
| author="user", | ||
| content=message_content, | ||
| type="text", | ||
| ) | ||
| ), | ||
| ) | ||
| result = response.result | ||
| assert result is not None | ||
| assert len(result) == 1 | ||
| message = result[0] | ||
| assert isinstance(message.content, TextContent) | ||
| assert ( | ||
| message.content.content | ||
| == f"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: {message_content}" | ||
| ) | ||
|
|
||
|
|
||
| class TestStreamingMessages: | ||
| """Test streaming message sending.""" | ||
|
|
||
| def test_stream_simple_message(self, client: Agentex, agent_name: str): | ||
| """Test streaming a simple message and aggregating deltas.""" | ||
|
|
||
| message_content = "Hello, Agent! Can you stream your response?" | ||
| aggregated_content = "" | ||
| full_content = "" | ||
| received_chunks = False | ||
|
|
||
| for chunk in client.agents.send_message_stream( | ||
| agent_name=agent_name, | ||
| params=ParamsSendMessageRequest( | ||
| content=TextContentParam( | ||
| author="user", | ||
| content=message_content, | ||
| type="text", | ||
| ) | ||
| ), | ||
| ): | ||
| received_chunks = True | ||
| task_message_update = chunk.result | ||
| # Collect text deltas as they arrive or check full messages | ||
| if isinstance(task_message_update, StreamTaskMessageDelta) and task_message_update.delta is not None: | ||
| delta = task_message_update.delta | ||
| if isinstance(delta, TextDelta) and delta.text_delta is not None: | ||
| aggregated_content += delta.text_delta | ||
|
|
||
| elif isinstance(task_message_update, StreamTaskMessageFull): | ||
| content = task_message_update.content | ||
| if isinstance(content, TextContent): | ||
| full_content = content.content | ||
|
|
||
| if not full_content and not aggregated_content: | ||
| raise AssertionError("No content was received in the streaming response.") | ||
| if not received_chunks: | ||
| raise AssertionError("No streaming chunks were received, when at least 1 was expected.") | ||
|
|
||
| if full_content: | ||
| assert ( | ||
| full_content | ||
| == f"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: {message_content}" | ||
| ) | ||
|
|
||
| if aggregated_content: | ||
| assert ( | ||
| aggregated_content | ||
| == f"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: {message_content}" | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main([__file__, "-v"]) | ||
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
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
Oops, something went wrong.
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.