Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 12 additions & 22 deletions python/valuecell/agents/sec_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(self):
self.sec_email = os.getenv("SEC_EMAIL", "your.name@example.com")
self.parser_model_id = os.getenv("SEC_PARSER_MODEL_ID", "openai/gpt-4o-mini")
self.analysis_model_id = os.getenv(
"SEC_ANALYSIS_MODEL_ID", "deepseek/deepseek-chat-v3-0324"
"SEC_ANALYSIS_MODEL_ID", "google/gemini-2.5-pro"
)
self.max_filings = int(os.getenv("SEC_MAX_FILINGS", "5"))
self.request_timeout = int(os.getenv("SEC_REQUEST_TIMEOUT", "30"))
Expand Down Expand Up @@ -124,11 +124,11 @@ async def _extract_ticker_from_query(self, query: str) -> str:
Query: {query}
"""

response = self.analysis_agent.run(extraction_prompt)
response = await self.analysis_agent.arun(extraction_prompt)
ticker = response.content.strip().upper()

# Basic validation
if ticker == "UNKNOWN" or len(ticker) > 10 or not ticker.isalpha():
if ticker == "UNKNOWN" or len(ticker) > 10:
raise ValueError(f"Invalid ticker extracted: {ticker}")

logger.info(f"Extracted ticker: {ticker} from query: {query}")
Expand All @@ -150,9 +150,8 @@ async def _get_sec_filings(self, ticker: str) -> Dict[str, str]:
for filing_type in filing_types:
try:
# Get the most recent filing of this type
filings = company.get_filings(form=filing_type).latest(1)
if filings:
filing = filings[0]
filing = company.get_filings(form=filing_type).latest()
if filing:
# Create a hash of the filing content/metadata
filing_content = f"{filing.accession_number}_{filing.filing_date}_{filing.form}"
filing_hash = hashlib.md5(filing_content.encode()).hexdigest()
Expand Down Expand Up @@ -228,7 +227,7 @@ async def _generate_filing_summary(
Keep the summary concise but informative (2-3 paragraphs maximum).
"""

response = self.analysis_agent.run(summary_prompt)
response = await self.analysis_agent.arun(summary_prompt)
return response.content

except Exception as e:
Expand Down Expand Up @@ -256,7 +255,7 @@ async def _classify_query(self, query: str) -> QueryType:
"""

try:
response = self.classifier_agent.run(classification_prompt)
response = await self.classifier_agent.arun(classification_prompt)
return response.content.query_type
except Exception as e:
logger.warning(
Expand All @@ -265,9 +264,7 @@ async def _classify_query(self, query: str) -> QueryType:
# If classification fails, default to 13F analysis (maintains backward compatibility)
return QueryType.FUND_HOLDINGS

async def _process_financial_data_query(
self, ticker: str, session_id: str, task_id: str
):
async def _process_financial_data_query(self, ticker: str):
"""
Process financial data queries (10-K, 8-K, 10-Q)
"""
Expand Down Expand Up @@ -365,9 +362,7 @@ async def _process_financial_data_query(
except Exception as e:
yield streaming.failed(f"Financial data query failed: {e}")

async def _process_fund_holdings_query(
self, ticker: str, session_id: str, task_id: str
):
async def _process_fund_holdings_query(self, ticker: str):
"""
Process 13F fund holdings queries (original logic)
"""
Expand Down Expand Up @@ -423,7 +418,6 @@ async def _process_fund_holdings_query(
- Specific changes in top 10 holdings
- Calculate increase/decrease percentages for major positions
- Analyze possible reasons for significant position adjustments

### 4. Investment Strategy Insights
- Investment style adjustments reflected in holdings changes
- Market trend judgments and responses
Expand Down Expand Up @@ -511,14 +505,10 @@ async def stream(

# 3. Route to appropriate processing method based on query type
if query_type == QueryType.FINANCIAL_DATA:
async for result in self._process_financial_data_query(
ticker, session_id, task_id
):
async for result in self._process_financial_data_query(ticker):
yield result
else: # QueryType.FUND_HOLDINGS
async for result in self._process_fund_holdings_query(
ticker, session_id, task_id
):
async for result in self._process_fund_holdings_query(ticker):
yield result

except Exception as e:
Expand Down Expand Up @@ -579,7 +569,7 @@ async def notify(self, query: str, session_id: str, task_id: str):
ticker, changes
)

yield notification.message(summary)
yield notification.component_generator(summary, "sec_feed")

# Wait before next check
await asyncio.sleep(check_interval)
Expand Down
1 change: 1 addition & 0 deletions python/valuecell/server/services/agent_stream_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async def stream_query_agent(

user_id = "default_user"
desired_agent_name = agent_name

conversation_id = agent_name + "_conv_" + user_id

user_input_meta = UserInputMetadata(
Expand Down