Add optional Adanos market sentiment tool - #1061
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughThis PR adds optional integration with Adanos Market Sentiment API to Lumibot strategies and agents. A new sentiment client library fetches US-equity sentiment from multiple sources (Reddit, X/FinTwit, news, Polymarket). Strategies access sentiment via ChangesAdanos Market Sentiment Integration
Sequence Diagram(s) sequenceDiagram
participant Strategy
participant BuiltinTool as adanos_market_sentiment
participant AdanosClient as AdanosMarketSentiment
participant AdanosAPI as Adanos API
Strategy->>BuiltinTool: call adanos_market_sentiment(mode, sources, days, end)
BuiltinTool->>AdanosClient: delegate to get_market_sentiment / get_stock_sentiment
AdanosClient->>AdanosAPI: GET /market or /stock with X-API-Key and params
AdanosAPI-->>AdanosClient: per-source JSON responses
AdanosClient-->>BuiltinTool: aggregated {results, errors, sources}
BuiltinTool-->>Strategy: {ok: ..., results, errors}
Estimated code review effort:
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Pylint (4.0.5)tests/test_adanos_sentiment.py************* Module pylintrc ... [truncated 4770 characters] ... "obj": "test_agent_manager_omits_unavailable_adanos_tool", lumibot/sentiment/adanos.py************* Module pylintrc ... [truncated 1241 characters] ... le": "lumibot.sentiment.adanos", Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (5)
tests/test_adanos_sentiment.py (4)
22-30: 💤 Low valueAdd docstring to test helper class.
The
_Responsemock class lacks a docstring. A brief docstring clarifies its role as an HTTP response stub.📝 Proposed docstring
class _Response: + """Mock HTTP response for stubbing requests.get in tests.""" def __init__(self, payload): self._payload = payload🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_adanos_sentiment.py` around lines 22 - 30, Add a concise docstring to the test helper class _Response describing that it is a lightweight HTTP response stub used in tests, what payload it stores, and that raise_for_status() is a no-op while json() returns the stored payload; update the class _Response (and optionally mention its methods __init__, raise_for_status, json in the docstring) to include this brief explanation so future readers understand its purpose.
44-53: ⚡ Quick winVerify all HTTP calls when multiple sources are requested.
The test passes
sources="reddit,news"(two sources) but only verifiescalls[0]. If the client makes one HTTP call per source (as suggested by the/reddit/path in the URL), the test should verify both calls or at least assert the total count to ensure no source is silently dropped.🔍 Proposed assertion to verify call count
assert result["sources"] == ["reddit", "news"] assert result["results"]["reddit"]["sentiment_score"] == 0.42 + assert len(calls) == 2, "Expected one call per source" assert calls[0]["url"] == "https://adanos.test/reddit/stocks/v1/stock/AAPL" assert calls[0]["headers"] == {"X-API-Key": "test-key"} assert calls[0]["params"] == {"days": 5, "to": "2026-05-20"} assert calls[0]["timeout"] == 3 + assert calls[1]["url"] == "https://adanos.test/news/stocks/v1/stock/AAPL"🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_adanos_sentiment.py` around lines 44 - 53, The test currently only inspects calls[0] after invoking client.get_stock_sentiment("aapl", sources="reddit,news", days=5); update the assertions to ensure both HTTP requests are made and validated: assert the length of calls (e.g., len(calls) == 2) and add checks for calls[1] mirroring the expectations for the "news" source (URL containing "/news/stocks/v1/stock/AAPL", same headers and params including days/to, and timeout), keeping the existing assertions for calls[0] for the "reddit" source so no source is dropped when get_stock_sentiment is called.
7-20: 💤 Low valueAdd docstring to test helper class.
The
_Strategymock class lacks a docstring explaining its purpose as a test fixture. Adding a brief docstring improves test readability and maintainability.📝 Proposed docstring
class _Strategy: + """Mock strategy fixture for Adanos sentiment testing. + + Provides fixed datetime (2026-05-20 14:30 UTC) and captures log messages. + """ is_backtesting = True broker = None🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_adanos_sentiment.py` around lines 7 - 20, Add a concise docstring to the _Strategy test helper class that states it is a mock/test fixture used by tests to emulate a strategy object (providing attributes is_backtesting, broker, log_messages and the AdanosMarketSentiment instance) and documents the purpose of its helper methods get_datetime and log_message; update the class _Strategy declaration (and optionally mention AdanosMarketSentiment, get_datetime, and log_message by name) with a one- or two-line docstring describing its role in tests.
1-109: ⚡ Quick winConsider adding edge case tests.
The current test suite covers happy paths and missing-credential scenarios well. Consider adding tests for:
- Invalid source names (e.g.,
sources="invalid_source")- Malformed API responses (missing expected fields, non-dict responses)
- HTTP errors (non-200 status codes)
- Timeout or network exceptions
These would increase robustness but are not essential for the initial implementation.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/test_adanos_sentiment.py` around lines 1 - 109, Add unit tests covering edge cases for AdanosMarketSentiment and the BuiltinTools adanos tool: add tests that call AdanosMarketSentiment.get_stock_sentiment and BuiltinTools.sentiment.adanos_market_sentiment().binder(...).function with invalid source names (e.g., "invalid_source") and assert errors are recorded in result["errors"]; add tests that monkeypatch lumibot.sentiment.adanos.requests.get to return malformed JSON (e.g., non-dict or missing expected keys) and assert the client handles it by returning empty results and populating result["errors"]; add tests that simulate HTTP errors by making _Response.raise_for_status raise an exception and verify exceptions are caught and logged; and add tests that simulate timeouts/network exceptions by having fake_get raise requests.Timeout (or a generic Exception) and assert timeouts are handled gracefully. Reference AdanosMarketSentiment, BuiltinTools.sentiment.adanos_market_sentiment, _Response, fake_get, and AgentManager to locate where to add these tests.docsrc/environment_variables.rst (1)
773-782: 💤 Low valueConsider relocating to a more appropriate section.
The ADANOS environment variables are documented under "SEC fundamentals and agent memory" (line 741), but Adanos provides market sentiment data rather than SEC fundamentals. This creates a categorization mismatch that may confuse users searching for sentiment-related configuration.
Consider either:
- Creating a new "Market sentiment data" section for ADANOS variables
- Renaming the section to "SEC fundamentals, market sentiment, and agent memory"
- Moving ADANOS variables to a "Data source credentials" subsection
The documentation content itself is accurate and complete.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@docsrc/environment_variables.rst` around lines 773 - 782, The ADANOS_API_KEY entry is placed under the "SEC fundamentals and agent memory" section but belongs under a sentiment/data-sources area; please move the ADANOS_API_KEY block (and any related ADANOS variables) out of the "SEC fundamentals and agent memory" section and either create a new "Market sentiment data" section or a "Data source credentials" subsection to house it, or alternatively rename the parent section to "SEC fundamentals, market sentiment, and agent memory" so the ADANOS_API_KEY entry logically matches surrounding content; update the section title and TOC entries accordingly to keep the docs consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lumibot/sentiment/adanos.py`:
- Around line 44-55: The helper _source_list can silently return an empty list
(e.g., when sources=="" or an iterable of empty strings) which causes downstream
no-ops; update _source_list (the function handling ADANOS_SOURCES) to treat an
empty requested list as an error: after building requested (in all branches)
check if not requested and raise a ValueError like "No Adanos sources provided"
or similar, ensuring blank strings or empty iterables are rejected rather than
returning [].
---
Nitpick comments:
In `@docsrc/environment_variables.rst`:
- Around line 773-782: The ADANOS_API_KEY entry is placed under the "SEC
fundamentals and agent memory" section but belongs under a
sentiment/data-sources area; please move the ADANOS_API_KEY block (and any
related ADANOS variables) out of the "SEC fundamentals and agent memory" section
and either create a new "Market sentiment data" section or a "Data source
credentials" subsection to house it, or alternatively rename the parent section
to "SEC fundamentals, market sentiment, and agent memory" so the ADANOS_API_KEY
entry logically matches surrounding content; update the section title and TOC
entries accordingly to keep the docs consistent.
In `@tests/test_adanos_sentiment.py`:
- Around line 22-30: Add a concise docstring to the test helper class _Response
describing that it is a lightweight HTTP response stub used in tests, what
payload it stores, and that raise_for_status() is a no-op while json() returns
the stored payload; update the class _Response (and optionally mention its
methods __init__, raise_for_status, json in the docstring) to include this brief
explanation so future readers understand its purpose.
- Around line 44-53: The test currently only inspects calls[0] after invoking
client.get_stock_sentiment("aapl", sources="reddit,news", days=5); update the
assertions to ensure both HTTP requests are made and validated: assert the
length of calls (e.g., len(calls) == 2) and add checks for calls[1] mirroring
the expectations for the "news" source (URL containing
"/news/stocks/v1/stock/AAPL", same headers and params including days/to, and
timeout), keeping the existing assertions for calls[0] for the "reddit" source
so no source is dropped when get_stock_sentiment is called.
- Around line 7-20: Add a concise docstring to the _Strategy test helper class
that states it is a mock/test fixture used by tests to emulate a strategy object
(providing attributes is_backtesting, broker, log_messages and the
AdanosMarketSentiment instance) and documents the purpose of its helper methods
get_datetime and log_message; update the class _Strategy declaration (and
optionally mention AdanosMarketSentiment, get_datetime, and log_message by name)
with a one- or two-line docstring describing its role in tests.
- Around line 1-109: Add unit tests covering edge cases for
AdanosMarketSentiment and the BuiltinTools adanos tool: add tests that call
AdanosMarketSentiment.get_stock_sentiment and
BuiltinTools.sentiment.adanos_market_sentiment().binder(...).function with
invalid source names (e.g., "invalid_source") and assert errors are recorded in
result["errors"]; add tests that monkeypatch
lumibot.sentiment.adanos.requests.get to return malformed JSON (e.g., non-dict
or missing expected keys) and assert the client handles it by returning empty
results and populating result["errors"]; add tests that simulate HTTP errors by
making _Response.raise_for_status raise an exception and verify exceptions are
caught and logged; and add tests that simulate timeouts/network exceptions by
having fake_get raise requests.Timeout (or a generic Exception) and assert
timeouts are handled gracefully. Reference AdanosMarketSentiment,
BuiltinTools.sentiment.adanos_market_sentiment, _Response, fake_get, and
AgentManager to locate where to add these tests.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e8527c3b-eb0c-40c0-945f-841249830147
📒 Files selected for processing (10)
CHANGELOG.mddocsrc/agents_builtin_tools.rstdocsrc/environment_variables.rstlumibot/__init__.pylumibot/components/agents/builtins.pylumibot/components/agents/manager.pylumibot/sentiment/__init__.pylumibot/sentiment/adanos.pylumibot/strategies/_strategy.pytests/test_adanos_sentiment.py
|
Addressed the review feedback in commit 415d64a:\n\n- reject empty Adanos source lists with a clear ValueError\n- expanded the multi-source test to assert both outbound API calls\n- added helper fixture docstrings\n- aligned the environment variable docs heading with market sentiment\n\nVerification run locally:\n- /tmp/lumibot-adanos-venv/bin/python -m pytest tests/test_adanos_sentiment.py -q -> 6 passed\n- py_compile for lumibot/sentiment/adanos.py and tests/test_adanos_sentiment.py\n- git diff --check |
Summary
AdanosMarketSentimenthelper available asstrategy.sentimentBuiltinTools.sentiment.adanos_market_sentiment()for AI agents whenADANOS_API_KEYis configuredDesign notes
toquery parameterADANOS_API_KEYis not set, matching the existing unavailable built-in-tool patternChecks
/tmp/lumibot-adanos-venv/bin/python -m pytest tests/test_adanos_sentiment.py tests/test_agent_alpaca_news_builtin.py tests/test_lazy_exports.py -q/tmp/lumibot-adanos-venv/bin/python -m pytest tests/test_adanos_sentiment.py -q/tmp/lumibot-adanos-venv/bin/python -m ruff check lumibot/sentiment/adanos.py tests/test_adanos_sentiment.py/tmp/lumibot-adanos-venv/bin/python -m py_compile lumibot/sentiment/adanos.py lumibot/components/agents/builtins.py lumibot/components/agents/manager.py lumibot/strategies/_strategy.py tests/test_adanos_sentiment.pygit diff --checkSummary by CodeRabbit
New Features
Documentation
Tests