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

Refactor microagent MarketFunctions to take market_id as input #66

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

evangriffiths
Copy link
Contributor

@evangriffiths evangriffiths commented Apr 10, 2024

Changes to microagent to prevent the agent from having to pass the 'market question' around to various Functions

  • Changed GetMarkets to return market questions and IDs
  • Added GetMarketProbability for getting the market p_yes from the market id
  • BuyTokens Functions take in market_id instead of market question
  • Required a bump to PMAT 0.11.0
  • Also added an integration test where the agent runs GetMarketProbability

Copy link
Contributor

coderabbitai bot commented Apr 10, 2024

Walkthrough

The updates primarily focus on enhancing type safety, renaming functions for clarity, and adjusting market-related functionalities across various modules. Changes include modifying type hints, updating function names and logic, and refining market handling and testing within the prediction market agent tooling.

Changes

Files Change Summary
.../known_outcome_agent/benchmark.py, .../known_outcome_agent/deploy.py Updated type hints and modified parameters for better clarity and functionality.
.../microchain_agent/functions.py, .../microchain_agent/utils.py Renamed functions, updated type hints, and introduced new functionalities for market handling.
pyproject.toml Upgraded dependency version to incorporate new features or fixes.
tests/agents/microchain/test_agent.py, tests/agents/microchain/test_functions.py Added new test cases and modified existing ones to align with the updated functionalities and ensure robustness.

Possibly related issues


Recent Review Details

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 795cb62 and e79fa25.
Files selected for processing (1)
  • tests/agents/microchain/test_functions.py (4 hunks)
Files skipped from review as they are similar to previous changes (1)
  • tests/agents/microchain/test_functions.py

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration 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.

@@ -39,7 +39,7 @@ def to_market(self) -> AgentMarket:
),
volume=None,
created_time=None,
close_time=None,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required change after bumping PMAT version

@@ -33,7 +34,7 @@ class DeployableKnownOutcomeAgent(DeployableAgent):
def load(self) -> None:
self.markets_with_known_outcomes: dict[str, Result] = {}

def pick_markets(self, markets: list[AgentMarket]) -> list[AgentMarket]:
def pick_markets(self, markets: t.Sequence[AgentMarket]) -> list[AgentMarket]:
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required change after bumping PMAT version

@@ -63,11 +62,18 @@ def __init__(self, market_type: MarketType) -> None:
self.market_type = market_type
super().__init__()

@property
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added helper function to MarketFunction class, as it's needed in a few places

]


class PredictPropabilityForQuestion(MarketFunction):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed otherwise it could easily be mistaken for GetMarketProbability

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a bit confused - shouldn't this method be named something like PlaceBet or BuyTokensForOutcome? It's not really predicting anything, like the description says it allows the agent to purchase tokens.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gabrielfior It's okay, just that Github hides the lines:

Screenshot by Dropbox Capture



def get_binary_markets(market_type: MarketType) -> list[AgentMarket]:
# Get the 5 markets that are closing soonest
cls = market_type.market_class
markets: list[AgentMarket] = cls.get_binary_markets(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Required change after bumping PMAT version

engine.register(Stop())
engine.register(GetMarkets(market_type=market_type))
engine.register(GetMarketProbability(market_type=market_type))
engine.register(Jsonify())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to give the agent this function, otherwise it would just stop after calling GetMarketProbability, so the final output was:

>> GetMarketProbability(market_id="0x04f93bad589f989313bf3386f9dfa0f9354c9c25")
['0.43316548923547493']
Error: empty reply, aborting

def test_get_probability(market_type: MarketType) -> None:
market_id = "0x0020d13c89140b47e10db54cbd53852b90bc1391"
get_market_probability = GetMarketProbability(market_type=market_type)
get_market_probability(market_id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the assertion missing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes good point. I noticed that the way we calculate p_yes for closed omen markets is broken atm, so I made this task gnosis/prediction-market-agent-tooling#181

I've added an assertion here that will fail once that task is resolved, but I think that's fine.

Comment on lines +84 to +87
m_json = json.loads(agent.history[-3]["content"])
m = MarketIDAndProbability.model_validate(m_json)
market: AgentMarket = market_type.market_class.get_binary_market(m.market_id)
assert market.p_yes == m.probability
Copy link
Contributor

Choose a reason for hiding this comment

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

Like this test a lot!
Just wondering - self.history makes sense (I don't see another way to fetch microchain output - one could use on_iteration_end and assign a variable, but don't think it would be much better).

This is a lot hackier though when compared with crewai (task.output.raw_content, task.output.json_output, etc) and autogen. So probably something to keep in mind when comparing those frameworks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's a good point. I thought the same

@kongzii kongzii merged commit 284fe76 into main Apr 11, 2024
6 checks passed
@kongzii kongzii deleted the evan/market-functions-id-input branch April 11, 2024 09:13
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.

3 participants