Skip to content

fix: inject resolved instrument identity into prompts#820

Open
Zavianx wants to merge 2 commits into
TauricResearch:mainfrom
Zavianx:fix/resolve-instrument-identity
Open

fix: inject resolved instrument identity into prompts#820
Zavianx wants to merge 2 commits into
TauricResearch:mainfrom
Zavianx:fix/resolve-instrument-identity

Conversation

@Zavianx
Copy link
Copy Markdown

@Zavianx Zavianx commented May 12, 2026

Summary

  • Resolve ticker identity once at graph startup using yfinance metadata
  • Store the resulting instrument context in the initial agent state
  • Reuse that context across analysts, researchers, trader, risk debaters, research manager, and portfolio manager prompts
  • Add regression tests for resolved identity context and fail-open identity resolution

Resolves #814

Testing

  • uv run --with pytest python -m pytest tests/test_ticker_symbol_handling.py tests/test_memory_log.py::TestPortfolioManagerInjection -q
  • uv run --with pytest python -m pytest -q

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to resolve and inject deterministic instrument identity (such as company name, sector, and industry) into the agent state using yfinance. This context is now utilized across various analyst, researcher, and manager nodes to ensure consistency and prevent ticker substitution. The reviewer suggests implementing caching for the identity resolution function to improve performance and mitigate potential rate-limiting issues.

Comment on lines +1 to +2
import logging
from typing import Any, Mapping
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Import functools to support caching of the instrument identity resolution results, which helps avoid redundant network calls.

Suggested change
import logging
from typing import Any, Mapping
import logging
import functools
from typing import Any, Mapping

return cleaned


def resolve_instrument_identity(ticker: str) -> dict[str, str]:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Resolving instrument identity involves a network call to yfinance, which can be slow and subject to rate limits. Since ticker metadata (like company name, sector, and industry) is generally static, caching these results will significantly improve performance, especially during backtests or when running the graph multiple times for the same ticker across different dates.

Applying @functools.lru_cache here is a safe and effective optimization.

@functools.lru_cache(maxsize=128)
def resolve_instrument_identity(ticker: str) -> dict[str, str]:

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a mechanism to resolve and inject deterministic instrument identity metadata—such as company name, sector, industry, and exchange—into the agent graph state using the yfinance library. The AgentState was updated to include an instrument_context field, and various analyst, researcher, and manager nodes were modified to utilize this precomputed context in their prompts and logic via the new get_instrument_context_from_state utility. Additionally, comprehensive unit tests were added to verify identity resolution, context building, and state propagation. I have no feedback to provide as no review comments were submitted.

@Zavianx
Copy link
Copy Markdown
Author

Zavianx commented May 12, 2026

Addressed the review suggestion in d574296: added @functools.lru_cache(maxsize=128) to resolve_instrument_identity and added a regression test to verify repeated same-ticker lookups reuse the cached result.

Testing:

  • uv run --with pytest python -m pytest tests/test_ticker_symbol_handling.py tests/test_memory_log.py::TestPortfolioManagerInjection -q
  • uv run --with pytest python -m pytest -q

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.

Bug: Multi-agent pipeline hallucinates wrong company identity — all analysts except fundamentals report on the wrong ticker

1 participant