Skip to content
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

NFT Game mods #680

Merged
merged 2 commits into from
Feb 10, 2025
Merged

NFT Game mods #680

merged 2 commits into from
Feb 10, 2025

Conversation

kongzii
Copy link
Contributor

@kongzii kongzii commented Feb 7, 2025

No description provided.

Copy link
Contributor

coderabbitai bot commented Feb 7, 2025

Walkthrough

This pull request introduces several modifications across various modules. It clarifies the description of the UpdateMySystemPrompt class, enhances pagination functionality in the app_nft_treasury_game.py file, and introduces new xDai-based constants for managing balances. Additionally, the logic in the before_iteration_callback method is updated to reset agent history, and logging functionality is added to track treasury balances. Other changes include updates to function signatures and logic for balance resets and game status checks, improving code clarity and consistency without altering core behaviors.

Changes

File(s) Change Summary
prediction_market_agent/.../agent_functions.py Expanded the description in UpdateMySystemPrompt to clarify that the system prompt is completely replaced.
prediction_market_agent/.../nft_treasury_game/app_nft_treasury_game.py Refactored pagination logic: added functions for navigating (first, previous, next, last) and updated display formatting.
prediction_market_agent/.../nft_treasury_game/constants_nft_treasury_game.py Introduced new constants (STARTING_AGENT_BALANCE, STARTING_TREASURY_BALANCE, TREASURY_THRESHOLD_BALANCE_TO_END_GAME) with an added xDai import.
prediction_market_agent/.../nft_treasury_game/deploy_nft_treasury_game.py Modified before_iteration_callback to reset agent history and updated the base prompt content for NFT treasury game.
prediction_market_agent/.../nft_treasury_game/messages_functions.py Added logging to GameRoundEnd, introduced the new GetUnseenMessagesInformation class, and updated the message functions list.
prediction_market_agent/.../nft_treasury_game/scripts/reset_balance_anvil.py Updated reset_balances: changed parameter types to xDai, removed the get_balances import, and altered is_treasury_empty logic to check game status.
prediction_market_agent/.../nft_treasury_game/tools_nft_treasury_game.py Revised get_nft_game_status to accept an optional Web3 instance and changed the treasury balance check logic using a threshold constant.
prediction_market_agent/run_reset_game.py Simplified the main function signature by removing balance parameters, now using constant values for initial balances.
prediction_market_agent/tools/anvil/anvil_requests.py Changed the set_balance function signature to accept xDai instead of int, streamlining the balance conversion process.

Sequence Diagram(s)

sequenceDiagram
  participant U as User
  participant UI as Pagination UI
  participant PF as Pagination Functions
  participant DD as Display Driver

  U->>UI: Click navigation button (first/prev/next/last)
  UI->>PF: Invoke corresponding function (go_to_first_page, etc.)
  PF->>DD: Calculate and update current page value with total pages
  DD-->>UI: Return updated pagination display
  UI-->>U: Show refreshed page view
Loading
sequenceDiagram
  participant A as NFT Game Agent
  participant D as DeployableAgentNFTGameAbstract
  participant H as History Manager
  participant L as Logging System

  A->>D: Trigger before_iteration_callback
  D->>H: Reset history with system prompt and new reasoning entry
  D->>L: Log treasury balance during game round end
  L-->>D: Confirm logging
  D-->>A: Continue with updated game state
Loading

Possibly related PRs

Suggested reviewers

  • gabrielfior

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c09cfad and f92620c.

📒 Files selected for processing (2)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/scripts/reset_balance_anvil.py (2 hunks)
  • prediction_market_agent/run_reset_game.py (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-build-image
  • GitHub Check: pytest-docker
  • GitHub Check: pytest
  • GitHub Check: mypy
🔇 Additional comments (6)
prediction_market_agent/run_reset_game.py (4)

12-15: Consider making the constants configurable.

Based on the previous discussion, consider making STARTING_AGENT_BALANCE and STARTING_TREASURY_BALANCE configurable through environment variables or command-line arguments. This would provide more flexibility for different environments and testing scenarios.


20-20: LGTM! Better function naming.

The renamed import from is_treasury_empty to is_game_in_finished_state better reflects the actual purpose of the function.


29-30: LGTM! Simplified function signature.

The function signature has been simplified to only accept rpc_url, with balance values now managed through constants.


39-44: LGTM! Consistent use of constants.

The balance parameters have been replaced with constants from constants_nft_treasury_game.py, maintaining consistency across the codebase.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/scripts/reset_balance_anvil.py (2)

14-17: LGTM! Well-organized imports.

The new imports for NFTGameStatus and get_nft_game_status support the shift from balance checks to game status checks.


24-26: LGTM! Improved type safety.

The function parameters now use the xDai type instead of int, providing better type safety and clarity.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/constants_nft_treasury_game.py (1)

13-14: Consider documenting the game economics.

The threshold calculation implies that the game ends when 10% of the treasury balance is withdrawn. Consider adding a comment explaining why this specific threshold was chosen and its implications for game economics.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/tools_nft_treasury_game.py (1)

20-21: Consider adding logging for game status changes.

When the game status changes to finished, it would be helpful to log the current treasury balance for debugging purposes.

 if treasury_balance.total < TREASURY_THRESHOLD_BALANCE_TO_END_GAME:
+    logger.info(f"Game finished. Treasury balance {treasury_balance.total} below threshold {TREASURY_THRESHOLD_BALANCE_TO_END_GAME}")
     return NFTGameStatus.finished
prediction_market_agent/run_reset_game.py (1)

34-35: Consider making sleep duration configurable.

The 10-minute sleep duration is hardcoded. Consider making it configurable through environment variables or command-line arguments for flexibility in different environments.

+REFLECTION_DURATION_MINUTES = 10
+
 @APP.command()
-def main(rpc_url: str) -> None:
+def main(
+    rpc_url: str,
+    reflection_duration_minutes: Annotated[int, typer.Option(default=REFLECTION_DURATION_MINUTES)] = REFLECTION_DURATION_MINUTES
+) -> None:
     if not is_treasury_empty(rpc_url=rpc_url):
         logger.info(f"Treasury not empty, exiting.")
         return

     # Give time to agents to reflect on the last game, in case this script gets executed right after it ended
-    time.sleep(10 * 60)
+    time.sleep(reflection_duration_minutes * 60)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (1)

195-195: Remove unnecessary f-string prefix.

The string doesn't contain any placeholders, so the f prefix can be removed.

-    st.markdown(f"### Agent's actions")
+    st.markdown("### Agent's actions")
🧰 Tools
🪛 Ruff (0.8.2)

195-195: f-string without any placeholders

Remove extraneous f prefix

(F541)

prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (1)

146-154: Consider preserving key learnings when resetting agent history.

While resetting the history improves memory management, consider preserving key insights from the previous game to help the agent make better decisions in the new game.

 self.agent.history = [
     system_prompt,  # Keep the system prompt in the new history.
     # Hack-in the reasoning in a way that agent thinks it's from himself -- otherwise he could ignore it.
     {
         "role": "assistant",
         "content": f"""{Reasoning.__name__}(reasoning='The game has started again. I will participate in the game again, using a new and better strategy than before.""",
     },
+    # Add a summary of key learnings from the previous game
+    {
+        "role": "assistant",
+        "content": f"""{Reasoning.__name__}(reasoning='Key learnings from previous game: [Insert top 3 insights here]')""",
+    },
     {"role": "user", "content": "The reasoning has been recorded"},
 ]
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aeff41e and c09cfad.

📒 Files selected for processing (9)
  • prediction_market_agent/agents/microchain_agent/agent_functions.py (1 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (2 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/constants_nft_treasury_game.py (2 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (2 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/messages_functions.py (2 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/scripts/reset_balance_anvil.py (2 hunks)
  • prediction_market_agent/agents/microchain_agent/nft_treasury_game/tools_nft_treasury_game.py (2 hunks)
  • prediction_market_agent/run_reset_game.py (3 hunks)
  • prediction_market_agent/tools/anvil/anvil_requests.py (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py

195-195: f-string without any placeholders

Remove extraneous f prefix

(F541)

⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: test-build-image
  • GitHub Check: pytest-docker
  • GitHub Check: pytest
  • GitHub Check: mypy
🔇 Additional comments (15)
prediction_market_agent/agents/microchain_agent/nft_treasury_game/constants_nft_treasury_game.py (1)

1-1: LGTM! Well-defined balance constants.

The use of xDai type for balance constants ensures type safety and clear representation of currency values.

Also applies to: 11-12

prediction_market_agent/agents/microchain_agent/nft_treasury_game/tools_nft_treasury_game.py (1)

17-18: LGTM! Improved function signature.

The optional Web3 parameter enhances flexibility and testability.

prediction_market_agent/tools/anvil/anvil_requests.py (1)

12-14: LGTM! Improved type safety.

The use of xDai type for balance parameter ensures consistent balance handling across the codebase.

prediction_market_agent/run_reset_game.py (1)

29-29: LGTM! Improved maintainability.

Using centralized constants for balance values improves consistency and maintainability.

Also applies to: 37-45

prediction_market_agent/agents/microchain_agent/agent_functions.py (1)

33-33: LGTM! Improved description clarity.

The updated description better communicates the function's behavior by explicitly stating that it replaces the entire system prompt.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/scripts/reset_balance_anvil.py (3)

14-17: LGTM! Added imports for game status management.

The new imports support the transition from balance-based to status-based game state management.


24-26: LGTM! Improved type safety.

The function signature now uses the more specific xDai type instead of int for balance parameters, reducing the risk of type-related errors.


46-50: LGTM! Refactored treasury status check.

The function now determines treasury status based on game state rather than balance thresholds, which is a more robust approach.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/messages_functions.py (3)

6-8: LGTM! Added imports for enhanced logging.

The new imports support treasury balance logging and improved observability.


142-144: LGTM! Added treasury balance logging.

The added logging statement provides valuable insights into the treasury state when an agent stops playing.


152-152: LGTM! Added message information function.

The addition of GetUnseenMessagesInformation to MESSAGES_FUNCTIONS enhances message handling capabilities.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/app_nft_treasury_game.py (3)

202-222: LGTM! Improved pagination logic.

The code now properly calculates the maximum page number and handles edge cases for button states.


205-218: LGTM! Added dedicated navigation functions.

The pagination logic is now encapsulated in dedicated functions, improving code organization and maintainability.


224-237: LGTM! Enhanced pagination UI.

The UI now includes first/last page buttons and displays the current page number with total pages, improving user experience.

prediction_market_agent/agents/microchain_agent/nft_treasury_game/deploy_nft_treasury_game.py (1)

346-352: LGTM! Clear improvements to game rules documentation.

The added clarifications about payment verification and real-time communication constraints help prevent confusion and align with the game's design.

Comment on lines +39 to +44
initial_xdai_balance_per_agent=STARTING_AGENT_BALANCE,
)
reset_balances(
rpc_url=rpc_url,
new_balance_agents_xdai=xdai_balance_per_agent,
new_balance_treasury_xdai=new_balance_treasury_xdai,
new_balance_agents_xdai=STARTING_AGENT_BALANCE,
new_balance_treasury_xdai=STARTING_TREASURY_BALANCE,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO these constants should be configurable, and they aren't if defined inside PMAT.
I'm fine with any configurable option, e.g.
-> Define as ENV in the container (via Terraform)
-> Define as parameters in the script (like previously)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on why? What advantage do you see in having this (and generally stuff like this) configurable through env?

In both cases mentioned, we still need to open up PR, approve, and merge.

I wouldn't care, but the motivation for me for the change was because of this. Some way to detect that something from the treasury was withdrawn.

If you have some way how to write it in another way, let's do that in follow up PR.

@kongzii kongzii merged commit f54b281 into main Feb 10, 2025
11 checks passed
@kongzii kongzii deleted the peter/nft-fixes branch February 10, 2025 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants