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

Remove cap on bet amount for microchain agent #239

Merged
merged 9 commits into from
Jul 31, 2024

Conversation

evangriffiths
Copy link
Contributor

@evangriffiths evangriffiths commented Jun 11, 2024

Just removing the bet cap meant the agent would still sometimes place very large bets (i.e. its full wallet!). I've added a new function, GetKellyBet. It looks like this is enough to get the agent to bet less rashly, but also more optimally.

Screenshot 2024-07-31 at 12 46 25

Copy link
Contributor

coderabbitai bot commented Jun 11, 2024

Walkthrough

The recent modifications to the MicrochainAgent class involve the removal of the MAX_AMOUNT attribute and its associated logic, allowing for unrestricted betting amounts. Additionally, a new GetKellyBet class has been introduced for calculating optimal bet sizes using the Kelly Criterion, thereby enhancing the agent's strategic betting capabilities.

Changes

File Path Change Summary
prediction_market_agent/agents/microchain_agent/market_functions.py Added GetKellyBet class for Kelly Criterion calculations; removed restrictions on bet amounts in MicrochainAgent.
tests/agents/microchain/test_functions.py Introduced test_kelly_bet to validate GetKellyBet functionality, expanding the testing framework for betting logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MicrochainAgent
    participant GetKellyBet

    User->>MicrochainAgent: Call with amount
    MicrochainAgent-->>User: Processed amount (no max limit check)

    User->>GetKellyBet: Request optimal bet
    GetKellyBet-->>User: Returns calculated bet size
Loading

This diagram illustrates the simplified interaction between a user and the MicrochainAgent following the removal of the maximum amount check, alongside the new functionality provided by the GetKellyBet class for optimal bet size calculations.


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between d60572e and dcab06f.

Files selected for processing (1)
  • prediction_market_agent/agents/microchain_agent/functions.py (2 hunks)
Additional comments not posted (3)
prediction_market_agent/agents/microchain_agent/functions.py (3)

Line range hint 14-14: The removal of the MAX_AMOUNT attribute simplifies the MicrochainAgent class.


Line range hint 15-15: The updated description property correctly reflects the removal of the bet amount cap.


Line range hint 16-16: Ensure that the removal of the maximum amount check in the __call__ method does not introduce any unintended consequences.

Verification successful

The search for MAX_AMOUNT did not produce any results, indicating that there are no remaining references to MAX_AMOUNT in the codebase. This suggests that the removal of the maximum amount check in the __call__ method does not affect other parts of the system.

Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the removal of the maximum amount check does not affect other parts of the system.

# Test: Search for any remaining references to `MAX_AMOUNT`. Expect: No occurrences.
rg --type python $'MAX_AMOUNT'

Length of output: 60



Script:

#!/bin/bash
# Description: Verify that the removal of the maximum amount check does not affect other parts of the system.

# Test: Search for any remaining references to `MAX_AMOUNT`. Expect: No occurrences.
rg --type py $'MAX_AMOUNT'

Length of output: 25

@@ -160,9 +160,6 @@ def __init__(self, market_type: MarketType, outcome: str):
)
self.user_address = APIKeys().bet_from_address

# Prevent the agent from spending recklessly!
self.MAX_AMOUNT = 0.1 if market_type == MarketType.OMEN else 1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

YOLOOO

@evangriffiths
Copy link
Contributor Author

Results from testing the agent without the cap:

  • With the default trader-agent prompt, it still bets v large amounts (emptying the wallet in a few bets)
  • With the 'just-born' config I tested, it was more conservative in its bet sizes (maybe due to 'survival' being mentioned in the prompt:
Act as an autonomous agent with a goal to learn, survive and evolve. AI agents learn by using learning functions and then updating their prompt using the combination of first getting their prompt, then modifying it and then updating it. After each Learn function called, the agent should update its prompt to include the new knowledge. The new knowledge needs to be about what was actually learned, not about just describing it. Updating the prompt after a learning session is an absolute necessity to make sure that the agent is able to use the new knowledge in the future. Agents should keep a track record of what they have learned in the past, to not repeat the same learning session again and again. A good prompt is clear, concise, and informative. It should contain all necessary information for the agent to perform well. Instead of saying 'I know about X,' the prompt should provide actual knowledge about X, including what it is and how it works. Reasoning is the process of thinking about something in a logical way to form a conclusion or judgment. The Reasoning function should be used often to help guide actions. Survival is the state or fact of continuing to live or exist. For an AI agent to survive, it must be able to continue to operate and perform its functions. In order to operate, it must keep a positive balance in its account. Every action or function that the agent does costs some amount of money. By acting as a trader agent in prediction markets and using other available functions to operate on them, an AI agent can create a profit to keep its balance positive.

I'll try changing the default trader-agent prompt and see if this helps.

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

Outside diff range, codebase verification and nitpick comments (1)
prediction_market_agent/agents/microchain_agent/market_functions.py (1)

Line range hint 14-19:
Consider adding safeguards or warnings for large bet amounts.

The removal of the cap on bet amounts can lead to excessive betting. Consider adding safeguards or warnings for large bet amounts to prevent rapid depletion of the agent's wallet.

+        # Add a warning for large bet amounts
+        LARGE_BET_THRESHOLD = 10.0  # Example threshold, adjust as needed
+        if amount > LARGE_BET_THRESHOLD:
+            print(f"Warning: You are placing a large bet of {amount} {self.currency}.")
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dcab06f and 96f1f10.

Files selected for processing (1)
  • prediction_market_agent/agents/microchain_agent/market_functions.py (1 hunks)
Additional comments not posted (1)
prediction_market_agent/agents/microchain_agent/market_functions.py (1)

Line range hint 14-19:
Verify the removal of the cap on bet amount.

The MAX_AMOUNT attribute and associated logic have been removed, allowing for unrestricted bet amounts.

@evangriffiths
Copy link
Contributor Author

I'll try changing the default trader-agent prompt and see if this helps

Fixed by adding a new MarketFunction GetKellyBet instead.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 96f1f10 and 2deb904.

Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • pyproject.toml is excluded by !**/*.toml
Files selected for processing (1)
  • prediction_market_agent/agents/microchain_agent/market_functions.py (4 hunks)
Additional comments not posted (5)
prediction_market_agent/agents/microchain_agent/market_functions.py (5)

382-383: Class GetKellyBet added.

The new class GetKellyBet implements functionality for calculating the optimal bet size using the Kelly Criterion.


384-389: Description property is well-defined.

The description property provides a clear and concise explanation of the class's functionality.


392-393: Example arguments property is well-defined.

The example arguments property provides a clear example of the expected input arguments.


395-409: Verify the correctness of the __call__ method.

The __call__ method calculates the bet amount using the Kelly Criterion. Ensure that the logic is correct and that the method integrates well with the rest of the codebase.


Line range hint 411-424:
Ensure the removal of MAX_AMOUNT does not introduce issues.

The MAX_AMOUNT attribute and associated logic have been removed. Verify that this change does not introduce any issues and that the class functions correctly without it.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2deb904 and 795f0ec.

Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • pyproject.toml is excluded by !**/*.toml
Files selected for processing (2)
  • prediction_market_agent/agents/microchain_agent/market_functions.py (4 hunks)
  • tests/agents/microchain/test_functions.py (2 hunks)
Additional comments not posted (3)
tests/agents/microchain/test_functions.py (1)

195-198: LGTM!

The test_kelly_bet function correctly tests the GetKellyBet class by verifying that the bet size is zero when there is no edge.

prediction_market_agent/agents/microchain_agent/market_functions.py (2)

382-411: LGTM!

The GetKellyBet class correctly implements the Kelly Criterion to calculate the optimal bet size and direction. The properties for description and example arguments are well-defined.


426-426: LGTM!

The removal of the MAX_AMOUNT attribute and related logic from the MicrochainAgent class aligns with the PR objective of allowing unrestricted bet amounts. The description property has been updated accordingly.

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 795f0ec and 8a78471.

Files ignored due to path filters (2)
  • poetry.lock is excluded by !**/*.lock, !**/*.lock
  • pyproject.toml is excluded by !**/*.toml
Files selected for processing (1)
  • prediction_market_agent/agents/microchain_agent/market_functions.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • prediction_market_agent/agents/microchain_agent/market_functions.py

@evangriffiths evangriffiths merged commit 2dc6b73 into main Jul 31, 2024
7 checks passed
@evangriffiths evangriffiths deleted the evan/microchain-no-max-bet branch July 31, 2024 14:42
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.

None yet

3 participants