Implementation:51bitquant Ai hedge fund crypto BaseNode call
| Knowledge Sources | |
|---|---|
| Domains | Graph_Architecture, Extensibility |
| Last Updated | 2026-10-28 14:00 GMT |
Overview
Interface specification for the abstract `BaseNode` contract that all strategy and graph nodes implement, provided by the `base_node` module.
Description
BaseNode defines the single abstract method `__call__(self, state: AgentState) -> Dict[str, Any]` which raises `NotImplementedError`. Every node in the LangGraph DAG — `DataNode`, `StartNode`, `EmptyNode`, `RiskManagementNode`, `PortfolioManagementNode`, and all strategy classes (`MacdStrategy`, `MyStrategy`) — subclasses `BaseNode` and implements `__call__`. The contract receives the shared `AgentState` TypedDict and returns a partial state update (`{"messages": [...], "data": {...}}`) merged by the LangGraph reducers (`add_messages` for `messages`, `deep_merge_dicts` for `data` and `metadata`).
This is a Pattern Doc: it documents an interface, not a concrete API you call directly.
Usage
Subclass `BaseNode` when creating a custom strategy or graph node. Implement `__call__` to read from `state["data"]`, compute your analysis, write results to `state["data"]["analyst_signals"][<agent_name>]`, emit a `HumanMessage`, and return `{"messages": [message], "data": data}`.
Code Reference
Source Location
- Repository: ai-hedge-fund-crypto
- File: src/graph/base_node.py
Signature
from .state import AgentState
class BaseNode:
def __call__(self, state: AgentState) -> Dict[str, Any]:
raise NotImplementedError("Subclasses must implement __call__")
Import
from src.graph.base_node import BaseNode
from src.graph.state import AgentState
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| state | AgentState | LangGraph state TypedDict (`messages`, `data`, `metadata`) |
Outputs
| Name | Type | Description |
|---|---|---|
| return | Partial state update, typically `{"messages": [HumanMessage], "data": dict}` |
Usage Examples
Minimal Custom Node
from typing import Dict, Any
import json
from langchain_core.messages import HumanMessage
from src.graph import AgentState, BaseNode
class MyStrategy(BaseNode):
def __call__(self, state: AgentState) -> Dict[str, Any]:
data = state.get("data", {})
tickers = data.get("tickers", [])
analysis = {t: {"signal": "neutral", "confidence": 50} for t in tickers}
message = HumanMessage(content=json.dumps(analysis), name="my_strategy_agent")
state["data"]["analyst_signals"]["my_strategy_agent"] = analysis
return {"messages": [message], "data": data}
Register and Wire
# See Workflow.create_workflow for dynamic loading via import_strategy_class
# Add "MyStrategy" to config.yaml signals.strategies