-
Notifications
You must be signed in to change notification settings - Fork 89
Feature/sdk improvements #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
base: main
Are you sure you want to change the base?
Feature/sdk improvements #30
Conversation
Core Changes: - Add worker_config.py for better worker configuration management - Update agent.py, config.py, and exceptions.py with improved documentation - Add comprehensive docstrings to custom_types.py - Enhance worker.py with better error handling Testing: - Add unit tests for custom types Infrastructure: - Update .gitignore for better Python project management - Fix FunctionResultStatus enum string conversion - Improve error handling and logging across components
1. Added tenacity import to test_api_client.py for network error handling 2. Updated create_workers function to use correct API format 3. Enhanced validate_response function with better error checks 4. Improved test coverage from 92% to 94%
1. Core SDK Updates: - Enhanced agent implementation - Updated custom types and worker configurations - Improved worker implementation 2. Test Coverage: - Added comprehensive test suite for all components - Including agent, API, config, and worker tests - Added weather worker example tests 3. Documentation and Examples: - Added API documentation - Added getting started guide - Added SDK overview - Added example weather agent and worker - Added requirements.txt
MantisClone
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! It really helped me to understand the GAME python SDK!
This was only a partial review, covering the documentation but not the SDK code changes.
| ### State Management | ||
|
|
||
| Workers maintain state between function calls: | ||
|
|
||
| ```python | ||
| def get_state(function_result, current_state): | ||
| """Update worker state after function execution.""" | ||
| if current_state is None: | ||
| return {'requests': 0} | ||
|
|
||
| current_state['requests'] += 1 | ||
| return current_state | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section about state management is unclear to me because the code snippet doesn't actually use get_state(). It also seems too contrived to be useful in a real worker.
- Fix the code snippet to actually show usage of
get_state(). - Consider adding more detail to the code snippet so that it's less contrived.
- Consider adding an explanation why someone would store the state between function calls.
- Consider increasing the complexity of the weather example, below, to include state management.
| def test_weather_worker(): | ||
| """Test weather worker functionality.""" | ||
| # Create worker | ||
| config = create_weather_worker_config(test_api_key) | ||
| worker = Worker(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider putting the test setup into a fixture.
| def test_weather_worker(): | |
| """Test weather worker functionality.""" | |
| # Create worker | |
| config = create_weather_worker_config(test_api_key) | |
| worker = Worker(config) | |
| @pytest.fixture | |
| def worker(): | |
| # Create worker | |
| config = create_weather_worker_config(test_api_key) | |
| return Worker(config) | |
| def test_weather_worker(worker): | |
| """Test weather worker functionality.""" | |
| ... |
| ### State Management | ||
|
|
||
| The `get_state_fn` defines how the worker maintains state between function calls: | ||
|
|
||
| ```python | ||
| def get_state(function_result, current_state): | ||
| """Manage worker state. | ||
|
|
||
| Args: | ||
| function_result: Result of last function call | ||
| current_state: Current state dictionary | ||
|
|
||
| Returns: | ||
| Updated state dictionary | ||
| """ | ||
| if current_state is None: | ||
| return {'count': 0} | ||
|
|
||
| current_state['count'] += 1 | ||
| return current_state | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider making the get_state_fn() use the function_result argument so the example is less contrived.
| ```python | ||
| from game_sdk.game.agent import Agent | ||
| from game_sdk.game.worker_config import WorkerConfig | ||
|
|
||
| # Create and configure the agent | ||
| agent = create_weather_agent() | ||
|
|
||
| # Run tests | ||
| test_weather_agent(agent) | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This snippet neglects to show how to create an Agent and add a Worker. Consider adding more detail.
| ### State Management | ||
|
|
||
| The worker maintains state between function calls: | ||
|
|
||
| ```python | ||
| def get_state(function_result, current_state): | ||
| if current_state is None: | ||
| return {'requests': 0, 'successes': 0, 'failures': 0} | ||
|
|
||
| if function_result and function_result.get('status') == 'success': | ||
| current_state['successes'] += 1 | ||
| elif function_result: | ||
| current_state['failures'] += 1 | ||
|
|
||
| current_state['requests'] += 1 | ||
| return current_state | ||
| ``` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This state management example is better because it uses the function_result 👍
| 'message': f"Current weather in {city}: {weather_data['condition']}, " | ||
| f"{weather_data['temp']}°F, {weather_data['humidity']} humidity", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix inconsistency. Weather data uses Celcius but the output message uses Fahrenheit.
| agent_description="Reports weather and provides recommendations", | ||
| agent_goal="Help users prepare for weather conditions", | ||
| get_agent_state_fn=get_state, | ||
| workers=[worker_config] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh nice. I didn't realize you can set the workers list at initialization instead of adding them later.
| # Test cities | ||
| test_cases = ["New York", "Miami", "Boston"] | ||
|
|
||
| for city in test_cases: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using @pytest.mark.parameterize to specify test cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, please disregard my previous comments about using pytest. Maybe it's better to not assume any given test framework.
| 'message': f"Current weather in {city}: {weather_data['condition']}, " | ||
| f"{weather_data['temp']}°F, {weather_data['humidity']} humidity", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same consistency issue as the previous file - choose either Celcius or Fahrenheit.
| 'data': None | ||
| } | ||
|
|
||
| def get_worker_state(function_result: Optional[Dict], current_state: Optional[Dict]) -> Dict[str, Any]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be named get_and_update_worker_state() to reflect that it doesn't just get the state, it also updates it.
Overview
This PR introduces comprehensive improvements to the GAME SDK, focusing on enhanced testing, documentation, and core component reliability.
Key Changes
1. Core SDK Enhancements
2. Test Suite Improvements
3. Documentation and Examples
4. Dependencies
Testing
Documentation
Added comprehensive documentation to help developers:
Breaking Changes
None. All changes are backward compatible.
Next Steps
Code Coverage Testing
Updates
_get_actionmethod in the Agent class to properly unpack the response dictionary when creating an ActionResponse object.Updates:
The code coverage has also improved from 92% to 94%, indicating better test coverage of our codebase. The remaining untested code is primarily in the agent module (86% coverage), which we can address in future updates if needed.